# HG changeset patch # User Miguel Garcia # Date 1399647027 -7200 # Node ID 56ab99b480af487f2404536a7c422347a26758bf # Parent d331b7c3d7c4217c81ad780d652f63dd8b374cc8 [single-pass-iter] lifecycle of single-pass iterators diff -r d331b7c3d7c4 -r 56ab99b480af graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/SinglePassNodeIterator.java --- 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 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 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 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); + } }