< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.loop/src/org/graalvm/compiler/loop/CountedLoopInfo.java

Print this page




  66     public ValueNode maxTripCountNode() {
  67         return maxTripCountNode(false);
  68     }
  69 
  70     public ValueNode maxTripCountNode(boolean assumePositive) {
  71         StructuredGraph graph = iv.valueNode().graph();
  72         Stamp stamp = iv.valueNode().stamp();
  73         ValueNode range = sub(graph, end, iv.initNode());
  74 
  75         ValueNode oneDirection;
  76         if (iv.direction() == Direction.Up) {
  77             oneDirection = ConstantNode.forIntegerStamp(stamp, 1, graph);
  78         } else {
  79             assert iv.direction() == Direction.Down;
  80             oneDirection = ConstantNode.forIntegerStamp(stamp, -1, graph);
  81         }
  82         if (oneOff) {
  83             range = add(graph, range, oneDirection);
  84         }
  85         // round-away-from-zero divison: (range + stride -/+ 1) / stride
  86         ValueNode denominator = add(graph, sub(graph, range, oneDirection), iv.strideNode());




  87         ValueNode div = divBefore(graph, loop.entryPoint(), denominator, iv.strideNode());
  88 
  89         if (assumePositive) {
  90             return div;
  91         }
  92         ConstantNode zero = ConstantNode.forIntegerStamp(stamp, 0, graph);
  93         return graph.unique(new ConditionalNode(graph.unique(new IntegerLessThanNode(zero, div)), div, zero));
  94     }
  95 
  96     /**
  97      * @return true if the loop has constant bounds and the trip count is representable as a
  98      *         positive integer.
  99      */
 100     public boolean isConstantMaxTripCount() {
 101         /*
 102          * It's possible that the iteration range is too large to treat this as constant because it
 103          * will overflow.
 104          */
 105         return (hasConstantBounds() && rawConstantMaxTripCount() >= 0);
 106     }




  66     public ValueNode maxTripCountNode() {
  67         return maxTripCountNode(false);
  68     }
  69 
  70     public ValueNode maxTripCountNode(boolean assumePositive) {
  71         StructuredGraph graph = iv.valueNode().graph();
  72         Stamp stamp = iv.valueNode().stamp();
  73         ValueNode range = sub(graph, end, iv.initNode());
  74 
  75         ValueNode oneDirection;
  76         if (iv.direction() == Direction.Up) {
  77             oneDirection = ConstantNode.forIntegerStamp(stamp, 1, graph);
  78         } else {
  79             assert iv.direction() == Direction.Down;
  80             oneDirection = ConstantNode.forIntegerStamp(stamp, -1, graph);
  81         }
  82         if (oneOff) {
  83             range = add(graph, range, oneDirection);
  84         }
  85         // round-away-from-zero divison: (range + stride -/+ 1) / stride
  86         ValueNode denominator = range;
  87         if (!oneDirection.stamp().equals(iv.strideNode().stamp())) {
  88             ValueNode subedRanged = sub(graph, range, oneDirection);
  89             denominator = add(graph, subedRanged, iv.strideNode());
  90         }
  91         ValueNode div = divBefore(graph, loop.entryPoint(), denominator, iv.strideNode());
  92 
  93         if (assumePositive) {
  94             return div;
  95         }
  96         ConstantNode zero = ConstantNode.forIntegerStamp(stamp, 0, graph);
  97         return graph.unique(new ConditionalNode(graph.unique(new IntegerLessThanNode(zero, div)), div, zero));
  98     }
  99 
 100     /**
 101      * @return true if the loop has constant bounds and the trip count is representable as a
 102      *         positive integer.
 103      */
 104     public boolean isConstantMaxTripCount() {
 105         /*
 106          * It's possible that the iteration range is too large to treat this as constant because it
 107          * will overflow.
 108          */
 109         return (hasConstantBounds() && rawConstantMaxTripCount() >= 0);
 110     }


< prev index next >