# HG changeset patch # User Thomas Wuerthinger # Date 1424710678 -3600 # Node ID f53c6c8e204851500415d1c9afd33e30cbf2d824 # Parent fb32f2d8abf48c74d43affdc08714e7c9657bffb Refactorings in SchedulePhase. diff -r fb32f2d8abf4 -r f53c6c8e2048 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java Mon Feb 23 17:47:49 2015 +0100 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java Mon Feb 23 17:57:58 2015 +0100 @@ -671,6 +671,10 @@ if (earliest != null) { return earliest; } + return earliestBlockHelper(node, earliest); + } + + private Block earliestBlockHelper(Node node, Block earliest) throws SchedulingError { /* * All inputs must be in a dominating block, otherwise the graph cannot be scheduled. This * implies that the inputs' blocks have a total ordering via their dominance relation. So in @@ -681,31 +685,19 @@ if (node.predecessor() != null) { throw new SchedulingError(); } - for (Node input : node.inputs().nonNull()) { - assert input instanceof ValueNode; - Block inputEarliest; - if (input instanceof InvokeWithExceptionNode) { - inputEarliest = cfg.getNodeToBlock().get(((InvokeWithExceptionNode) input).next()); - } else { - inputEarliest = earliestBlock(input); - } - if (earliest == null) { - earliest = inputEarliest; - } else if (earliest != inputEarliest) { - // Find out whether earliest or inputEarliest is earlier. - Block a = earliest.getDominator(); - Block b = inputEarliest; - while (true) { - if (a == inputEarliest || b == null) { - // Nothing to change, the previous earliest block is still earliest. - break; - } else if (b == earliest || a == null) { - // New earliest is the earliest. - earliest = inputEarliest; - break; - } - a = a.getDominator(); - b = b.getDominator(); + for (Node input : node.inputs()) { + if (input != null) { + assert input instanceof ValueNode; + Block inputEarliest; + if (input instanceof InvokeWithExceptionNode) { + inputEarliest = cfg.getNodeToBlock().get(((InvokeWithExceptionNode) input).next()); + } else { + inputEarliest = earliestBlock(input); + } + if (earliest == null) { + earliest = inputEarliest; + } else if (earliest != inputEarliest) { + earliest = findEarlierBlock(earliest, inputEarliest); } } } @@ -716,6 +708,23 @@ return earliest; } + private static Block findEarlierBlock(Block earliest, Block inputEarliest) { + // Find out whether earliest or inputEarliest is earlier. + Block a = earliest.getDominator(); + Block b = inputEarliest; + while (true) { + if (a == inputEarliest || b == null) { + // Nothing to change, the previous earliest block is still earliest. + return earliest; + } else if (b == earliest || a == null) { + // New earliest is the earliest. + return inputEarliest; + } + a = a.getDominator(); + b = b.getDominator(); + } + } + /** * Schedules a node out of loop based on its earliest schedule. Note that this movement is only * valid if it's done for every other node in the schedule, otherwise this movement is @@ -1071,20 +1080,16 @@ return; } + addToLatestSortingHelper(i, state); + } + + private void addToLatestSortingHelper(ValueNode i, SortState state) { FrameState stateAfter = null; if (i instanceof StateSplit) { stateAfter = ((StateSplit) i).stateAfter(); } - for (Node input : i.inputs()) { - if (input instanceof FrameState) { - if (input != stateAfter) { - addUnscheduledToLatestSorting((FrameState) input, state); - } - } else { - addToLatestSorting((ValueNode) input, state); - } - } + addInputsToLatestSorting(i, state, stateAfter); if (state.readsSize() != 0) { if (i instanceof MemoryCheckpoint.Single) { @@ -1112,6 +1117,18 @@ } } + private void addInputsToLatestSorting(ValueNode i, SortState state, FrameState stateAfter) { + for (Node input : i.inputs()) { + if (input instanceof FrameState) { + if (input != stateAfter) { + addUnscheduledToLatestSorting((FrameState) input, state); + } + } else { + addToLatestSorting((ValueNode) input, state); + } + } + } + /** * Sorts the nodes within a block by adding the nodes to a list in a post-order iteration over * all usages. The resulting list is reversed to create an earliest-possible scheduling of