# HG changeset patch # User Gilles Duboscq # Date 1342778720 -7200 # Node ID 59f209dd356bab763c572927d620f0b608c6214a # Parent 0428e0b46c6327a3ad630fb8ef7445a74cc0e5df Be more precise on the set of node that are canonicalized in IterativeCheckCastElimination diff -r 0428e0b46c63 -r 59f209dd356b graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Thu Jul 19 13:28:16 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Fri Jul 20 12:05:20 2012 +0200 @@ -140,6 +140,10 @@ new PropagateTypeCachePhase(target, runtime, assumptions).apply(graph); } + if (GraalOptions.OptCanonicalizer) { + new CanonicalizerPhase(target, runtime, assumptions).apply(graph); + } + if (GraalOptions.CheckCastElimination && GraalOptions.OptCanonicalizer) { new IterativeCheckCastEliminationPhase(target, runtime, assumptions).apply(graph); } @@ -195,6 +199,10 @@ } new RemoveValueProxyPhase().apply(graph); + if (GraalOptions.OptCanonicalizer) { + new CanonicalizerPhase(target, runtime, assumptions).apply(graph); + } + if (GraalOptions.CheckCastElimination && GraalOptions.OptCanonicalizer) { new IterativeCheckCastEliminationPhase(target, runtime, assumptions).apply(graph); } diff -r 0428e0b46c63 -r 59f209dd356b graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CheckCastEliminationPhase.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CheckCastEliminationPhase.java Thu Jul 19 13:28:16 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/CheckCastEliminationPhase.java Fri Jul 20 12:05:20 2012 +0200 @@ -47,12 +47,10 @@ private static final DebugMetric metricGuardsReplaced = Debug.metric("GuardsReplaced"); private StructuredGraph graph; - private boolean graphModified; @Override protected void run(StructuredGraph inputGraph) { graph = inputGraph; - graphModified = false; new EliminateCheckCasts(graph.start(), new State()).apply(); } @@ -307,7 +305,6 @@ BooleanNode condition = guard.condition(); ValueNode existingGuards = guard.negated() ? state.falseConditions.get(condition) : state.trueConditions.get(condition); if (existingGuards != null) { - graphModified = true; guard.replaceAtUsages(existingGuards); GraphUtil.killWithUnusedFloatingInputs(guard); metricGuardsReplaced.increment(); @@ -321,7 +318,6 @@ removeCheck = true; } if (removeCheck) { - graphModified = true; metricNullCheckGuardRemoved.increment(); } } @@ -346,7 +342,6 @@ piNode = graph.unique(new PiNode(checkCast.object(), lastBegin, nonNull ? StampFactory.declaredNonNull(type) : StampFactory.declared(type))); checkCast.replaceAtUsages(piNode); graph.removeFixed(checkCast); - graphModified = true; metricCheckCastRemoved.increment(); } } else if (node instanceof IfNode) { @@ -387,7 +382,6 @@ } } if (replaceWith != null) { - graphModified = true; ifNode.setCompare(replaceWith); if (compare.usages().isEmpty()) { GraphUtil.killWithUnusedFloatingInputs(compare); @@ -397,8 +391,4 @@ } } - public boolean wasGraphModfied() { - return graphModified; - } - } diff -r 0428e0b46c63 -r 59f209dd356b graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/IterativeCheckCastEliminationPhase.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/IterativeCheckCastEliminationPhase.java Thu Jul 19 13:28:16 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/IterativeCheckCastEliminationPhase.java Fri Jul 20 12:05:20 2012 +0200 @@ -22,7 +22,11 @@ */ package com.oracle.graal.compiler.phases; +import java.util.*; + import com.oracle.graal.api.code.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.graph.Graph.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; @@ -34,27 +38,35 @@ public IterativeCheckCastEliminationPhase(TargetDescription target, GraalCodeCacheProvider runtime, Assumptions assumptions) { this.target = target; - // TODO Auto-generated constructor stub this.runtime = runtime; this.assumptions = assumptions; } @Override protected void run(StructuredGraph graph) { + Set canonicalizationRoots = new HashSet<>(); CheckCastEliminationPhase eliminate = new CheckCastEliminationPhase(); - CanonicalizerPhase canon = new CanonicalizerPhase(target, runtime, assumptions); - boolean canonRun = false; + Listener listener = new Listener(canonicalizationRoots); while (true) { + graph.trackInputChange(listener); eliminate.apply(graph); - if (!eliminate.wasGraphModfied()) { + graph.stopTrackingInputChange(); + if (canonicalizationRoots.isEmpty()) { break; } - canon.apply(graph); - canonRun = true; - } - if (!canonRun) { - canon.apply(graph); + new CanonicalizerPhase(target, runtime, assumptions, canonicalizationRoots, null).apply(graph); + canonicalizationRoots.clear(); } } + private static class Listener implements InputChangedListener { + private final Set canonicalizationRoots; + public Listener(Set canonicalizationRoots) { + this.canonicalizationRoots = canonicalizationRoots; + } + @Override + public void inputChanged(Node node) { + canonicalizationRoots.add(node); + } + } }