Mercurial > hg > graal-jvmci-8
changeset 9054:c7f289614722
Merge.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Fri, 12 Apr 2013 18:15:44 +0200 |
parents | 1a99a8df6dad (diff) 1946c86f8842 (current diff) |
children | b28c80b6ee58 |
files | |
diffstat | 38 files changed, 430 insertions(+), 396 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/BoxingEliminationTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/BoxingEliminationTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -30,6 +30,7 @@ import com.oracle.graal.nodes.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; +import com.oracle.graal.phases.tiers.*; import com.oracle.graal.virtual.nodes.*; import com.oracle.graal.virtual.phases.ea.*; @@ -307,8 +308,9 @@ graph = parse(snippet); new ComputeProbabilityPhase().apply(graph); Assumptions assumptions = new Assumptions(false); + HighTierContext context = new HighTierContext(runtime(), assumptions); new InliningPhase(runtime(), null, replacements, assumptions, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL).apply(graph); - new PartialEscapeAnalysisPhase(runtime(), assumptions, false, false).apply(graph); + new PartialEscapeAnalysisPhase(false, false).apply(graph, context); new CullFrameStatesPhase().apply(graph); } @@ -325,13 +327,14 @@ new ComputeProbabilityPhase().apply(graph); Assumptions assumptions = new Assumptions(false); + HighTierContext context = new HighTierContext(runtime(), assumptions); new InliningPhase(runtime(), null, replacements, assumptions, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL).apply(graph); if (loopPeeling) { new LoopTransformHighPhase().apply(graph); } new DeadCodeEliminationPhase().apply(graph); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); - new PartialEscapeAnalysisPhase(runtime(), assumptions, false, false).apply(graph); + new CanonicalizerPhase().apply(graph, context); + new PartialEscapeAnalysisPhase(false, false).apply(graph, context); for (MaterializeObjectNode materialize : graph.getNodes(MaterializeObjectNode.class)) { materialize.getVirtualObject().materializeAt(materialize, materialize.getValues(), false, materialize.getLockCount()); @@ -339,12 +342,12 @@ new CullFrameStatesPhase().apply(graph); new DeadCodeEliminationPhase().apply(graph); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase().apply(graph, context); StructuredGraph referenceGraph = parse(referenceSnippet); new InliningPhase(runtime(), null, replacements, assumptions, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL).apply(referenceGraph); new DeadCodeEliminationPhase().apply(referenceGraph); - new CanonicalizerPhase(runtime(), assumptions).apply(referenceGraph); + new CanonicalizerPhase().apply(referenceGraph, context); assertEquals(referenceGraph, graph, excludeVirtual); } });
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CompareCanonicalizerTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/CompareCanonicalizerTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -35,7 +35,7 @@ private StructuredGraph getCanonicalizedGraph(String name) { StructuredGraph graph = parse(name); - new CanonicalizerPhase(runtime(), null).apply(graph); + new CanonicalizerPhase.Instance(runtime(), null).apply(graph); return graph; } @@ -53,7 +53,7 @@ assertEquals(referenceGraph, graph); } Assumptions assumptions = new Assumptions(false); - new CanonicalizerPhase(runtime(), assumptions).apply(referenceGraph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(referenceGraph); for (int i = 1; i < 4; i++) { StructuredGraph graph = getCanonicalizedGraph("canonicalCompare" + i); assertEquals(referenceGraph, graph);
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/DegeneratedLoopsTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/DegeneratedLoopsTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -82,7 +82,7 @@ public void run() { StructuredGraph graph = parse(snippet); new InliningPhase(runtime(), null, replacements, new Assumptions(false), null, getDefaultPhasePlan(), OptimisticOptimizations.ALL).apply(graph); - new CanonicalizerPhase(runtime(), new Assumptions(false)).apply(graph); + new CanonicalizerPhase.Instance(runtime(), new Assumptions(false)).apply(graph); Debug.dump(graph, "Graph"); StructuredGraph referenceGraph = parse(REFERENCE_SNIPPET); Debug.dump(referenceGraph, "ReferenceGraph");
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IfCanonicalizerTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IfCanonicalizerTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -144,7 +144,7 @@ n.replaceFirstInput(local, constant); } Debug.dump(graph, "Graph"); - new CanonicalizerPhase(runtime(), new Assumptions(false)).apply(graph); + new CanonicalizerPhase.Instance(runtime(), new Assumptions(false)).apply(graph); StructuredGraph referenceGraph = parse(REFERENCE_SNIPPET); assertEquals(referenceGraph, graph); }
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InvokeExceptionTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InvokeExceptionTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -66,7 +66,7 @@ } Assumptions assumptions = new Assumptions(false); new InliningPhase(runtime(), hints, replacements, assumptions, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL).apply(graph); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(graph); new DeadCodeEliminationPhase().apply(graph); } }
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InvokeHintsTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InvokeHintsTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -77,7 +77,7 @@ Assumptions assumptions = new Assumptions(false); new InliningPhase(runtime(), hints, replacements, assumptions, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL).apply(graph); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(graph); new DeadCodeEliminationPhase().apply(graph); StructuredGraph referenceGraph = parse(REFERENCE_SNIPPET); assertEquals(referenceGraph, graph);
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/LoopUnswitchTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/LoopUnswitchTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -133,8 +133,8 @@ } Assumptions assumptions = new Assumptions(false); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); - new CanonicalizerPhase(runtime(), assumptions).apply(referenceGraph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(referenceGraph); Debug.scope("Test", new DebugDumpScope("Test:" + snippet), new Runnable() { @Override
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MonitorGraphTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MonitorGraphTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -94,7 +94,7 @@ } Assumptions assumptions = new Assumptions(false); new InliningPhase(runtime(), hints, replacements, assumptions, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL).apply(graph); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(graph); new DeadCodeEliminationPhase().apply(graph); return graph; }
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/PushNodesThroughPiTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/PushNodesThroughPiTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -83,9 +83,9 @@ private StructuredGraph compileTestSnippet(final String snippet) { StructuredGraph graph = parse(snippet); new LoweringPhase(null, runtime(), replacements, new Assumptions(false)).apply(graph); - new CanonicalizerPhase(runtime(), null).apply(graph); + new CanonicalizerPhase.Instance(runtime(), null).apply(graph); new PushThroughPiPhase().apply(graph); - new CanonicalizerPhase(runtime(), null).apply(graph); + new CanonicalizerPhase.Instance(runtime(), null).apply(graph); return graph; }
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ReadAfterCheckCast.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ReadAfterCheckCast.java Fri Apr 12 18:15:44 2013 +0200 @@ -89,7 +89,7 @@ new FloatingReadPhase().apply(graph); new EliminatePartiallyRedundantGuardsPhase(true, false).apply(graph); new ReadEliminationPhase().apply(graph); - new CanonicalizerPhase(runtime(), null).apply(graph); + new CanonicalizerPhase.Instance(runtime(), null).apply(graph); Debug.dump(graph, "After lowering");
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ReassociateAndCanonicalTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ReassociateAndCanonicalTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -244,9 +244,9 @@ private <T extends Node & Node.IterableNodeType> void test(String test, String ref) { StructuredGraph testGraph = parse(test); Assumptions assumptions = new Assumptions(false); - new CanonicalizerPhase(runtime(), assumptions).apply(testGraph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(testGraph); StructuredGraph refGraph = parse(ref); - new CanonicalizerPhase(runtime(), assumptions).apply(refGraph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(refGraph); assertEquals(testGraph, refGraph); } }
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ScalarTypeSystemTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ScalarTypeSystemTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -166,9 +166,9 @@ StructuredGraph graph = parse(snippet); Debug.dump(graph, "Graph"); Assumptions assumptions = new Assumptions(false); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(graph); new ConditionalEliminationPhase(runtime()).apply(graph); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(graph); StructuredGraph referenceGraph = parse(referenceSnippet); assertEquals(referenceGraph, graph); }
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/StampCanonicalizerTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/StampCanonicalizerTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -98,7 +98,7 @@ private void testZeroReturn(String methodName) { StructuredGraph graph = parse(methodName); - new CanonicalizerPhase(runtime(), new Assumptions(false)).apply(graph); + new CanonicalizerPhase.Instance(runtime(), new Assumptions(false)).apply(graph); new DeadCodeEliminationPhase().apply(graph); assertConstantReturn(graph, 0); }
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/StraighteningTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/StraighteningTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -89,7 +89,7 @@ // No debug scope to reduce console noise for @Test(expected = ...) tests StructuredGraph graph = parse(snippet); Debug.dump(graph, "Graph"); - new CanonicalizerPhase(runtime(), new Assumptions(false)).apply(graph); + new CanonicalizerPhase.Instance(runtime(), new Assumptions(false)).apply(graph); StructuredGraph referenceGraph = parse(REFERENCE_SNIPPET); assertEquals(referenceGraph, graph); }
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/TypeSystemTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/TypeSystemTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -186,13 +186,13 @@ StructuredGraph graph = parse(snippet); Debug.dump(graph, "Graph"); Assumptions assumptions = new Assumptions(false); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(graph); new ConditionalEliminationPhase(runtime()).apply(graph); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(graph); // a second canonicalizer is needed to process nested MaterializeNodes - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(graph); StructuredGraph referenceGraph = parse(referenceSnippet); - new CanonicalizerPhase(runtime(), assumptions).apply(referenceGraph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(referenceGraph); assertEquals(referenceGraph, graph); } @@ -244,9 +244,9 @@ StructuredGraph graph = parse(snippet); Debug.dump(graph, "Graph"); Assumptions assumptions = new Assumptions(false); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(graph); new ConditionalEliminationPhase(runtime()).apply(graph); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(graph); Debug.dump(graph, "Graph"); Assert.assertFalse("shouldn't have nodes of type " + clazz, graph.getNodes(clazz).iterator().hasNext()); }
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/deopt/CompiledMethodTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/deopt/CompiledMethodTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -55,7 +55,7 @@ public void test1() { Method method = getMethod("testMethod"); final StructuredGraph graph = parse(method); - new CanonicalizerPhase(runtime(), new Assumptions(false)).apply(graph); + new CanonicalizerPhase.Instance(runtime(), new Assumptions(false)).apply(graph); new DeadCodeEliminationPhase().apply(graph); for (Node node : graph.getNodes()) {
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EscapeAnalysisTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EscapeAnalysisTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -37,6 +37,7 @@ import com.oracle.graal.nodes.java.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; +import com.oracle.graal.phases.tiers.*; import com.oracle.graal.virtual.nodes.*; import com.oracle.graal.virtual.phases.ea.*; @@ -222,9 +223,10 @@ } Assumptions assumptions = new Assumptions(false); + HighTierContext context = new HighTierContext(runtime(), assumptions); new InliningPhase(runtime(), null, replacements, assumptions, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL).apply(graph); new DeadCodeEliminationPhase().apply(graph); - new PartialEscapeAnalysisPhase(runtime(), assumptions, iterativeEscapeAnalysis, false).apply(graph); + new PartialEscapeAnalysisPhase(iterativeEscapeAnalysis, false).apply(graph, context); Assert.assertEquals(1, graph.getNodes(ReturnNode.class).count()); ReturnNode returnNode = graph.getNodes(ReturnNode.class).first(); if (expectedConstantResult != null) {
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/IterativeInliningTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/IterativeInliningTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -34,6 +34,7 @@ import com.oracle.graal.nodes.java.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; +import com.oracle.graal.phases.tiers.*; import com.oracle.graal.virtual.phases.ea.*; public class IterativeInliningTest extends GraalCompilerTest { @@ -102,6 +103,7 @@ graph = parse(snippet); new ComputeProbabilityPhase().apply(graph); GraalOptions.OptEarlyReadElimination = true; - new IterativeInliningPhase(runtime(), replacements, new Assumptions(false), null, getDefaultPhasePlan(), OptimisticOptimizations.ALL, false).apply(graph); + HighTierContext context = new HighTierContext(runtime(), new Assumptions(false)); + new IterativeInliningPhase(replacements, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL, false).apply(graph, context); } }
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PEAReadEliminationTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PEAReadEliminationTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -34,6 +34,7 @@ import com.oracle.graal.nodes.java.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; +import com.oracle.graal.phases.tiers.*; import com.oracle.graal.virtual.phases.ea.*; public class PEAReadEliminationTest extends GraalCompilerTest { @@ -222,7 +223,8 @@ graph = parse(snippet); new ComputeProbabilityPhase().apply(graph); Assumptions assumptions = new Assumptions(false); + HighTierContext context = new HighTierContext(runtime(), assumptions); new InliningPhase(runtime(), null, replacements, assumptions, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL).apply(graph); - new PartialEscapeAnalysisPhase(runtime(), assumptions, false, true).apply(graph); + new PartialEscapeAnalysisPhase(false, true).apply(graph, context); } }
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PartialEscapeAnalysisTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PartialEscapeAnalysisTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -24,7 +24,7 @@ import java.util.concurrent.*; -import junit.framework.*; +import junit.framework.Assert; import org.junit.Test; @@ -36,6 +36,7 @@ import com.oracle.graal.nodes.java.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; +import com.oracle.graal.phases.tiers.*; import com.oracle.graal.virtual.nodes.*; import com.oracle.graal.virtual.phases.ea.*; @@ -160,14 +161,15 @@ n.node().setProbability(100000); } Assumptions assumptions = new Assumptions(false); + HighTierContext context = new HighTierContext(runtime(), assumptions); new InliningPhase(runtime(), null, replacements, assumptions, null, getDefaultPhasePlan(), OptimisticOptimizations.ALL).apply(graph); new DeadCodeEliminationPhase().apply(graph); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); - new PartialEscapeAnalysisPhase(runtime(), assumptions, false, false).apply(graph); + new CanonicalizerPhase().apply(graph, context); + new PartialEscapeAnalysisPhase(false, false).apply(graph, context); new CullFrameStatesPhase().apply(graph); new DeadCodeEliminationPhase().apply(graph); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase().apply(graph, context); return graph; } });
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/inlining/InliningTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/inlining/InliningTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -162,7 +162,7 @@ Debug.dump(graph, "Graph"); new InliningPhase(runtime(), null, replacements, assumptions, null, phasePlan, OptimisticOptimizations.ALL).apply(graph); Debug.dump(graph, "Graph"); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(graph); new DeadCodeEliminationPhase().apply(graph); return graph; }
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Fri Apr 12 18:15:44 2013 +0200 @@ -36,7 +36,6 @@ import com.oracle.graal.debug.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; -import com.oracle.graal.loop.phases.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.cfg.*; import com.oracle.graal.nodes.spi.*; @@ -120,18 +119,20 @@ } if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(runtime, assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime, assumptions).apply(graph); } + HighTierContext highTierContext = new HighTierContext(runtime, assumptions); + if (GraalOptions.Inline && !plan.isPhaseDisabled(InliningPhase.class)) { if (GraalOptions.IterativeInlining) { - new IterativeInliningPhase(runtime, replacements, assumptions, cache, plan, optimisticOpts, GraalOptions.OptEarlyReadElimination).apply(graph); + new IterativeInliningPhase(replacements, cache, plan, optimisticOpts, GraalOptions.OptEarlyReadElimination).apply(graph, highTierContext); } else { new InliningPhase(runtime, null, replacements, assumptions, cache, plan, optimisticOpts).apply(graph); new DeadCodeEliminationPhase().apply(graph); if (GraalOptions.ConditionalElimination && GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(runtime, assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime, assumptions).apply(graph); new IterativeConditionalEliminationPhase(runtime, assumptions).apply(graph); } } @@ -139,44 +140,21 @@ plan.runPhases(PhasePosition.HIGH_LEVEL, graph); - if (GraalOptions.FullUnroll) { - new LoopFullUnrollPhase(runtime, assumptions).apply(graph); - if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(runtime, assumptions).apply(graph); - } - } - - if (GraalOptions.OptTailDuplication) { - new TailDuplicationPhase().apply(graph); - if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(runtime, assumptions).apply(graph); - } - } - - if (GraalOptions.PartialEscapeAnalysis && !plan.isPhaseDisabled(PartialEscapeAnalysisPhase.class)) { - new PartialEscapeAnalysisPhase(runtime, assumptions, true, GraalOptions.OptEarlyReadElimination).apply(graph); - } - - HighTierContext highTierContext = new HighTierContext(runtime, assumptions); Suites.HIGH_TIER.apply(graph, highTierContext); - if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(runtime, assumptions).apply(graph); - } - new LoweringPhase(target, runtime, replacements, assumptions).apply(graph); if (GraalOptions.OptPushThroughPi) { new PushThroughPiPhase().apply(graph); if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(runtime, assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime, assumptions).apply(graph); } } if (GraalOptions.OptFloatingReads) { int mark = graph.getMark(); new FloatingReadPhase().apply(graph); - new CanonicalizerPhase(runtime, assumptions, mark, null).apply(graph); + new CanonicalizerPhase.Instance(runtime, assumptions, mark, null).apply(graph); if (GraalOptions.OptReadElimination) { new ReadEliminationPhase().apply(graph); } @@ -184,7 +162,7 @@ new RemoveValueProxyPhase().apply(graph); if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(runtime, assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime, assumptions).apply(graph); } if (GraalOptions.OptEliminatePartiallyRedundantGuards) { @@ -200,7 +178,7 @@ } if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(runtime, assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime, assumptions).apply(graph); } plan.runPhases(PhasePosition.MID_LEVEL, graph);
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/Suites.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/Suites.java Fri Apr 12 18:15:44 2013 +0200 @@ -28,6 +28,7 @@ import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; import com.oracle.graal.phases.tiers.*; +import com.oracle.graal.virtual.phases.ea.*; public class Suites { @@ -36,6 +37,24 @@ private static PhaseSuite<HighTierContext> createHighTier() { ArrayList<BasePhase<? super HighTierContext>> phases = new ArrayList<>(); + if (GraalOptions.FullUnroll) { + phases.add(new LoopFullUnrollPhase()); + if (GraalOptions.OptCanonicalizer) { + phases.add(new CanonicalizerPhase()); + } + } + + if (GraalOptions.OptTailDuplication) { + phases.add(new TailDuplicationPhase()); + if (GraalOptions.OptCanonicalizer) { + phases.add(new CanonicalizerPhase()); + } + } + + if (GraalOptions.PartialEscapeAnalysis) { + phases.add(new PartialEscapeAnalysisPhase(true, GraalOptions.OptEarlyReadElimination)); + } + if (GraalOptions.OptConvertDeoptsToGuards) { phases.add(new ConvertDeoptimizeToGuardPhase()); } @@ -52,6 +71,10 @@ phases.add(new CullFrameStatesPhase()); } + if (GraalOptions.OptCanonicalizer) { + phases.add(new CanonicalizerPhase()); + } + return new PhaseSuite<>("HighTier", phases); } }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ArrayCopyNode.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ArrayCopyNode.java Fri Apr 12 18:15:44 2013 +0200 @@ -31,6 +31,7 @@ import com.oracle.graal.nodes.virtual.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; +import com.oracle.graal.phases.tiers.*; import com.oracle.graal.replacements.nodes.*; public class ArrayCopyNode extends MacroNode implements Virtualizable, IterableNodeType, Lowerable { @@ -81,9 +82,10 @@ } // the canonicalization before loop unrolling is needed to propagate the length into // additions, etc. - new CanonicalizerPhase(tool.getRuntime(), tool.assumptions()).apply(snippetGraph); - new LoopFullUnrollPhase(tool.getRuntime(), tool.assumptions()).apply(snippetGraph); - new CanonicalizerPhase(tool.getRuntime(), tool.assumptions()).apply(snippetGraph); + HighTierContext context = new HighTierContext(tool.getRuntime(), tool.assumptions()); + new CanonicalizerPhase().apply(snippetGraph, context); + new LoopFullUnrollPhase().apply(snippetGraph, context); + new CanonicalizerPhase().apply(snippetGraph, context); } @Override
--- a/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopTransformations.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopTransformations.java Fri Apr 12 18:15:44 2013 +0200 @@ -60,7 +60,7 @@ while (!loopBegin.isDeleted()) { int mark = graph.getMark(); peel(loop); - new CanonicalizerPhase(runtime, assumptions, mark, null).apply(graph); + new CanonicalizerPhase.Instance(runtime, assumptions, mark, null).apply(graph); if (iterations++ > UNROLL_LIMIT || graph.getNodeCount() > GraalOptions.MaximumDesiredSize * 3) { throw new BailoutException("FullUnroll : Graph seems to grow out of proportion"); }
--- a/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/phases/LoopFullUnrollPhase.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/phases/LoopFullUnrollPhase.java Fri Apr 12 18:15:44 2013 +0200 @@ -22,31 +22,21 @@ */ package com.oracle.graal.loop.phases; -import com.oracle.graal.api.code.*; import com.oracle.graal.debug.*; import com.oracle.graal.loop.*; import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; import com.oracle.graal.phases.*; +import com.oracle.graal.phases.tiers.*; -public class LoopFullUnrollPhase extends Phase { +public class LoopFullUnrollPhase extends BasePhase<HighTierContext> { private static final DebugMetric FULLY_UNROLLED_LOOPS = Debug.metric("FullUnrolls"); - private final GraalCodeCacheProvider runtime; - private final Assumptions assumptions; - private int unrollCount; - public LoopFullUnrollPhase(GraalCodeCacheProvider runtime, Assumptions assumptions) { - this.runtime = runtime; - this.assumptions = assumptions; - } - - public int getUnrollCount() { - return unrollCount; + public LoopFullUnrollPhase() { } @Override - protected void run(StructuredGraph graph) { + protected void run(StructuredGraph graph, HighTierContext context) { if (graph.hasLoops()) { boolean peeled; do { @@ -56,11 +46,10 @@ for (LoopEx loop : dataCounted.countedLoops()) { if (LoopPolicies.shouldFullUnroll(loop)) { Debug.log("FullUnroll %s", loop); - LoopTransformations.fullUnroll(loop, runtime, assumptions); + LoopTransformations.fullUnroll(loop, context.getRuntime(), context.getAssumptions()); FULLY_UNROLLED_LOOPS.increment(); Debug.dump(graph, "After fullUnroll %s", loop); peeled = true; - unrollCount++; break; } }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java Fri Apr 12 18:15:44 2013 +0200 @@ -36,8 +36,9 @@ import com.oracle.graal.nodes.type.*; import com.oracle.graal.nodes.util.*; import com.oracle.graal.phases.*; +import com.oracle.graal.phases.tiers.*; -public class CanonicalizerPhase extends Phase { +public class CanonicalizerPhase extends BasePhase<PhaseContext> { private static final int MAX_ITERATION_PER_NODE = 10; private static final DebugMetric METRIC_CANONICALIZED_NODES = Debug.metric("CanonicalizedNodes"); @@ -47,155 +48,163 @@ private static final DebugMetric METRIC_SIMPLIFICATION_CONSIDERED_NODES = Debug.metric("SimplificationConsideredNodes"); public static final DebugMetric METRIC_GLOBAL_VALUE_NUMBERING_HITS = Debug.metric("GlobalValueNumberingHits"); - private final int newNodesMark; - private final Assumptions assumptions; - private final MetaAccessProvider runtime; - private final CustomCanonicalizer customCanonicalizer; - private final Iterable<Node> initWorkingSet; - - private NodeWorkList workList; - private Tool tool; - private List<Node> snapshotTemp; - public interface CustomCanonicalizer { ValueNode canonicalize(Node node); } - public CanonicalizerPhase(MetaAccessProvider runtime, Assumptions assumptions) { - this(runtime, assumptions, null, 0, null); - } - - /** - * @param runtime - * @param assumptions - * @param workingSet the initial working set of nodes on which the canonicalizer works, should - * be an auto-grow node bitmap - * @param customCanonicalizer - */ - public CanonicalizerPhase(MetaAccessProvider runtime, Assumptions assumptions, Iterable<Node> workingSet, CustomCanonicalizer customCanonicalizer) { - this(runtime, assumptions, workingSet, 0, customCanonicalizer); - } - - /** - * @param newNodesMark only the {@linkplain Graph#getNewNodes(int) new nodes} specified by this - * mark are processed otherwise all nodes in the graph are processed - */ - public CanonicalizerPhase(MetaAccessProvider runtime, Assumptions assumptions, int newNodesMark, CustomCanonicalizer customCanonicalizer) { - this(runtime, assumptions, null, newNodesMark, customCanonicalizer); - } - - public CanonicalizerPhase(MetaAccessProvider runtime, Assumptions assumptions, Iterable<Node> workingSet, int newNodesMark, CustomCanonicalizer customCanonicalizer) { - this.newNodesMark = newNodesMark; - this.assumptions = assumptions; - this.runtime = runtime; - this.customCanonicalizer = customCanonicalizer; - this.initWorkingSet = workingSet; - this.snapshotTemp = new ArrayList<>(); - } - @Override - protected void run(StructuredGraph graph) { - if (initWorkingSet == null) { - workList = graph.createNodeWorkList(newNodesMark == 0, MAX_ITERATION_PER_NODE); - } else { - workList = graph.createNodeWorkList(false, MAX_ITERATION_PER_NODE); - workList.addAll(initWorkingSet); - } - if (newNodesMark > 0) { - workList.addAll(graph.getNewNodes(newNodesMark)); - } - tool = new Tool(workList, runtime, assumptions); - processWorkSet(graph); - } - - private void processWorkSet(StructuredGraph graph) { - graph.trackInputChange(new InputChangedListener() { - - @Override - public void inputChanged(Node node) { - workList.addAgain(node); - } - }); - - for (Node n : workList) { - processNode(n, graph); - } - - graph.stopTrackingInputChange(); + protected void run(StructuredGraph graph, PhaseContext context) { + new Instance(context.getRuntime(), context.getAssumptions()).run(graph); } - private void processNode(Node node, StructuredGraph graph) { - if (node.isAlive()) { - METRIC_PROCESSED_NODES.increment(); + public static class Instance extends Phase { + + private final int newNodesMark; + private final Assumptions assumptions; + private final MetaAccessProvider runtime; + private final CustomCanonicalizer customCanonicalizer; + private final Iterable<Node> initWorkingSet; + + private NodeWorkList workList; + private Tool tool; + private List<Node> snapshotTemp; + + public Instance(MetaAccessProvider runtime, Assumptions assumptions) { + this(runtime, assumptions, null, 0, null); + } - if (tryGlobalValueNumbering(node, graph)) { - return; + /** + * @param runtime + * @param assumptions + * @param workingSet the initial working set of nodes on which the canonicalizer works, + * should be an auto-grow node bitmap + * @param customCanonicalizer + */ + public Instance(MetaAccessProvider runtime, Assumptions assumptions, Iterable<Node> workingSet, CustomCanonicalizer customCanonicalizer) { + this(runtime, assumptions, workingSet, 0, customCanonicalizer); + } + + /** + * @param newNodesMark only the {@linkplain Graph#getNewNodes(int) new nodes} specified by + * this mark are processed otherwise all nodes in the graph are processed + */ + public Instance(MetaAccessProvider runtime, Assumptions assumptions, int newNodesMark, CustomCanonicalizer customCanonicalizer) { + this(runtime, assumptions, null, newNodesMark, customCanonicalizer); + } + + public Instance(MetaAccessProvider runtime, Assumptions assumptions, Iterable<Node> workingSet, int newNodesMark, CustomCanonicalizer customCanonicalizer) { + super("Canonicalizer"); + this.newNodesMark = newNodesMark; + this.assumptions = assumptions; + this.runtime = runtime; + this.customCanonicalizer = customCanonicalizer; + this.initWorkingSet = workingSet; + this.snapshotTemp = new ArrayList<>(); + } + + @Override + protected void run(StructuredGraph graph) { + if (initWorkingSet == null) { + workList = graph.createNodeWorkList(newNodesMark == 0, MAX_ITERATION_PER_NODE); + } else { + workList = graph.createNodeWorkList(false, MAX_ITERATION_PER_NODE); + workList.addAll(initWorkingSet); } - int mark = graph.getMark(); - if (!tryKillUnused(node)) { - node.inputs().filter(GraphUtil.isFloatingNode()).snapshotTo(snapshotTemp); - if (!tryCanonicalize(node, graph)) { - tryInferStamp(node, graph); - } else { - for (Node in : snapshotTemp) { - if (in.isAlive() && in.usages().isEmpty()) { - GraphUtil.killWithUnusedFloatingInputs(in); + if (newNodesMark > 0) { + workList.addAll(graph.getNewNodes(newNodesMark)); + } + tool = new Tool(workList, runtime, assumptions); + processWorkSet(graph); + } + + private void processWorkSet(StructuredGraph graph) { + graph.trackInputChange(new InputChangedListener() { + + @Override + public void inputChanged(Node node) { + workList.addAgain(node); + } + }); + + for (Node n : workList) { + processNode(n, graph); + } + + graph.stopTrackingInputChange(); + } + + private void processNode(Node node, StructuredGraph graph) { + if (node.isAlive()) { + METRIC_PROCESSED_NODES.increment(); + + if (tryGlobalValueNumbering(node, graph)) { + return; + } + int mark = graph.getMark(); + if (!tryKillUnused(node)) { + node.inputs().filter(GraphUtil.isFloatingNode()).snapshotTo(snapshotTemp); + if (!tryCanonicalize(node, graph)) { + tryInferStamp(node, graph); + } else { + for (Node in : snapshotTemp) { + if (in.isAlive() && in.usages().isEmpty()) { + GraphUtil.killWithUnusedFloatingInputs(in); + } } } + snapshotTemp.clear(); } - snapshotTemp.clear(); - } - for (Node newNode : graph.getNewNodes(mark)) { - workList.add(newNode); + for (Node newNode : graph.getNewNodes(mark)) { + workList.add(newNode); + } } } - } - private static boolean tryKillUnused(Node node) { - if (node.isAlive() && GraphUtil.isFloatingNode().apply(node) && node.usages().isEmpty()) { - GraphUtil.killWithUnusedFloatingInputs(node); - return true; - } - return false; - } - - public static boolean tryGlobalValueNumbering(Node node, StructuredGraph graph) { - if (node.getNodeClass().valueNumberable()) { - Node newNode = graph.findDuplicate(node); - if (newNode != null) { - assert !(node instanceof FixedNode || newNode instanceof FixedNode); - node.replaceAtUsages(newNode); - node.safeDelete(); - METRIC_GLOBAL_VALUE_NUMBERING_HITS.increment(); - Debug.log("GVN applied and new node is %1s", newNode); + private static boolean tryKillUnused(Node node) { + if (node.isAlive() && GraphUtil.isFloatingNode().apply(node) && node.usages().isEmpty()) { + GraphUtil.killWithUnusedFloatingInputs(node); return true; } + return false; } - return false; - } - public boolean tryCanonicalize(final Node node, final StructuredGraph graph) { - boolean result = baseTryCanonicalize(node, graph); - if (!result && customCanonicalizer != null) { - ValueNode canonical = customCanonicalizer.canonicalize(node); - if (canonical == node && customCanonicalizer != null) { - canonical = customCanonicalizer.canonicalize(node); + public static boolean tryGlobalValueNumbering(Node node, StructuredGraph graph) { + if (node.getNodeClass().valueNumberable()) { + Node newNode = graph.findDuplicate(node); + if (newNode != null) { + assert !(node instanceof FixedNode || newNode instanceof FixedNode); + node.replaceAtUsages(newNode); + node.safeDelete(); + METRIC_GLOBAL_VALUE_NUMBERING_HITS.increment(); + Debug.log("GVN applied and new node is %1s", newNode); + return true; + } } - result = performReplacement(node, graph, canonical); + return false; } - return result; - } - public boolean baseTryCanonicalize(final Node node, final StructuredGraph graph) { - if (node instanceof Canonicalizable) { - assert !(node instanceof Simplifiable); - METRIC_CANONICALIZATION_CONSIDERED_NODES.increment(); - return Debug.scope("CanonicalizeNode", node, new Callable<Boolean>() { + public boolean tryCanonicalize(final Node node, final StructuredGraph graph) { + boolean result = baseTryCanonicalize(node, graph); + if (!result && customCanonicalizer != null) { + ValueNode canonical = customCanonicalizer.canonicalize(node); + if (canonical == node && customCanonicalizer != null) { + canonical = customCanonicalizer.canonicalize(node); + } + result = performReplacement(node, graph, canonical); + } + return result; + } - public Boolean call() { - ValueNode canonical = ((Canonicalizable) node).canonical(tool); + public boolean baseTryCanonicalize(final Node node, final StructuredGraph graph) { + if (node instanceof Canonicalizable) { + assert !(node instanceof Simplifiable); + METRIC_CANONICALIZATION_CONSIDERED_NODES.increment(); + return Debug.scope("CanonicalizeNode", node, new Callable<Boolean>() { + + public Boolean call() { + ValueNode canonical = ((Canonicalizable) node).canonical(tool); // @formatter:off // cases: original node: // |Floating|Fixed-unconnected|Fixed-connected| @@ -211,137 +220,139 @@ // X: must not happen (checked with assertions) // @formatter:on - return performReplacement(node, graph, canonical); - } - }); - } else if (node instanceof Simplifiable) { - Debug.log("Canonicalizer: simplifying %s", node); - METRIC_SIMPLIFICATION_CONSIDERED_NODES.increment(); - Debug.scope("SimplifyNode", node, new Runnable() { + return performReplacement(node, graph, canonical); + } + }); + } else if (node instanceof Simplifiable) { + Debug.log("Canonicalizer: simplifying %s", node); + METRIC_SIMPLIFICATION_CONSIDERED_NODES.increment(); + Debug.scope("SimplifyNode", node, new Runnable() { - public void run() { - ((Simplifiable) node).simplify(tool); - } - }); + public void run() { + ((Simplifiable) node).simplify(tool); + } + }); + } + return node.isDeleted(); } - return node.isDeleted(); - } - private boolean performReplacement(final Node node, final StructuredGraph graph, ValueNode canonical) { - if (canonical == node) { - Debug.log("Canonicalizer: work on %s", node); - return false; - } else { - Debug.log("Canonicalizer: replacing %s with %s", node, canonical); - METRIC_CANONICALIZED_NODES.increment(); - if (node instanceof FloatingNode) { - if (canonical == null) { - // case 1 - graph.removeFloating((FloatingNode) node); + private boolean performReplacement(final Node node, final StructuredGraph graph, ValueNode canonical) { + if (canonical == node) { + Debug.log("Canonicalizer: work on %s", node); + return false; + } else { + Debug.log("Canonicalizer: replacing %s with %s", node, canonical); + METRIC_CANONICALIZED_NODES.increment(); + if (node instanceof FloatingNode) { + if (canonical == null) { + // case 1 + graph.removeFloating((FloatingNode) node); + } else { + // case 2 + assert !(canonical instanceof FixedNode) || (canonical.predecessor() != null || canonical instanceof StartNode || canonical instanceof MergeNode) : node + " -> " + canonical + + " : replacement should be floating or fixed and connected"; + graph.replaceFloating((FloatingNode) node, canonical); + } } else { - // case 2 - assert !(canonical instanceof FixedNode) || (canonical.predecessor() != null || canonical instanceof StartNode || canonical instanceof MergeNode) : node + " -> " + canonical + - " : replacement should be floating or fixed and connected"; - graph.replaceFloating((FloatingNode) node, canonical); - } - } else { - assert node instanceof FixedWithNextNode && node.predecessor() != null : node + " -> " + canonical + " : node should be fixed & connected (" + node.predecessor() + ")"; - FixedWithNextNode fixedWithNext = (FixedWithNextNode) node; + assert node instanceof FixedWithNextNode && node.predecessor() != null : node + " -> " + canonical + " : node should be fixed & connected (" + node.predecessor() + ")"; + FixedWithNextNode fixedWithNext = (FixedWithNextNode) node; - // When removing a fixed node, new canonicalization opportunities for its successor - // may arise - assert fixedWithNext.next() != null; - tool.addToWorkList(fixedWithNext.next()); + // When removing a fixed node, new canonicalization opportunities for its +// successor + // may arise + assert fixedWithNext.next() != null; + tool.addToWorkList(fixedWithNext.next()); - if (canonical == null) { - // case 3 - graph.removeFixed(fixedWithNext); - } else if (canonical instanceof FloatingNode) { - // case 4 - graph.replaceFixedWithFloating(fixedWithNext, (FloatingNode) canonical); - } else { - assert canonical instanceof FixedNode; - if (canonical.predecessor() == null) { - assert !canonical.cfgSuccessors().iterator().hasNext() : "replacement " + canonical + " shouldn't have successors"; - // case 5 - graph.replaceFixedWithFixed(fixedWithNext, (FixedWithNextNode) canonical); + if (canonical == null) { + // case 3 + graph.removeFixed(fixedWithNext); + } else if (canonical instanceof FloatingNode) { + // case 4 + graph.replaceFixedWithFloating(fixedWithNext, (FloatingNode) canonical); } else { - assert canonical.cfgSuccessors().iterator().hasNext() : "replacement " + canonical + " should have successors"; - // case 6 - node.replaceAtUsages(canonical); - graph.removeFixed(fixedWithNext); + assert canonical instanceof FixedNode; + if (canonical.predecessor() == null) { + assert !canonical.cfgSuccessors().iterator().hasNext() : "replacement " + canonical + " shouldn't have successors"; + // case 5 + graph.replaceFixedWithFixed(fixedWithNext, (FixedWithNextNode) canonical); + } else { + assert canonical.cfgSuccessors().iterator().hasNext() : "replacement " + canonical + " should have successors"; + // case 6 + node.replaceAtUsages(canonical); + graph.removeFixed(fixedWithNext); + } } } + return true; } - return true; } - } - /** - * Calls {@link ValueNode#inferStamp()} on the node and, if it returns true (which means that - * the stamp has changed), re-queues the node's usages . If the stamp has changed then this - * method also checks if the stamp now describes a constant integer value, in which case the - * node is replaced with a constant. - */ - private void tryInferStamp(Node node, StructuredGraph graph) { - if (node.isAlive() && node instanceof ValueNode) { - ValueNode valueNode = (ValueNode) node; - METRIC_INFER_STAMP_CALLED.increment(); - if (valueNode.inferStamp()) { - METRIC_STAMP_CHANGED.increment(); - if (valueNode.stamp() instanceof IntegerStamp && valueNode.integerStamp().lowerBound() == valueNode.integerStamp().upperBound()) { - ValueNode replacement = ConstantNode.forIntegerKind(valueNode.kind(), valueNode.integerStamp().lowerBound(), graph); - Debug.log("Canonicalizer: replacing %s with %s (inferStamp)", valueNode, replacement); - valueNode.replaceAtUsages(replacement); - } else { - for (Node usage : valueNode.usages()) { - workList.addAgain(usage); + /** + * Calls {@link ValueNode#inferStamp()} on the node and, if it returns true (which means + * that the stamp has changed), re-queues the node's usages . If the stamp has changed then + * this method also checks if the stamp now describes a constant integer value, in which + * case the node is replaced with a constant. + */ + private void tryInferStamp(Node node, StructuredGraph graph) { + if (node.isAlive() && node instanceof ValueNode) { + ValueNode valueNode = (ValueNode) node; + METRIC_INFER_STAMP_CALLED.increment(); + if (valueNode.inferStamp()) { + METRIC_STAMP_CHANGED.increment(); + if (valueNode.stamp() instanceof IntegerStamp && valueNode.integerStamp().lowerBound() == valueNode.integerStamp().upperBound()) { + ValueNode replacement = ConstantNode.forIntegerKind(valueNode.kind(), valueNode.integerStamp().lowerBound(), graph); + Debug.log("Canonicalizer: replacing %s with %s (inferStamp)", valueNode, replacement); + valueNode.replaceAtUsages(replacement); + } else { + for (Node usage : valueNode.usages()) { + workList.addAgain(usage); + } } } } } - } - private static final class Tool implements SimplifierTool { + private static final class Tool implements SimplifierTool { - private final NodeWorkList nodeWorkSet; - private final MetaAccessProvider runtime; - private final Assumptions assumptions; + private final NodeWorkList nodeWorkSet; + private final MetaAccessProvider runtime; + private final Assumptions assumptions; - public Tool(NodeWorkList nodeWorkSet, MetaAccessProvider runtime, Assumptions assumptions) { - this.nodeWorkSet = nodeWorkSet; - this.runtime = runtime; - this.assumptions = assumptions; - } + public Tool(NodeWorkList nodeWorkSet, MetaAccessProvider runtime, Assumptions assumptions) { + this.nodeWorkSet = nodeWorkSet; + this.runtime = runtime; + this.assumptions = assumptions; + } - @Override - public void deleteBranch(FixedNode branch) { - branch.predecessor().replaceFirstSuccessor(branch, null); - GraphUtil.killCFG(branch); - } + @Override + public void deleteBranch(FixedNode branch) { + branch.predecessor().replaceFirstSuccessor(branch, null); + GraphUtil.killCFG(branch); + } - /** - * @return an object that can be used for recording assumptions or {@code null} if - * assumptions are not allowed in the current context. - */ - @Override - public Assumptions assumptions() { - return assumptions; - } + /** + * @return an object that can be used for recording assumptions or {@code null} if + * assumptions are not allowed in the current context. + */ + @Override + public Assumptions assumptions() { + return assumptions; + } - @Override - public MetaAccessProvider runtime() { - return runtime; - } + @Override + public MetaAccessProvider runtime() { + return runtime; + } - @Override - public void addToWorkList(Node node) { - nodeWorkSet.addAgain(node); - } + @Override + public void addToWorkList(Node node) { + nodeWorkSet.addAgain(node); + } - @Override - public void removeIfUnused(Node node) { - tryKillUnused(node); + @Override + public void removeIfUnused(Node node) { + tryKillUnused(node); + } } } }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java Fri Apr 12 18:15:44 2013 +0200 @@ -117,7 +117,7 @@ Iterable<Node> newNodes = graph.getNewNodes(mark); inliningPolicy.scanInvokes(newNodes); if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(runtime, assumptions, invokeUsages, mark, customCanonicalizer).apply(graph); + new CanonicalizerPhase.Instance(runtime, assumptions, invokeUsages, mark, customCanonicalizer).apply(graph); } inliningCount++; metricInliningPerformed.increment(); @@ -161,7 +161,7 @@ new ComputeProbabilityPhase().apply(newGraph); } if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(runtime, assumptions).apply(newGraph); + new CanonicalizerPhase.Instance(runtime, assumptions).apply(newGraph); } if (GraalOptions.CullFrameStates) { new CullFrameStatesPhase().apply(newGraph);
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IterativeConditionalEliminationPhase.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IterativeConditionalEliminationPhase.java Fri Apr 12 18:15:44 2013 +0200 @@ -53,7 +53,7 @@ if (canonicalizationRoots.isEmpty()) { break; } - new CanonicalizerPhase(runtime, assumptions, canonicalizationRoots, null).apply(graph); + new CanonicalizerPhase.Instance(runtime, assumptions, canonicalizationRoots, null).apply(graph); canonicalizationRoots.clear(); } }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java Fri Apr 12 18:15:44 2013 +0200 @@ -151,7 +151,7 @@ deferred = false; processBlock(schedule.getCFG().getStartBlock(), graph.createNodeBitMap(), null, schedule, processed); Debug.dump(graph, "Lowering iteration %d", i++); - new CanonicalizerPhase(runtime, assumptions, mark, null).apply(graph); + new CanonicalizerPhase.Instance(runtime, assumptions, mark, null).apply(graph); if (!deferred && !containsLowerable(graph.getNewNodes(mark))) { // No new lowerable nodes - done!
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/TailDuplicationPhase.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/TailDuplicationPhase.java Fri Apr 12 18:15:44 2013 +0200 @@ -127,21 +127,13 @@ } }; - private int tailDuplicationCount; - - public int getTailDuplicationCount() { - return tailDuplicationCount; - } - @Override protected void run(StructuredGraph graph) { // A snapshot is taken here, so that new MergeNode instances aren't considered for tail // duplication. for (MergeNode merge : graph.getNodes(MergeNode.class).snapshot()) { if (!(merge instanceof LoopBeginNode) && merge.probability() >= GraalOptions.TailDuplicationProbability) { - if (tailDuplicate(merge, DEFAULT_DECISION, null)) { - tailDuplicationCount++; - } + tailDuplicate(merge, DEFAULT_DECISION, null); } } }
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/HighTierContext.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/HighTierContext.java Fri Apr 12 18:15:44 2013 +0200 @@ -25,21 +25,9 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; -public class HighTierContext { - - private final MetaAccessProvider runtime; - private final Assumptions assumptions; +public class HighTierContext extends PhaseContext { public HighTierContext(MetaAccessProvider runtime, Assumptions assumptions) { - this.runtime = runtime; - this.assumptions = assumptions; - } - - public MetaAccessProvider getRuntime() { - return runtime; - } - - public Assumptions getAssumptions() { - return assumptions; + super(runtime, assumptions); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/PhaseContext.java Fri Apr 12 18:15:44 2013 +0200 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.phases.tiers; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; + +public class PhaseContext { + + private final MetaAccessProvider runtime; + private final Assumptions assumptions; + + public PhaseContext(MetaAccessProvider runtime, Assumptions assumptions) { + this.runtime = runtime; + this.assumptions = assumptions; + } + + public MetaAccessProvider getRuntime() { + return runtime; + } + + public Assumptions getAssumptions() { + return assumptions; + } +}
--- a/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/MethodSubstitutionTest.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/MethodSubstitutionTest.java Fri Apr 12 18:15:44 2013 +0200 @@ -54,7 +54,7 @@ Debug.dump(graph, "Graph"); new InliningPhase(runtime(), null, replacements, assumptions, null, phasePlan, OptimisticOptimizations.ALL).apply(graph); Debug.dump(graph, "Graph"); - new CanonicalizerPhase(runtime(), assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime(), assumptions).apply(graph); new DeadCodeEliminationPhase().apply(graph); assertNotInGraph(graph, Invoke.class);
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Fri Apr 12 18:15:44 2013 +0200 @@ -323,7 +323,7 @@ protected void afterInline(StructuredGraph caller, StructuredGraph callee) { if (GraalOptions.OptCanonicalizer) { new WordTypeRewriterPhase(runtime, target.wordKind).apply(caller); - new CanonicalizerPhase(runtime, assumptions).apply(caller); + new CanonicalizerPhase.Instance(runtime, assumptions).apply(caller); } } @@ -337,7 +337,7 @@ new DeadCodeEliminationPhase().apply(graph); if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(runtime, assumptions).apply(graph); + new CanonicalizerPhase.Instance(runtime, assumptions).apply(graph); } }
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Fri Apr 12 18:15:44 2013 +0200 @@ -375,7 +375,7 @@ new NodeIntrinsificationPhase(runtime).apply(snippetCopy); new WordTypeRewriterPhase(runtime, target.wordKind).apply(snippetCopy); - new CanonicalizerPhase(runtime, replacements.getAssumptions(), 0, null).apply(snippetCopy); + new CanonicalizerPhase.Instance(runtime, replacements.getAssumptions(), 0, null).apply(snippetCopy); } assert NodeIntrinsificationVerificationPhase.verify(snippetCopy); @@ -432,7 +432,7 @@ LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin); int mark = snippetCopy.getMark(); LoopTransformations.fullUnroll(loop, runtime, null); - new CanonicalizerPhase(runtime, replacements.getAssumptions(), mark, null).apply(snippetCopy); + new CanonicalizerPhase.Instance(runtime, replacements.getAssumptions(), mark, null).apply(snippetCopy); } FixedNode explodeLoopNext = explodeLoop.next(); explodeLoop.clearSuccessors();
--- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/IterativeInliningPhase.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/IterativeInliningPhase.java Fri Apr 12 18:15:44 2013 +0200 @@ -25,28 +25,24 @@ import java.util.*; import java.util.concurrent.*; -import com.oracle.graal.api.code.*; import com.oracle.graal.debug.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; +import com.oracle.graal.phases.tiers.*; -public class IterativeInliningPhase extends Phase { +public class IterativeInliningPhase extends BasePhase<HighTierContext> { private final PhasePlan plan; - private final GraalCodeCacheProvider runtime; private final Replacements replacements; - private final Assumptions assumptions; private final GraphCache cache; private final OptimisticOptimizations optimisticOpts; private final boolean readElimination; - public IterativeInliningPhase(GraalCodeCacheProvider runtime, Replacements replacements, Assumptions assumptions, GraphCache cache, PhasePlan plan, OptimisticOptimizations optimisticOpts, boolean readElimination) { - this.runtime = runtime; + public IterativeInliningPhase(Replacements replacements, GraphCache cache, PhasePlan plan, OptimisticOptimizations optimisticOpts, boolean readElimination) { this.replacements = replacements; - this.assumptions = assumptions; this.cache = cache; this.plan = plan; this.optimisticOpts = optimisticOpts; @@ -60,12 +56,12 @@ } @Override - protected void run(final StructuredGraph graph) { - runIterations(graph, true); - runIterations(graph, false); + protected void run(final StructuredGraph graph, final HighTierContext context) { + runIterations(graph, true, context); + runIterations(graph, false, context); } - private void runIterations(final StructuredGraph graph, final boolean simple) { + private void runIterations(final StructuredGraph graph, final boolean simple, final HighTierContext context) { Boolean continueIteration = true; for (int iteration = 0; iteration < GraalOptions.EscapeAnalysisIterations && continueIteration; iteration++) { continueIteration = Debug.scope("iteration " + iteration, new Callable<Boolean>() { @@ -73,13 +69,13 @@ @Override public Boolean call() { boolean progress = false; - PartialEscapeAnalysisPhase ea = new PartialEscapeAnalysisPhase(runtime, assumptions, false, readElimination); - ea.apply(graph); - progress |= ea.hasChanged(); + PartialEscapeAnalysisPhase ea = new PartialEscapeAnalysisPhase(false, readElimination); + boolean eaResult = ea.runAnalysis(graph, context); + progress |= eaResult; Map<Invoke, Double> hints = GraalOptions.PEAInliningHints ? PartialEscapeAnalysisPhase.getHints(graph) : null; - InliningPhase inlining = new InliningPhase(runtime, hints, replacements, assumptions, cache, plan, optimisticOpts); + InliningPhase inlining = new InliningPhase(context.getRuntime(), hints, replacements, context.getAssumptions(), cache, plan, optimisticOpts); inlining.setMaxMethodsPerInlining(simple ? 1 : Integer.MAX_VALUE); inlining.apply(graph); progress |= inlining.getInliningCount() > 0; @@ -87,8 +83,8 @@ new DeadCodeEliminationPhase().apply(graph); if (GraalOptions.ConditionalElimination && GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(runtime, assumptions).apply(graph); - new IterativeConditionalEliminationPhase(runtime, assumptions).apply(graph); + new CanonicalizerPhase().apply(graph, context); + new IterativeConditionalEliminationPhase(context.getRuntime(), context.getAssumptions()).apply(graph); } return progress;
--- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeAnalysisPhase.java Fri Apr 12 17:23:14 2013 +0200 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeAnalysisPhase.java Fri Apr 12 18:15:44 2013 +0200 @@ -25,7 +25,6 @@ import java.util.*; import java.util.concurrent.*; -import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.debug.*; import com.oracle.graal.graph.*; @@ -37,33 +36,25 @@ import com.oracle.graal.phases.common.CanonicalizerPhase.CustomCanonicalizer; import com.oracle.graal.phases.graph.*; import com.oracle.graal.phases.schedule.*; +import com.oracle.graal.phases.tiers.*; import com.oracle.graal.virtual.nodes.*; -public class PartialEscapeAnalysisPhase extends Phase { +public class PartialEscapeAnalysisPhase extends BasePhase<HighTierContext> { - private final MetaAccessProvider runtime; - private final Assumptions assumptions; - private CustomCanonicalizer customCanonicalizer; + private final CustomCanonicalizer customCanonicalizer; private final boolean iterative; private final boolean readElimination; - private boolean changed; + public PartialEscapeAnalysisPhase(boolean iterative, boolean readElimination) { + this(null, iterative, readElimination); + } - public PartialEscapeAnalysisPhase(MetaAccessProvider runtime, Assumptions assumptions, boolean iterative, boolean readElimination) { - this.runtime = runtime; - this.assumptions = assumptions; + public PartialEscapeAnalysisPhase(CustomCanonicalizer customCanonicalizer, boolean iterative, boolean readElimination) { + this.customCanonicalizer = customCanonicalizer; this.iterative = iterative; this.readElimination = readElimination; } - public boolean hasChanged() { - return changed; - } - - public void setCustomCanonicalizer(CustomCanonicalizer customCanonicalizer) { - this.customCanonicalizer = customCanonicalizer; - } - public static final void trace(String format, Object... obj) { if (GraalOptions.TraceEscapeAnalysis) { Debug.log(format, obj); @@ -71,9 +62,13 @@ } @Override - protected void run(final StructuredGraph graph) { + protected void run(StructuredGraph graph, HighTierContext context) { + runAnalysis(graph, context); + } + + public boolean runAnalysis(final StructuredGraph graph, final HighTierContext context) { if (!matches(graph, GraalOptions.EscapeAnalyzeOnly)) { - return; + return false; } if (!readElimination) { @@ -85,26 +80,26 @@ } } if (!analyzableNodes) { - return; + return false; } } - Boolean continueIteration = true; + boolean continueIteration = true; + boolean changed = false; for (int iteration = 0; iteration < GraalOptions.EscapeAnalysisIterations && continueIteration; iteration++) { - continueIteration = Debug.scope("iteration " + iteration, new Callable<Boolean>() { + boolean currentChanged = Debug.scope("iteration " + iteration, new Callable<Boolean>() { @Override public Boolean call() { SchedulePhase schedule = new SchedulePhase(); schedule.apply(graph, false); - PartialEscapeClosure closure = new PartialEscapeClosure(graph.createNodeBitMap(), schedule, runtime, assumptions); + PartialEscapeClosure closure = new PartialEscapeClosure(graph.createNodeBitMap(), schedule, context.getRuntime(), context.getAssumptions()); ReentrantBlockIterator.apply(closure, schedule.getCFG().getStartBlock(), new BlockState(), null); if (!closure.hasChanged()) { return false; } - changed = true; // apply the effects collected during the escape analysis iteration List<Node> obsoleteNodes = closure.applyEffects(graph); @@ -115,13 +110,17 @@ new DeadCodeEliminationPhase().apply(graph); if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase(runtime, assumptions, null, customCanonicalizer).apply(graph); + new CanonicalizerPhase.Instance(context.getRuntime(), context.getAssumptions(), null, customCanonicalizer).apply(graph); } - return iterative; + return true; } }); + continueIteration = currentChanged && iterative; + changed |= currentChanged; } + + return changed; } private static boolean matches(StructuredGraph graph, String filter) {