Ejemplo n.º 1
0
 public Collection<LoopEx> countedLoops() {
   List<LoopEx> counted = new LinkedList<>();
   for (LoopEx loop : loops()) {
     if (loop.isCounted()) {
       counted.add(loop);
     }
   }
   return counted;
 }
Ejemplo n.º 2
0
 public InductionVariable getInductionVariable(ValueNode value) {
   InductionVariable match = null;
   for (LoopEx loop : loops()) {
     InductionVariable iv = loop.getInductionVariables().get(value);
     if (iv != null) {
       if (match != null) {
         return null;
       }
       match = iv;
     }
   }
   return match;
 }
Ejemplo n.º 3
0
  public LoopsData(final StructuredGraph graph) {
    cfg =
        Debug.scope(
            "ControlFlowGraph",
            new Callable<ControlFlowGraph>() {

              @Override
              public ControlFlowGraph call() throws Exception {
                return ControlFlowGraph.compute(graph, true, true, true, true);
              }
            });
    for (Loop lirLoop : cfg.getLoops()) {
      LoopEx ex = new LoopEx(lirLoop, this);
      lirLoopToEx.put(lirLoop, ex);
      loopBeginToEx.put(ex.loopBegin(), ex);
    }
  }
Ejemplo n.º 4
0
 public void detectedCountedLoops() {
   for (LoopEx loop : loops()) {
     InductionVariables ivs = new InductionVariables(loop);
     LoopBeginNode loopBegin = loop.loopBegin();
     FixedNode next = loopBegin.next();
     while (next instanceof FixedGuardNode || next instanceof ValueAnchorNode) {
       next = ((FixedWithNextNode) next).next();
     }
     if (next instanceof IfNode) {
       IfNode ifNode = (IfNode) next;
       boolean negated = false;
       if (!loopBegin.isLoopExit(ifNode.falseSuccessor())) {
         if (!loopBegin.isLoopExit(ifNode.trueSuccessor())) {
           continue;
         }
         negated = true;
       }
       LogicNode ifTest = ifNode.condition();
       if (!(ifTest instanceof IntegerLessThanNode)) {
         if (ifTest instanceof IntegerBelowThanNode) {
           Debug.log("Ignored potential Counted loop at %s with |<|", loopBegin);
         }
         continue;
       }
       IntegerLessThanNode lessThan = (IntegerLessThanNode) ifTest;
       Condition condition = null;
       InductionVariable iv = null;
       ValueNode limit = null;
       if (loop.isOutsideLoop(lessThan.x())) {
         iv = ivs.get(lessThan.y());
         if (iv != null) {
           condition = lessThan.condition().mirror();
           limit = lessThan.x();
         }
       } else if (loop.isOutsideLoop(lessThan.y())) {
         iv = ivs.get(lessThan.x());
         if (iv != null) {
           condition = lessThan.condition();
           limit = lessThan.y();
         }
       }
       if (condition == null) {
         continue;
       }
       if (negated) {
         condition = condition.negate();
       }
       boolean oneOff = false;
       switch (condition) {
         case LE:
           oneOff = true; // fall through
         case LT:
           if (iv.direction() != Direction.Up) {
             continue;
           }
           break;
         case GE:
           oneOff = true; // fall through
         case GT:
           if (iv.direction() != Direction.Down) {
             continue;
           }
           break;
         default:
           throw GraalInternalError.shouldNotReachHere();
       }
       loop.setCounted(
           new CountedLoopInfo(
               loop,
               iv,
               limit,
               oneOff,
               negated ? ifNode.falseSuccessor() : ifNode.trueSuccessor()));
     }
   }
 }