# HG changeset patch # User Roland Schatz # Date 1384269716 -3600 # Node ID 8b82bdad798abaeebe969a9e0fb0fcd436e3271d # Parent aeb651f3c5d97a2b82fadd6bebb0f5ce421e5262 Make it possible to run counted loop detection on a single loop. diff -r aeb651f3c5d9 -r 8b82bdad798a graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopEx.java --- a/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopEx.java Tue Nov 12 13:12:29 2013 +0100 +++ b/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopEx.java Tue Nov 12 16:21:56 2013 +0100 @@ -28,9 +28,11 @@ import com.oracle.graal.debug.*; import com.oracle.graal.graph.*; import com.oracle.graal.graph.iterators.*; +import com.oracle.graal.loop.InductionVariable.Direction; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.cfg.*; +import com.oracle.graal.nodes.extended.*; public class LoopEx { @@ -146,8 +148,74 @@ } } - public void setCounted(CountedLoopInfo countedLoopInfo) { - counted = countedLoopInfo; + public boolean detectCounted() { + LoopBeginNode loopBegin = 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())) { + return false; + } + negated = true; + } + LogicNode ifTest = ifNode.condition(); + if (!(ifTest instanceof IntegerLessThanNode)) { + if (ifTest instanceof IntegerBelowThanNode) { + Debug.log("Ignored potential Counted loop at %s with |<|", loopBegin); + } + return false; + } + IntegerLessThanNode lessThan = (IntegerLessThanNode) ifTest; + Condition condition = null; + InductionVariable iv = null; + ValueNode limit = null; + if (isOutsideLoop(lessThan.x())) { + iv = getInductionVariables().get(lessThan.y()); + if (iv != null) { + condition = lessThan.condition().mirror(); + limit = lessThan.x(); + } + } else if (isOutsideLoop(lessThan.y())) { + iv = getInductionVariables().get(lessThan.x()); + if (iv != null) { + condition = lessThan.condition(); + limit = lessThan.y(); + } + } + if (condition == null) { + return false; + } + if (negated) { + condition = condition.negate(); + } + boolean oneOff = false; + switch (condition) { + case LE: + oneOff = true; // fall through + case LT: + if (iv.direction() != Direction.Up) { + return false; + } + break; + case GE: + oneOff = true; // fall through + case GT: + if (iv.direction() != Direction.Down) { + return false; + } + break; + default: + throw GraalInternalError.shouldNotReachHere(); + } + counted = new CountedLoopInfo(this, iv, limit, oneOff, negated ? ifNode.falseSuccessor() : ifNode.trueSuccessor()); + return true; + } + return false; } public LoopsData loopsData() { diff -r aeb651f3c5d9 -r 8b82bdad798a graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopsData.java --- a/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopsData.java Tue Nov 12 13:12:29 2013 +0100 +++ b/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopsData.java Tue Nov 12 16:21:56 2013 +0100 @@ -26,12 +26,8 @@ import java.util.concurrent.*; import com.oracle.graal.debug.*; -import com.oracle.graal.graph.*; -import com.oracle.graal.loop.InductionVariable.Direction; import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.cfg.*; -import com.oracle.graal.nodes.extended.*; public class LoopsData { @@ -102,72 +98,7 @@ 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())); - } + loop.detectCounted(); } }