Package soot.toolkits.graph

Examples of soot.toolkits.graph.DominatorNode


        for(Iterator godesIt = graph.iterator(); godesIt.hasNext();)
        {
         
            Object gode = godesIt.next();

            DominatorNode dode = fetchDode(gode);
            DominatorNode parent = fetchParent(gode);

            if(parent == null){
              
              //make sure the array is created!
              if(heads == null)
                  heads = new ArrayList();
             
                heads.add(dode);
            }
            else{
                parent.addChild(dode);
                dode.setParent(parent);
            }
        }
     
        head = (DominatorNode) heads.get(0);
        // identify the tail nodes
       
        for(Iterator dodesIt = this.iterator(); dodesIt.hasNext();)
        {
            DominatorNode dode = (DominatorNode) dodesIt.next();

            if(dode.isTail())
                tails.add(dode);
        }
   
    }
View Full Code Here


    {
      Unit tail = itr.next();
      if(!(tail instanceof ThrowStmt))
        continue;
     
      DominatorNode x = dom.getDode(tail);
      DominatorNode parentOfX = dom.getParentOf(x);
      Object xgode = x.getGode();
      DominatorNode xpdomDode = pdom.getDode(xgode);
      Object parentXGode = parentOfX.getGode();
      DominatorNode parentpdomDode = pdom.getDode(parentXGode);
      //while x post-dominates its dominator (parent in dom)
      while(pdom.isDominatorOf(xpdomDode, parentpdomDode))
      {
        x = parentOfX;
        parentOfX = dom.getParentOf(x);
       
        //If parent is null we must be at the head of the graph
        if(parentOfX == null)
          //throw new RuntimeException("This should never have happened!");
          break;
       
        xgode = x.getGode();
        xpdomDode = pdom.getDode(xgode);
        parentXGode = parentOfX.getGode();
        parentpdomDode = pdom.getDode(parentXGode);
      }
     
      if(parentOfX != null)
        x = parentOfX;
     
      xgode = x.getGode();
      xpdomDode = pdom.getDode(xgode);
     
     
      Unit mergePoint = null;
     
      if(x2mergePoint.containsKey(xgode))
        mergePoint = x2mergePoint.get(xgode);
      else
      {
        //Now get all the children of x in the dom
       
        List<DominatorNode> domChilds = dom.getChildrenOf(x);
               
        Object child1god = null;
        Object child2god = null;
       
        for(Iterator<DominatorNode> domItr = domChilds.iterator(); domItr.hasNext(); )
        {
          DominatorNode child = domItr.next();
          Object childGode = child.getGode();
          DominatorNode childpdomDode = pdom.getDode(childGode);
         
         
          //we don't want to make a loop!
          List<Unit> path = this.getExtendedBasicBlockPathBetween((Unit)childGode, tail);
         
          //if(dom.isDominatorOf(child, dom.getDode(tail)))
          if(!(path == null || path.size() == 0))
            continue;
         
          if(pdom.isDominatorOf(childpdomDode, xpdomDode))
          {
            mergePoint = (Unit) child.getGode();       
            break;
          }         
                 
          //gather two eligible childs
          if(child1god == null)
            child1god = childGode;
          else if(child2god == null)
            child2god = childGode;
           
        }
       
        if(mergePoint == null)
        {
          if(child1god != null && child2god != null)
          {
            DominatorNode child1 = pdom.getDode(child1god);
            DominatorNode child2 = pdom.getDode(child2god);
 
            //go up the pdom tree and find the common parent of child1 and child2
            DominatorNode comParent = child1.getParent();
            while(comParent != null)
            {
              if(pdom.isDominatorOf(comParent, child2))
              {
                mergePoint = (Unit) comParent.getGode();
                break;
              }
              comParent = comParent.getParent();
            }
          }
          else if(child1god != null || child2god != null){
         
            DominatorNode y = null;
           
            if(child1god != null)
              y = pdom.getDode(child1god);
            else if(child2god != null)
              y = pdom.getDode(child2god);
           
             
            DominatorNode initialY = dom.getDode(y.getGode());
            DominatorNode yDodeInDom = initialY;
           
            while(dom.isDominatorOf(x, yDodeInDom))
            {
              y = y.getParent();
             
              //If this is a case where the childs of a conditional
              //are all throws, or returns, just forget it!
              if(y == null)
              {
                break ;
              }
              yDodeInDom = dom.getDode(y.getGode());
            }
            if(y != null)
              mergePoint = (Unit) y.getGode();
            else
              mergePoint = (Unit) initialY.getGode();
          }
        }
       
        //This means no (dom) child of x post-dominates x, so just use the child that is
        //immediately
        /*if(mergePoint == null)
        {
          //throw new RuntimeException("No child post-dominates x.");
          mergePoint = potentialMergePoint;
         
        }*/
        //This means no (dom) child of x post-dominates x, so just use the child that is
        //immediately. this means there is no good reliable merge point. So we just fetch the succ
        //of x in CFg so that the succ does not dominate the throw, and find the first
        //post-dom of the succ so that x does not dom it.
        //
        if(mergePoint == null)
        {
          List<Unit> xSucc = this.unitToSuccs.get(x.getGode());
          for(Iterator<Unit> uItr = xSucc.iterator(); uItr.hasNext(); )
          {
            Unit u = uItr.next();
            if(dom.isDominatorOf(dom.getDode(u), dom.getDode(tail)))
              continue;
           
           
            DominatorNode y = pdom.getDode(u);
           
            while(dom.isDominatorOf(x, y))
            {
              y = y.getParent();
              //If this is a case where the childs of a conditional
              //are all throws, or returns, just forget it!
              if(y == null)
              {
                continue TailsLoop;
              }
            }
            mergePoint = (Unit) y.getGode();
            break;
          }
        }
        //the following happens if the throw is the only exit in the method (even if return stmt is present.)
        else if(dom.isDominatorOf(dom.getDode(mergePoint), dom.getDode(tail)))
View Full Code Here

  {
    try{
      //System.out.println("##entered weakRegionDFS for region " + r);
      this.m_regions.get(new Integer(r)).add(v);
     
      DominatorNode parentOfV = this.m_dom.getParentOf(this.m_dom.getDode(v));
      Block u2 = (parentOfV == null) ? null : (Block)parentOfV.getGode();
     
      List children = this.m_pdom.getChildrenOf(this.m_pdom.getDode(v));
      for(int i = 0; i < children.size(); i++)
      {
        DominatorNode w = (DominatorNode)children.get(i);
        Block u1 = (Block)w.getGode();
 
        if(u2 != null && u1.equals(u2))
        {
          this.weakRegionDFS((Block)w.getGode(), r);     
        }
        else
        {
          this.m_regCount++;
          this.m_regions.put(new Integer(this.m_regCount), this.createRegion(this.m_regCount));
          this.weakRegionDFS((Block)w.getGode(), this.m_regCount);     
       
      } 
    }
    catch(RuntimeException e)
    {
View Full Code Here

  {
    //regions keep an implicit order of the contained blocks so it matters where blocks are added
    //below.
    this.m_regions.get(new Integer(r)).add2Back(v);
   
    DominatorNode parentOfV = this.m_pdom.getParentOf(this.m_pdom.getDode(v));
    Block u2 = (parentOfV == null) ? null : (Block)parentOfV.getGode();
   
    List children = this.m_dom.getChildrenOf(this.m_dom.getDode(v));
    for(int i = 0; i < children.size(); i++)
    {
      DominatorNode w = (DominatorNode)children.get(i);
      Block u1 = (Block)w.getGode();
     
      if(u2 != null && u1.equals(u2))
      {
        this.weakRegionDFS2((Block)w.getGode(), r);     
      }
      else
      {
        this.m_regCount++;
        this.m_regions.put(new Integer(this.m_regCount), this.createRegion(this.m_regCount));
        this.weakRegionDFS2((Block)w.getGode(), this.m_regCount);     
     
    } 

  }
View Full Code Here

         
          if(b.equals(a))
            throw new RuntimeException("PDG construction: A and B are not supposed to be the same node!");
         
         
          DominatorNode aDode = pdom.getDode(a);
          DominatorNode bDode = pdom.getDode(b);
         
          //If B post-dominates A, go to the next successor.
          if(pdom.isDominatorOf(bDode, aDode))
            continue;
         
          //FIXME: what if the parent is null?!!
          DominatorNode aParentDode = aDode.getParent();
         
          DominatorNode dode = bDode;
          while(dode != aParentDode)
          {
            dependents.add((Block)dode.getGode());
           
            //This occurs if the CFG is multi-tailed and therefore the pdom is a forest.
            if(dode.getParent() == null)
              //throw new RuntimeException("parent dode in pdom is null: dode is " + aDode);
              break;
            dode = dode.getParent();           
          }
         
          /*
           * If node A is in the dependent list of A, then A is the header of a loop.
           * Otherwise, A could still be the header of a loop or just a simple predicate.
           */
         
          //first make A's pdg node be a conditional (predicate) pdgnode, if it's not already.         
          if(pdgNodeOfA.getAttrib() != PDGNode.Attribute.CONDHEADER)
          {
            PDGNode oldA = pdgNodeOfA;
            pdgNodeOfA = new ConditionalPDGNode(pdgNodeOfA);
            this.replaceInGraph(pdgNodeOfA, oldA);
            pdgnode.removeDependent(oldA);
            this.m_obj2pdgNode.put(a, pdgNodeOfA);
            pdgnode.addDependent(pdgNodeOfA);
            pdgNodeOfA.setAttrib(PDGNode.Attribute.CONDHEADER);
           
            curNodeInRegion = pdgNodeOfA;
          }   
         
          List<Block> copyOfDependents = new ArrayList<Block>();
          copyOfDependents.addAll(dependents);
         
          //First, add the dependency for B and its corresponding region.
          Region regionOfB = block2region.get(b);
          PDGNode pdgnodeOfBRegion = null;
          if(!this.m_obj2pdgNode.containsKey(regionOfB))
          {
            pdgnodeOfBRegion = new PDGNode(regionOfB, PDGNode.Type.REGION);
            this.addNode(pdgnodeOfBRegion);
            this.m_obj2pdgNode.put(regionOfB, pdgnodeOfBRegion);
           
          }
          else
            pdgnodeOfBRegion = this.m_obj2pdgNode.get(regionOfB);
         
          //set the region hierarchy
          regionOfB.setParent(r);
          r.addChildRegion(regionOfB);
         
          //add the dependency edges
          this.addEdge(pdgNodeOfA, pdgnodeOfBRegion, "dependency");
          pdgNodeOfA.addDependent(pdgnodeOfBRegion);
          regions2process.add(regionOfB);
          //now remove b and all the nodes in the same weak region from the list of dependents
          copyOfDependents.remove(b);
          copyOfDependents.removeAll(regionOfB.getBlocks());
       
         
          /* What remains here in the dependence set needs to be processed separately. For
           * each node X remained in the dependency set, find the corresponding PDG region node
           * and add a dependency edge from the region of B to the region of X. If X's weak
           * region contains other nodes not in the dependency set of A, create a new region
           * for X and add the proper dependency edges (this actually happens if X is the header
           * of a loop and B is a predicate guarding a break/continue.)
           *
           * Note: it seems the only case that there is a node remained in the dependents is when there
           * is a path from b to the header of a loop.
           */
         
          while(!copyOfDependents.isEmpty())
          {
            Block depB = copyOfDependents.remove(0);
            Region rdepB = block2region.get(depB);
           
            /*
             * Actually, there are cases when depB is not the header of a loop and therefore would not dominate the current node
             * (A) and therefore might not have been created yet. This has happened when an inner loop breaks out of the outer
             * loop but could have other cases too.
             */
            PDGNode depBPDGNode = this.m_obj2pdgNode.get(depB);
            if(depBPDGNode == null)
            {           
              //First, add the dependency for depB and its corresponding region.
             
              PDGNode pdgnodeOfdepBRegion = null;
              if(!this.m_obj2pdgNode.containsKey(rdepB))
              {
                pdgnodeOfdepBRegion = new PDGNode(rdepB, PDGNode.Type.REGION);
                this.addNode(pdgnodeOfdepBRegion);
                this.m_obj2pdgNode.put(rdepB, pdgnodeOfdepBRegion);
               
              }
              else
                pdgnodeOfdepBRegion = this.m_obj2pdgNode.get(rdepB);
             
              //set the region hierarchy
              rdepB.setParent(regionOfB);
              regionOfB.addChildRegion(rdepB);
             
              //add the dependency edges
              this.addEdge(pdgnodeOfBRegion, pdgnodeOfdepBRegion, "dependency");
              pdgnodeOfBRegion.addDependent(pdgnodeOfdepBRegion);
              regions2process.add(rdepB);
             
              //now remove all the nodes in the same weak region from the list of dependents
             
              copyOfDependents.removeAll(rdepB.getBlocks());
             
              continue;

            }
           
            /**
             * If all the nodes in the weak region of depB are dependent on A, then add
             * an edge from the region of B to the region of depB.
             *
             * else, a new region has to be created to contain the dependences of depB, if
             * not already created.
             */
            if(dependents.containsAll(rdepB.getBlocks()))
            {
              /*
               * Just add an edge to the pdg node of the existing depB region.
               *
               */
              //add the dependency edges
              //First, add the dependency for depB and its corresponding region.
             
              PDGNode pdgnodeOfdepBRegion = null;
              if(!this.m_obj2pdgNode.containsKey(rdepB))
              {
                pdgnodeOfdepBRegion = new PDGNode(rdepB, PDGNode.Type.REGION);
                this.addNode(pdgnodeOfdepBRegion);
                this.m_obj2pdgNode.put(rdepB, pdgnodeOfdepBRegion);
               
              }
              else
                pdgnodeOfdepBRegion = this.m_obj2pdgNode.get(rdepB);
             
              //set the region hierarchy
              //Do not set this because the region was created before so must have the
              //proper parent already.
              //rdepB.setParent(regionOfB);
              //regionOfB.addChildRegion(rdepB);
             
              this.addEdge(pdgnodeOfBRegion, pdgnodeOfdepBRegion, "dependency");
              pdgnodeOfBRegion.addDependent(pdgnodeOfdepBRegion);
              regions2process.add(rdepB);
             
              //now remove all the nodes in the same weak region from the list of dependents
             
              copyOfDependents.removeAll(rdepB.getBlocks());
 
              continue;
            }
            else
            {
              PDGNode predPDGofdepB = (PDGNode) this.getPredsOf(depBPDGNode).get(0);
              assert(this.m_obj2pdgNode.containsKey(rdepB));             
              PDGNode pdgnodeOfdepBRegion = this.m_obj2pdgNode.get(rdepB);
              //If the loop header has not been separated from its weak region yet
              if(predPDGofdepB == pdgnodeOfdepBRegion)
              {
                /*
                 * Create a new region to represent the whole loop. In fact, this is a strong
                 * region as opposed to the weak regions that were created in the RegionAnalysis.
                 * This strong region only contains the header of the loop, A, and is dependent
                 * on it. Also, A is dependent on this strong region as well.
                 */
               
                Region newRegion = new Region(this.m_strongRegionStartID++, topLevelRegion.getSootMethod(), topLevelRegion.getSootClass(), this.m_cfg);
                newRegion.add(depB);
               
                this.m_strongRegions.add(newRegion);
                               
                //toBeRemoved.add(depB);
                List<Block> blocks2BRemoved;
                if(toBeRemoved.contains(predPDGofdepB))
                  blocks2BRemoved = toBeRemoved.get(predPDGofdepB);
                else
                {
                  blocks2BRemoved = new ArrayList<Block>();
                  toBeRemoved.put(rdepB, blocks2BRemoved);
                }
                blocks2BRemoved.add(depB);
               
               
               
                PDGNode newpdgnode = new LoopedPDGNode(newRegion, PDGNode.Type.REGION, depBPDGNode);
                this.addNode(newpdgnode);
                this.m_obj2pdgNode.put(newRegion, newpdgnode);
                newpdgnode.setAttrib(PDGNode.Attribute.LOOPHEADER);
                depBPDGNode.setAttrib(PDGNode.Attribute.LOOPHEADER);
               
                this.removeEdge(pdgnodeOfdepBRegion, depBPDGNode, "dependency");
                pdgnodeOfdepBRegion.removeDependent(depBPDGNode);
                this.addEdge(pdgnodeOfdepBRegion, newpdgnode, "dependency");
                this.addEdge(newpdgnode, depBPDGNode, "dependency");
                pdgnodeOfdepBRegion.addDependent(newpdgnode);
                newpdgnode.addDependent(depBPDGNode);
               
               
               
                //If a is dependent on itself (simple loop)
                if(depB == a)
                {
                  PDGNode loopBodyPDGNode = (PDGNode) this.getSuccsOf(depBPDGNode).get(0);
                  this.addEdge(depBPDGNode, newpdgnode, "dependency-back");
                  ((LoopedPDGNode)newpdgnode).setBody(loopBodyPDGNode);
                 
                  depBPDGNode.addBackDependent(newpdgnode);
                 
                  //This is needed to correctly adjust the prev/next pointers for the new loop node. We should not need
                  //to adjust the old loop header node because the prev/next should not have been set previously for it.
                  curNodeInRegion = newpdgnode;
                 
                }
                else
                {
                 
                  //this is a back-dependency
                  pdgnodeOfBRegion.addBackDependent(newpdgnode);
                  this.addEdge(pdgnodeOfBRegion, newpdgnode, "dependency-back");
                 
                  //DEtermine which dependent of the loop header is actually the loop body region
                  PDGNode loopBodyPDGNode = null;
                  List<PDGNode> successors = this.getSuccsOf(depBPDGNode);
                  Iterator<PDGNode> succItr = successors.iterator();
                  while(succItr.hasNext())
                  {
                    PDGNode succRPDGNode = succItr.next();
                   
                    assert(succRPDGNode.getType() == PDGNode.Type.REGION);
                    Region succR = (Region) succRPDGNode.getNode();
                    Block h = succR.getBlocks().get(0);
                   
                    DominatorNode hdode = dom.getDode(h);
                    DominatorNode adode = dom.getDode(a);
                   
                    if(dom.isDominatorOf(hdode, adode))
                    {
                      loopBodyPDGNode = succRPDGNode;
                      break;
View Full Code Here

TOP

Related Classes of soot.toolkits.graph.DominatorNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.