# HG changeset patch # User Bernhard Urban # Date 1413290555 -7200 # Node ID dab7852da7d70ca3bde251a7bf76aa6eaface456 # Parent df548b06c2591c6950b76624f248e3cbc49c1e81 truffle pe: re-enable SimplePartialEvaluationTest diff -r df548b06c259 -r dab7852da7d7 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 Tue Oct 14 13:35:13 2014 +0200 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/PartialEvaluationTest.java Tue Oct 14 14:42:35 2014 +0200 @@ -22,32 +22,22 @@ */ package com.oracle.graal.truffle.test; -import java.util.*; - import org.junit.*; import com.oracle.graal.api.code.*; import com.oracle.graal.compiler.test.*; import com.oracle.graal.debug.*; import com.oracle.graal.debug.Debug.Scope; -import com.oracle.graal.java.*; -import com.oracle.graal.loop.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.java.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; -import com.oracle.graal.phases.common.inlining.*; import com.oracle.graal.phases.tiers.*; import com.oracle.graal.printer.*; import com.oracle.graal.truffle.*; -import com.oracle.graal.virtual.phases.ea.*; import com.oracle.truffle.api.*; import com.oracle.truffle.api.nodes.*; public class PartialEvaluationTest extends GraalCompilerTest { - - private static final long UNROLL_LIMIT = 100; private final TruffleCompilerImpl truffleCompiler; public PartialEvaluationTest() { @@ -64,11 +54,11 @@ protected InstalledCode assertPartialEvalEquals(String methodName, RootNode root, Object[] arguments) { Assumptions assumptions = new Assumptions(true); - StructuredGraph actual = partialEval(root, arguments, assumptions, true); + StructuredGraph actual = partialEval(root, arguments, assumptions); InstalledCode result = new InstalledCode("Test:" + methodName); truffleCompiler.compileMethodHelper(actual, assumptions, root.toString(), getSpeculationLog(), result); + removeFrameStates(actual); StructuredGraph expected = parseForComparison(methodName); - removeFrameStates(actual); Assert.assertEquals(getCanonicalGraphString(expected, true, true), getCanonicalGraphString(actual, true, true)); return result; } @@ -79,14 +69,14 @@ protected void assertPartialEvalNoInvokes(RootNode root, Object[] arguments) { Assumptions assumptions = new Assumptions(true); - StructuredGraph actual = partialEval(root, arguments, assumptions, true); + StructuredGraph actual = partialEval(root, arguments, assumptions); removeFrameStates(actual); for (MethodCallTargetNode node : actual.getNodes(MethodCallTargetNode.class)) { Assert.fail("Found invalid method call target node: " + node); } } - protected StructuredGraph partialEval(RootNode root, Object[] arguments, final Assumptions assumptions, final boolean canonicalizeReads) { + protected StructuredGraph partialEval(RootNode root, Object[] arguments, final Assumptions assumptions) { final OptimizedCallTarget compilable = (OptimizedCallTarget) Truffle.getRuntime().createCallTarget(root); // Executed AST so that all classes are loaded and initialized. @@ -95,55 +85,12 @@ compilable.call(arguments); try (Scope s = Debug.scope("TruffleCompilation", new TruffleDebugJavaMethod(compilable))) { - - StructuredGraph resultGraph = truffleCompiler.getPartialEvaluator().createGraph(compilable, assumptions); - CanonicalizerPhase canonicalizer = new CanonicalizerPhase(canonicalizeReads); - PhaseContext context = new PhaseContext(getProviders(), assumptions); - - if (resultGraph.hasLoops()) { - boolean unrolled; - do { - unrolled = false; - LoopsData loopsData = new LoopsData(resultGraph); - loopsData.detectedCountedLoops(); - for (LoopEx ex : innerLoopsFirst(loopsData.countedLoops())) { - if (ex.counted().isConstantMaxTripCount()) { - long constant = ex.counted().constantMaxTripCount(); - if (constant <= UNROLL_LIMIT) { - LoopTransformations.fullUnroll(ex, context, canonicalizer); - Debug.dump(resultGraph, "After loop unrolling %d times", constant); - - canonicalizer.apply(resultGraph, context); - unrolled = true; - break; - } - } - } - loopsData.deleteUnusedNodes(); - } while (unrolled); - } - - new DeadCodeEliminationPhase().apply(resultGraph); - new PartialEscapePhase(true, canonicalizer).apply(resultGraph, context); - - return resultGraph; + return truffleCompiler.getPartialEvaluator().createGraph(compilable, assumptions); } catch (Throwable e) { throw Debug.handle(e); } } - private static List innerLoopsFirst(Collection loops) { - ArrayList sortedLoops = new ArrayList<>(loops); - Collections.sort(sortedLoops, new Comparator() { - - @Override - public int compare(LoopEx o1, LoopEx o2) { - return o2.loop().getDepth() - o1.loop().getDepth(); - } - }); - return sortedLoops; - } - protected void removeFrameStates(StructuredGraph graph) { for (FrameState frameState : graph.getNodes(FrameState.class)) { frameState.replaceAtUsages(null); @@ -154,35 +101,9 @@ } protected StructuredGraph parseForComparison(final String methodName) { - try (Scope s = Debug.scope("Truffle", new DebugDumpScope("Comparison: " + methodName))) { - Assumptions assumptions = new Assumptions(false); StructuredGraph graph = parseEager(methodName); - PhaseContext context = new PhaseContext(getProviders(), assumptions); - CanonicalizerPhase canonicalizer = new CanonicalizerPhase(true); - canonicalizer.apply(graph, context); - - // Additional inlining. - PhaseSuite graphBuilderSuite = getCustomGraphBuilderSuite(GraphBuilderConfiguration.getFullDebugDefault()); - graphBuilderSuite.appendPhase(canonicalizer); - graphBuilderSuite.appendPhase(new DeadCodeEliminationPhase()); - - new ConvertDeoptimizeToGuardPhase().apply(graph); - canonicalizer.apply(graph, context); - new DeadCodeEliminationPhase().apply(graph); - - HighTierContext highTierContext = new HighTierContext(getProviders(), assumptions, null, graphBuilderSuite, TruffleCompilerImpl.Optimizations); - InliningPhase inliningPhase = new InliningPhase(canonicalizer); - inliningPhase.apply(graph, highTierContext); - removeFrameStates(graph); - - new ConvertDeoptimizeToGuardPhase().apply(graph); - canonicalizer.apply(graph, context); - new DeadCodeEliminationPhase().apply(graph); - - new LoweringPhase(new CanonicalizerPhase(true), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); - canonicalizer.apply(graph, context); - new DeadCodeEliminationPhase().apply(graph); + compile(graph.method(), graph); return graph; } catch (Throwable e) { throw Debug.handle(e); diff -r df548b06c259 -r dab7852da7d7 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java Tue Oct 14 13:35:13 2014 +0200 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java Tue Oct 14 14:42:35 2014 +0200 @@ -27,7 +27,6 @@ import com.oracle.graal.truffle.test.nodes.*; import com.oracle.truffle.api.frame.*; -@Ignore("Currently ignored due to problems with code coverage tools.") public class SimplePartialEvaluationTest extends PartialEvaluationTest { public static Object constant42() { @@ -97,7 +96,7 @@ public void loop() { FrameDescriptor fd = new FrameDescriptor(); AbstractTestNode result = new BlockTestNode(new AbstractTestNode[]{new StoreLocalTestNode("x", fd, new ConstantTestNode(0)), - new LoopTestNode(21, new StoreLocalTestNode("x", fd, new AddTestNode(new LoadLocalTestNode("x", fd), new ConstantTestNode(2))))}); + new LoopTestNode(7, new StoreLocalTestNode("x", fd, new AddTestNode(new LoadLocalTestNode("x", fd), new ConstantTestNode(6))))}); assertPartialEvalEquals("constant42", new RootTestNode(fd, "loop", result)); } @@ -106,6 +105,8 @@ FrameDescriptor fd = new FrameDescriptor(); AbstractTestNode result = new BlockTestNode(new AbstractTestNode[]{new StoreLocalTestNode("x", fd, new ConstantTestNode(0)), new LoopTestNode(42, new StoreLocalTestNode("x", fd, new AddTestNode(new LoadLocalTestNode("x", fd), new ConstantTestNode(1))))}); - assertPartialEvalNoInvokes(new RootTestNode(fd, "loop", result)); + RootTestNode rootNode = new RootTestNode(fd, "loop", result); + assertPartialEvalNoInvokes(rootNode); + assertPartialEvalEquals("constant42", rootNode); } }