changeset 15584:56ab99b480af

[single-pass-iter] lifecycle of single-pass iterators
author Miguel Garcia <miguel.m.garcia@oracle.com>
date Fri, 09 May 2014 16:50:27 +0200
parents d331b7c3d7c4
children 4d5b1e7a4d93
files graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/SinglePassNodeIterator.java
diffstat 1 files changed, 22 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/SinglePassNodeIterator.java	Fri May 09 16:22:54 2014 +0200
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/SinglePassNodeIterator.java	Fri May 09 16:50:27 2014 +0200
@@ -87,11 +87,11 @@
         do {
             if (current instanceof InvokeWithExceptionNode) {
                 invoke((Invoke) current);
-                queueSuccessors(current, null);
+                queueSuccessors(current);
                 current = nextQueuedNode();
             } else if (current instanceof LoopBeginNode) {
                 state.loopBegin((LoopBeginNode) current);
-                nodeStates.put(current, state);
+                keepForLater(current, state);
                 state = state.clone();
                 loopBegin((LoopBeginNode) current);
                 current = ((LoopBeginNode) current).next();
@@ -117,8 +117,8 @@
                 node(current);
                 current = nextQueuedNode();
             } else if (current instanceof ControlSplitNode) {
-                Set<Node> successors = controlSplit((ControlSplitNode) current);
-                queueSuccessors(current, successors);
+                controlSplit((ControlSplitNode) current);
+                queueSuccessors(current);
                 current = nextQueuedNode();
             } else {
                 assert false : current;
@@ -127,20 +127,11 @@
         finished();
     }
 
-    private void queueSuccessors(FixedNode x, Set<Node> successors) {
-        nodeStates.put(x, state);
-        if (successors != null) {
-            for (Node node : successors) {
-                if (node != null) {
-                    nodeStates.put((FixedNode) node.predecessor(), state);
-                    nodeQueue.addFirst((BeginNode) node);
-                }
-            }
-        } else {
-            for (Node node : x.successors()) {
-                if (node != null) {
-                    nodeQueue.addFirst((BeginNode) node);
-                }
+    private void queueSuccessors(FixedNode x) {
+        keepForLater(x, state);
+        for (Node node : x.successors()) {
+            if (node != null) {
+                nodeQueue.addFirst((BeginNode) node);
             }
         }
     }
@@ -159,12 +150,8 @@
                     states.add(other);
                 }
                 boolean ready = state.merge(merge, states);
-                assert ready;
-                if (ready) {
-                    return merge;
-                } else {
-                    nodeQueue.addLast(merge);
-                }
+                assert ready : "Not a single-pass iterator after all";
+                return merge;
             } else {
                 assert node.predecessor() != null;
                 state = nodeStates.get(node.predecessor()).clone();
@@ -178,7 +165,7 @@
     private void finishLoopEnds(LoopEndNode end) {
         assert !visitedEnds.isMarked(end);
         assert !nodeStates.containsKey(end);
-        nodeStates.put(end, state);
+        keepForLater(end, state);
         visitedEnds.mark(end);
         LoopBeginNode begin = end.loopBegin();
         boolean endsVisited = true;
@@ -203,7 +190,7 @@
     private void queueMerge(EndNode end) {
         assert !visitedEnds.isMarked(end);
         assert !nodeStates.containsKey(end);
-        nodeStates.put(end, state);
+        keepForLater(end, state);
         visitedEnds.mark(end);
         MergeNode merge = end.merge();
         boolean endsVisited = true;
@@ -236,16 +223,23 @@
         node(loopEnd);
     }
 
-    protected Set<Node> controlSplit(ControlSplitNode controlSplit) {
+    protected void controlSplit(ControlSplitNode controlSplit) {
         node(controlSplit);
-        return null;
     }
 
     protected void invoke(Invoke invoke) {
         node(invoke.asNode());
     }
 
+    /**
+     * The lifecycle that single-pass node iterators go through is described in {@link #apply()}
+     */
     protected void finished() {
         // nothing to do
     }
+
+    private void keepForLater(FixedNode x, T s) {
+        assert !nodeStates.containsKey(x);
+        nodeStates.put(x, s);
+    }
 }