# HG changeset patch # User Christian Wimmer # Date 1431644901 25200 # Node ID e4a2ebb472713b9b52e0457350a529b94eaf255b # Parent d339bcb65015b2d1d1198960c521d5ca56527354 Add utility method to remove a phase with a given class diff -r d339bcb65015 -r e4a2ebb47271 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/PhaseSuite.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/PhaseSuite.java Thu May 14 16:06:42 2015 -0700 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/PhaseSuite.java Thu May 14 16:08:21 2015 -0700 @@ -70,6 +70,31 @@ return false; } + /** + * Removes the first instance of the given phase class, looking recursively into inner phase + * suites. + */ + public boolean removePhase(Class> phaseClass) { + ListIterator> it = phases.listIterator(); + while (it.hasNext()) { + BasePhase phase = it.next(); + if (phaseClass.isInstance(phase)) { + it.remove(); + return true; + } else if (phase instanceof PhaseSuite) { + @SuppressWarnings("unchecked") + PhaseSuite innerSuite = (PhaseSuite) phase; + if (innerSuite.removePhase(phaseClass)) { + if (innerSuite.phases.isEmpty()) { + it.remove(); + } + return true; + } + } + } + return false; + } + @Override protected void run(StructuredGraph graph, C context) { for (BasePhase phase : phases) {