# HG changeset patch # User Roland Schatz # Date 1378910475 -7200 # Node ID 943f1863e1c19e228fae63f3d8c4c9b4781aa9aa # Parent 152b4146f05b887b57785a2af84809b18c7e9875 Early exit from ReentrantNodeIterator. diff -r 152b4146f05b -r 943f1863e1c1 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ReentrantNodeIterator.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ReentrantNodeIterator.java Tue Sep 10 19:20:20 2013 +0200 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ReentrantNodeIterator.java Wed Sep 11 16:41:15 2013 +0200 @@ -44,6 +44,15 @@ protected abstract StateT afterSplit(AbstractBeginNode node, StateT oldState); protected abstract Map processLoop(LoopBeginNode loop, StateT initialState); + + /** + * Determine whether iteration should continue in the current state. + * + * @param currentState + */ + protected boolean continueIteration(StateT currentState) { + return true; + } } private ReentrantNodeIterator() { @@ -83,64 +92,69 @@ } else { FixedNode next = ((FixedWithNextNode) current).next(); state = closure.processNode(current, state); - current = next; + current = closure.continueIteration(state) ? next : null; } } if (current != null) { state = closure.processNode(current, state); - NodeClassIterator successors = current.successors().iterator(); - if (!successors.hasNext()) { - if (current instanceof LoopEndNode) { - blockEndStates.put(current, state); - } else if (current instanceof EndNode) { - // add the end node and see if the merge is ready for processing - MergeNode merge = ((EndNode) current).merge(); - if (merge instanceof LoopBeginNode) { - Map loopExitState = closure.processLoop((LoopBeginNode) merge, state); - for (Map.Entry entry : loopExitState.entrySet()) { - blockEndStates.put(entry.getKey(), entry.getValue()); - nodeQueue.add(entry.getKey()); - } - } else { - assert !blockEndStates.containsKey(current); + if (closure.continueIteration(state)) { + NodeClassIterator successors = current.successors().iterator(); + if (!successors.hasNext()) { + if (current instanceof LoopEndNode) { blockEndStates.put(current, state); - boolean endsVisited = true; - for (AbstractEndNode forwardEnd : merge.forwardEnds()) { - if (!blockEndStates.containsKey(forwardEnd)) { - endsVisited = false; - break; + } else if (current instanceof EndNode) { + // add the end node and see if the merge is ready for processing + MergeNode merge = ((EndNode) current).merge(); + if (merge instanceof LoopBeginNode) { + Map loopExitState = closure.processLoop((LoopBeginNode) merge, state); + for (Map.Entry entry : loopExitState.entrySet()) { + blockEndStates.put(entry.getKey(), entry.getValue()); + nodeQueue.add(entry.getKey()); + } + } else { + assert !blockEndStates.containsKey(current); + blockEndStates.put(current, state); + boolean endsVisited = true; + for (AbstractEndNode forwardEnd : merge.forwardEnds()) { + if (!blockEndStates.containsKey(forwardEnd)) { + endsVisited = false; + break; + } + } + if (endsVisited) { + ArrayList states = new ArrayList<>(merge.forwardEndCount()); + for (int i = 0; i < merge.forwardEndCount(); i++) { + AbstractEndNode forwardEnd = merge.forwardEndAt(i); + assert blockEndStates.containsKey(forwardEnd); + StateT other = blockEndStates.get(forwardEnd); + states.add(other); + } + state = closure.merge(merge, states); + current = closure.continueIteration(state) ? merge : null; + continue; } } - if (endsVisited) { - ArrayList states = new ArrayList<>(merge.forwardEndCount()); - for (int i = 0; i < merge.forwardEndCount(); i++) { - AbstractEndNode forwardEnd = merge.forwardEndAt(i); - assert blockEndStates.containsKey(forwardEnd); - StateT other = blockEndStates.get(forwardEnd); - states.add(other); - } - state = closure.merge(merge, states); - current = merge; - continue; - } } - } - } else { - FixedNode firstSuccessor = (FixedNode) successors.next(); - if (!successors.hasNext()) { - current = firstSuccessor; - continue; } else { - while (successors.hasNext()) { - AbstractBeginNode successor = (AbstractBeginNode) successors.next(); - blockEndStates.put(successor, closure.afterSplit(successor, state)); - nodeQueue.add(successor); + FixedNode firstSuccessor = (FixedNode) successors.next(); + if (!successors.hasNext()) { + current = firstSuccessor; + continue; + } else { + while (successors.hasNext()) { + AbstractBeginNode successor = (AbstractBeginNode) successors.next(); + StateT successorState = closure.afterSplit(successor, state); + if (closure.continueIteration(successorState)) { + blockEndStates.put(successor, successorState); + nodeQueue.add(successor); + } + } + state = closure.afterSplit((AbstractBeginNode) firstSuccessor, state); + current = closure.continueIteration(state) ? firstSuccessor : null; + continue; } - state = closure.afterSplit((AbstractBeginNode) firstSuccessor, state); - current = firstSuccessor; - continue; } } }