changeset 12761:8b82bdad798a

Make it possible to run counted loop detection on a single loop.
author Roland Schatz <roland.schatz@oracle.com>
date Tue, 12 Nov 2013 16:21:56 +0100
parents aeb651f3c5d9
children 884bee435276
files graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopEx.java graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopsData.java
diffstat 2 files changed, 71 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- 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() {
--- 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();
         }
     }