--- old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/PhaseSuite.java 2017-07-07 09:31:34.000000000 -0700 +++ new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases/src/org/graalvm/compiler/phases/PhaseSuite.java 2017-07-07 09:31:34.000000000 -0700 @@ -72,6 +72,30 @@ } /** + * Inserts a phase before the last phase in the suite. If the suite contains no phases the new + * phase will be inserted as the first phase. + */ + public final void addBeforeLast(BasePhase phase) { + ListIterator> last = findLastPhase(); + if (last.hasPrevious()) { + last.previous(); + } + last.add(phase); + } + + /** + * Returns a {@link ListIterator} at the position of the last phase in the suite. If the suite + * has no phases then it will return an empty iterator. + */ + private ListIterator> findLastPhase() { + ListIterator> it = phases.listIterator(); + while (it.hasNext()) { + it.next(); + } + return it; + } + + /** * Returns a {@link ListIterator} at the position of the first phase which is an instance of * {@code phaseClass} or null if no such phase can be found. *