# HG changeset patch # User Roland Schatz # Date 1378815359 -7200 # Node ID 8a3d99fc36cf5a807e5542a3979419c4e72306fc # Parent a63b63822183a02977c1deb6c0093794426aee9a Pass canonicalizer into tail duplication. diff -r a63b63822183 -r 8a3d99fc36cf graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/HighTier.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/HighTier.java Tue Sep 10 14:09:10 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/HighTier.java Tue Sep 10 14:15:59 2013 +0200 @@ -77,7 +77,7 @@ } if (OptTailDuplication.getValue()) { - appendPhase(new TailDuplicationPhase()); + appendPhase(new TailDuplicationPhase(canonicalizer)); } if (PartialEscapeAnalysis.getValue()) { diff -r a63b63822183 -r 8a3d99fc36cf graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java Tue Sep 10 14:09:10 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java Tue Sep 10 14:15:59 2013 +0200 @@ -38,7 +38,7 @@ import com.oracle.graal.api.meta.ResolvedJavaType.Representation; import com.oracle.graal.debug.*; import com.oracle.graal.graph.*; -import com.oracle.graal.graph.Node.*; +import com.oracle.graal.graph.Node.Verbosity; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.extended.*; @@ -707,7 +707,8 @@ if (opportunities > 0) { metricInliningTailDuplication.increment(); Debug.log("MultiTypeGuardInlineInfo starting tail duplication (%d opportunities)", opportunities); - TailDuplicationPhase.tailDuplicate(returnMerge, TailDuplicationPhase.TRUE_DECISION, replacementNodes, new PhaseContext(runtime, assumptions, replacements)); + TailDuplicationPhase.tailDuplicate(returnMerge, TailDuplicationPhase.TRUE_DECISION, replacementNodes, new PhaseContext(runtime, assumptions, replacements), new CanonicalizerPhase( + !AOTCompilation.getValue())); } } } diff -r a63b63822183 -r 8a3d99fc36cf graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/TailDuplicationPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/TailDuplicationPhase.java Tue Sep 10 14:09:10 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/TailDuplicationPhase.java Tue Sep 10 14:15:59 2013 +0200 @@ -42,8 +42,8 @@ /** * This class is a phase that looks for opportunities for tail duplication. The static method - * {@link #tailDuplicate(MergeNode, TailDuplicationDecision, List, PhaseContext)} can also be used - * to drive tail duplication from other places, e.g., inlining. + * {@link #tailDuplicate(MergeNode, TailDuplicationDecision, List, PhaseContext, CanonicalizerPhase)} + * can also be used to drive tail duplication from other places, e.g., inlining. */ public class TailDuplicationPhase extends BasePhase { @@ -53,6 +53,8 @@ private static final DebugMetric metricDuplicationConsidered = Debug.metric("DuplicationConsidered"); private static final DebugMetric metricDuplicationPerformed = Debug.metric("DuplicationPerformed"); + private final CanonicalizerPhase canonicalizer; + /** * This interface is used by tail duplication to let clients decide if tail duplication should * be performed. @@ -129,6 +131,10 @@ } }; + public TailDuplicationPhase(CanonicalizerPhase canonicalizer) { + this.canonicalizer = canonicalizer; + } + @Override protected void run(StructuredGraph graph, PhaseContext phaseContext) { NodesToDoubles nodeProbabilities = new ComputeProbabilityClosure(graph).apply(); @@ -137,7 +143,7 @@ // duplication. for (MergeNode merge : graph.getNodes(MergeNode.class).snapshot()) { if (!(merge instanceof LoopBeginNode) && nodeProbabilities.get(merge) >= TailDuplicationProbability.getValue()) { - tailDuplicate(merge, DEFAULT_DECISION, null, phaseContext); + tailDuplicate(merge, DEFAULT_DECISION, null, phaseContext, canonicalizer); } } } @@ -159,7 +165,7 @@ * {@link PiNode} in the duplicated branch that corresponds to the entry. * @param phaseContext */ - public static boolean tailDuplicate(MergeNode merge, TailDuplicationDecision decision, List replacements, PhaseContext phaseContext) { + public static boolean tailDuplicate(MergeNode merge, TailDuplicationDecision decision, List replacements, PhaseContext phaseContext, CanonicalizerPhase canonicalizer) { assert !(merge instanceof LoopBeginNode); assert replacements == null || replacements.size() == merge.forwardEndCount(); FixedNode fixed = merge; @@ -172,7 +178,7 @@ metricDuplicationConsidered.increment(); if (decision.doTransform(merge, fixedCount)) { metricDuplicationPerformed.increment(); - new DuplicationOperation(merge, replacements).duplicate(phaseContext); + new DuplicationOperation(merge, replacements, canonicalizer).duplicate(phaseContext); return true; } } @@ -190,6 +196,8 @@ private final HashMap bottomPhis = new HashMap<>(); private final List replacements; + private final CanonicalizerPhase canonicalizer; + /** * Initializes the tail duplication operation without actually performing any work. * @@ -197,10 +205,11 @@ * @param replacements A list of replacement {@link PiNode}s, or null. If this is non-null, * then the size of the list needs to match the number of end nodes at the merge. */ - public DuplicationOperation(MergeNode merge, List replacements) { + public DuplicationOperation(MergeNode merge, List replacements, CanonicalizerPhase canonicalizer) { this.merge = merge; this.replacements = replacements; this.graph = merge.graph(); + this.canonicalizer = canonicalizer; } /** @@ -289,7 +298,7 @@ phi.setMerge(mergeAfter); } } - new CanonicalizerPhase.Instance(phaseContext.getRuntime(), phaseContext.getAssumptions(), !AOTCompilation.getValue(), graph.getNewNodes(startMark), null).apply(graph); + canonicalizer.applyIncremental(graph, phaseContext, startMark); Debug.dump(graph, "After tail duplication at %s", merge); }