# HG changeset patch # User Roland Schatz # Date 1378804476 -7200 # Node ID aa9ce8d5677113eef881834aa27dda550de8a5ab # Parent e231671f39d080a0c151e41d3fca908c49f9dc53 New methods for incremental canonicalization. diff -r e231671f39d0 -r aa9ce8d56771 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/FloatingReadTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/FloatingReadTest.java Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/FloatingReadTest.java Tue Sep 10 11:14:36 2013 +0200 @@ -60,7 +60,7 @@ public void run() { StructuredGraph graph = parse(snippet); PhaseContext context = new PhaseContext(runtime(), new Assumptions(false), replacements); - new LoweringPhase(LoweringType.BEFORE_GUARDS).apply(graph, context); + new LoweringPhase(LoweringType.BEFORE_GUARDS, new CanonicalizerPhase(true)).apply(graph, context); new FloatingReadPhase().apply(graph); ReturnNode returnNode = null; diff -r e231671f39d0 -r aa9ce8d56771 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/LockEliminationTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/LockEliminationTest.java Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/LockEliminationTest.java Tue Sep 10 11:14:36 2013 +0200 @@ -96,7 +96,7 @@ new InliningPhase().apply(graph, context); new CanonicalizerPhase(true).apply(graph, context); new DeadCodeEliminationPhase().apply(graph); - new LoweringPhase(LoweringType.BEFORE_GUARDS).apply(graph, context); + new LoweringPhase(LoweringType.BEFORE_GUARDS, new CanonicalizerPhase(true)).apply(graph, context); new ValueAnchorCleanupPhase().apply(graph); new LockEliminationPhase().apply(graph); return graph; diff -r e231671f39d0 -r aa9ce8d56771 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MemoryScheduleTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MemoryScheduleTest.java Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MemoryScheduleTest.java Tue Sep 10 11:14:36 2013 +0200 @@ -504,7 +504,7 @@ if (mode == TestMode.INLINED_WITHOUT_FRAMESTATES) { new InliningPhase().apply(graph, context); } - new LoweringPhase(LoweringType.BEFORE_GUARDS).apply(graph, context); + new LoweringPhase(LoweringType.BEFORE_GUARDS, new CanonicalizerPhase(true)).apply(graph, context); if (mode == TestMode.WITHOUT_FRAMESTATES || mode == TestMode.INLINED_WITHOUT_FRAMESTATES) { for (Node node : graph.getNodes()) { if (node instanceof StateSplit) { @@ -523,8 +523,8 @@ MidTierContext midContext = new MidTierContext(runtime(), assumptions, replacements, runtime().getTarget(), OptimisticOptimizations.ALL); new GuardLoweringPhase().apply(graph, midContext); - new LoweringPhase(LoweringType.AFTER_GUARDS).apply(graph, midContext); - new LoweringPhase(LoweringType.AFTER_FSA).apply(graph, midContext); + new LoweringPhase(LoweringType.AFTER_GUARDS, new CanonicalizerPhase(true)).apply(graph, midContext); + new LoweringPhase(LoweringType.AFTER_FSA, new CanonicalizerPhase(true)).apply(graph, midContext); SchedulePhase schedule = new SchedulePhase(SchedulingStrategy.LATEST_OUT_OF_LOOPS, memsched); schedule.apply(graph); diff -r e231671f39d0 -r aa9ce8d56771 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/PushNodesThroughPiTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/PushNodesThroughPiTest.java Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/PushNodesThroughPiTest.java Tue Sep 10 11:14:36 2013 +0200 @@ -94,7 +94,7 @@ StructuredGraph graph = parse(snippet); PhaseContext context = new PhaseContext(runtime(), new Assumptions(false), replacements); CanonicalizerPhase canonicalizer = new CanonicalizerPhase(true); - new LoweringPhase(LoweringType.BEFORE_GUARDS).apply(graph, context); + new LoweringPhase(LoweringType.BEFORE_GUARDS, canonicalizer).apply(graph, context); canonicalizer.apply(graph, context); new PushThroughPiPhase().apply(graph); canonicalizer.apply(graph, context); diff -r e231671f39d0 -r aa9ce8d56771 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ReadAfterCheckCastTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ReadAfterCheckCastTest.java Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ReadAfterCheckCastTest.java Tue Sep 10 11:14:36 2013 +0200 @@ -85,7 +85,7 @@ public void run() { StructuredGraph graph = parse(snippet); PhaseContext context = new PhaseContext(runtime(), new Assumptions(false), replacements); - new LoweringPhase(LoweringType.BEFORE_GUARDS).apply(graph, context); + new LoweringPhase(LoweringType.BEFORE_GUARDS, new CanonicalizerPhase(true)).apply(graph, context); new FloatingReadPhase().apply(graph); new EliminatePartiallyRedundantGuardsPhase(true, false).apply(graph); new ReadEliminationPhase().apply(graph); diff -r e231671f39d0 -r aa9ce8d56771 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 Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/HighTier.java Tue Sep 10 11:14:36 2013 +0200 @@ -98,6 +98,6 @@ appendPhase(canonicalizer); } - appendPhase(new LoweringPhase(LoweringType.BEFORE_GUARDS)); + appendPhase(new LoweringPhase(LoweringType.BEFORE_GUARDS, canonicalizer)); } } diff -r e231671f39d0 -r aa9ce8d56771 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LowTier.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LowTier.java Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LowTier.java Tue Sep 10 11:14:36 2013 +0200 @@ -22,6 +22,8 @@ */ package com.oracle.graal.compiler.phases; +import static com.oracle.graal.phases.GraalOptions.*; + import com.oracle.graal.nodes.spi.Lowerable.LoweringType; import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; @@ -30,7 +32,9 @@ public class LowTier extends PhaseSuite { public LowTier() { - appendPhase(new LoweringPhase(LoweringType.AFTER_FSA)); + CanonicalizerPhase canonicalizer = new CanonicalizerPhase(!AOTCompilation.getValue()); + + appendPhase(new LoweringPhase(LoweringType.AFTER_FSA, canonicalizer)); appendPhase(new ExpandLogicPhase()); diff -r e231671f39d0 -r aa9ce8d56771 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/MidTier.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/MidTier.java Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/MidTier.java Tue Sep 10 11:14:36 2013 +0200 @@ -51,7 +51,7 @@ } if (OptFloatingReads.getValue()) { - IncrementalCanonicalizerPhase incCanonicalizer = new IncrementalCanonicalizerPhase<>(); + IncrementalCanonicalizerPhase incCanonicalizer = new IncrementalCanonicalizerPhase<>(canonicalizer); incCanonicalizer.appendPhase(new FloatingReadPhase()); appendPhase(incCanonicalizer); if (OptReadElimination.getValue()) { @@ -86,7 +86,7 @@ appendPhase(new GuardLoweringPhase()); - appendPhase(new LoweringPhase(LoweringType.AFTER_GUARDS)); + appendPhase(new LoweringPhase(LoweringType.AFTER_GUARDS, canonicalizer)); appendPhase(new FrameStateAssignmentPhase()); diff -r e231671f39d0 -r aa9ce8d56771 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierAdditionTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierAdditionTest.java Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierAdditionTest.java Tue Sep 10 11:14:36 2013 +0200 @@ -250,9 +250,9 @@ HighTierContext highContext = new HighTierContext(runtime(), new Assumptions(false), replacements, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL); MidTierContext midContext = new MidTierContext(runtime(), new Assumptions(false), replacements, runtime().getTarget(), OptimisticOptimizations.ALL); new InliningPhase(new InliningPhase.InlineEverythingPolicy()).apply(graph, highContext); - new LoweringPhase(LoweringType.BEFORE_GUARDS).apply(graph, highContext); + new LoweringPhase(LoweringType.BEFORE_GUARDS, new CanonicalizerPhase(true)).apply(graph, highContext); new GuardLoweringPhase().apply(graph, midContext); - new LoweringPhase(LoweringType.AFTER_GUARDS).apply(graph, midContext); + new LoweringPhase(LoweringType.AFTER_GUARDS, new CanonicalizerPhase(true)).apply(graph, midContext); new WriteBarrierAdditionPhase().apply(graph); Debug.dump(graph, "After Write Barrier Addition"); diff -r e231671f39d0 -r aa9ce8d56771 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierVerificationTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierVerificationTest.java Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierVerificationTest.java Tue Sep 10 11:14:36 2013 +0200 @@ -637,10 +637,10 @@ MidTierContext midTierContext = new MidTierContext(runtime(), new Assumptions(false), replacements, runtime().getTarget(), OptimisticOptimizations.ALL); - new LoweringPhase(LoweringType.BEFORE_GUARDS).apply(graph, highTierContext); + new LoweringPhase(LoweringType.BEFORE_GUARDS, new CanonicalizerPhase(true)).apply(graph, highTierContext); new GuardLoweringPhase().apply(graph, midTierContext); new SafepointInsertionPhase().apply(graph); - new LoweringPhase(LoweringType.AFTER_GUARDS).apply(graph, highTierContext); + new LoweringPhase(LoweringType.AFTER_GUARDS, new CanonicalizerPhase(true)).apply(graph, highTierContext); new WriteBarrierAdditionPhase().apply(graph); diff -r e231671f39d0 -r aa9ce8d56771 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java Tue Sep 10 11:14:36 2013 +0200 @@ -49,6 +49,7 @@ public static final DebugMetric METRIC_GLOBAL_VALUE_NUMBERING_HITS = Debug.metric("GlobalValueNumberingHits"); private final boolean canonicalizeReads; + private final CustomCanonicalizer customCanonicalizer; public interface CustomCanonicalizer { @@ -56,12 +57,41 @@ } public CanonicalizerPhase(boolean canonicalizeReads) { + this(canonicalizeReads, null); + } + + public CanonicalizerPhase(boolean canonicalizeReads, CustomCanonicalizer customCanonicalizer) { this.canonicalizeReads = canonicalizeReads; + this.customCanonicalizer = customCanonicalizer; } @Override protected void run(StructuredGraph graph, PhaseContext context) { - new Instance(context.getRuntime(), context.getAssumptions(), canonicalizeReads).run(graph); + new Instance(context.getRuntime(), context.getAssumptions(), canonicalizeReads, customCanonicalizer).run(graph); + } + + public void applyIncremental(StructuredGraph graph, PhaseContext context, int newNodesMark) { + applyIncremental(graph, context, newNodesMark, true); + } + + public void applyIncremental(StructuredGraph graph, PhaseContext context, int newNodesMark, boolean dumpGraph) { + new Instance(context.getRuntime(), context.getAssumptions(), canonicalizeReads, newNodesMark, customCanonicalizer).apply(graph, dumpGraph); + } + + public void applyIncremental(StructuredGraph graph, PhaseContext context, Iterable workingSet) { + applyIncremental(graph, context, workingSet, true); + } + + public void applyIncremental(StructuredGraph graph, PhaseContext context, Iterable workingSet, boolean dumpGraph) { + new Instance(context.getRuntime(), context.getAssumptions(), canonicalizeReads, workingSet, customCanonicalizer).apply(graph, dumpGraph); + } + + public void applyIncremental(StructuredGraph graph, PhaseContext context, Iterable workingSet, int newNodesMark) { + applyIncremental(graph, context, workingSet, newNodesMark, true); + } + + public void applyIncremental(StructuredGraph graph, PhaseContext context, Iterable workingSet, int newNodesMark, boolean dumpGraph) { + new Instance(context.getRuntime(), context.getAssumptions(), canonicalizeReads, workingSet, newNodesMark, customCanonicalizer).apply(graph, dumpGraph); } public static class Instance extends Phase { @@ -77,7 +107,11 @@ private Tool tool; public Instance(MetaAccessProvider runtime, Assumptions assumptions, boolean canonicalizeReads) { - this(runtime, assumptions, canonicalizeReads, null, 0, null); + this(runtime, assumptions, canonicalizeReads, null); + } + + private Instance(MetaAccessProvider runtime, Assumptions assumptions, boolean canonicalizeReads, CustomCanonicalizer customCanonicalizer) { + this(runtime, assumptions, canonicalizeReads, null, 0, customCanonicalizer); } /** diff -r e231671f39d0 -r aa9ce8d56771 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IncrementalCanonicalizerPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IncrementalCanonicalizerPhase.java Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IncrementalCanonicalizerPhase.java Tue Sep 10 11:14:36 2013 +0200 @@ -22,29 +22,22 @@ */ package com.oracle.graal.phases.common; -import static com.oracle.graal.phases.GraalOptions.*; - import com.oracle.graal.nodes.*; import com.oracle.graal.phases.*; -import com.oracle.graal.phases.common.CanonicalizerPhase.CustomCanonicalizer; import com.oracle.graal.phases.tiers.*; public class IncrementalCanonicalizerPhase extends PhaseSuite { - private final CustomCanonicalizer customCanonicalizer; + private final CanonicalizerPhase canonicalizer; - public IncrementalCanonicalizerPhase() { - this(null); - } - - public IncrementalCanonicalizerPhase(CustomCanonicalizer customCanonicalizer) { - this.customCanonicalizer = customCanonicalizer; + public IncrementalCanonicalizerPhase(CanonicalizerPhase canonicalizer) { + this.canonicalizer = canonicalizer; } @Override protected void run(StructuredGraph graph, C context) { int mark = graph.getMark(); super.run(graph, context); - new CanonicalizerPhase.Instance(context.getRuntime(), context.getAssumptions(), !AOTCompilation.getValue(), mark, customCanonicalizer).apply(graph); + canonicalizer.applyIncremental(graph, context, mark, false); } } diff -r e231671f39d0 -r aa9ce8d56771 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java Tue Sep 10 11:14:36 2013 +0200 @@ -135,10 +135,12 @@ } private final LoweringType loweringType; + private final CanonicalizerPhase canonicalizer; - public LoweringPhase(LoweringType loweringType) { + public LoweringPhase(LoweringType loweringType, CanonicalizerPhase canonicalizer) { super("Lowering (" + loweringType.name() + ")"); this.loweringType = loweringType; + this.canonicalizer = canonicalizer; } private static boolean containsLowerable(NodeIterable nodes) { @@ -157,9 +159,8 @@ Round round = new Round(i++, context); int mark = graph.getMark(); - IncrementalCanonicalizerPhase canonicalizer = new IncrementalCanonicalizerPhase<>(); - canonicalizer.appendPhase(round); - canonicalizer.apply(graph, context); + round.apply(graph); + canonicalizer.applyIncremental(graph, context, mark); if (!containsLowerable(graph.getNewNodes(mark))) { // No new lowerable nodes - done! diff -r e231671f39d0 -r aa9ce8d56771 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/PartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/PartialEvaluationTest.java Mon Sep 09 10:48:28 2013 +0200 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/PartialEvaluationTest.java Tue Sep 10 11:14:36 2013 +0200 @@ -195,7 +195,7 @@ canonicalizerPhase.apply(graph); new DeadCodeEliminationPhase().apply(graph); - new LoweringPhase(LoweringType.BEFORE_GUARDS).apply(graph, context); + new LoweringPhase(LoweringType.BEFORE_GUARDS, new CanonicalizerPhase(true)).apply(graph, context); canonicalizerPhase.apply(graph); new DeadCodeEliminationPhase().apply(graph); return graph;