Search in sources :

Example 16 with HighTierContext

use of org.graalvm.compiler.phases.tiers.HighTierContext in project graal by oracle.

the class MarkUnsafeAccessTest method testCompiled.

@Test
public void testCompiled() throws IOException {
    ResolvedJavaMethod getMethod = asResolvedJavaMethod(getMethod(ByteBuffer.class, "get", new Class<?>[] {}));
    ResolvedJavaType mbbClass = getMetaAccess().lookupJavaType(MappedByteBuffer.class);
    ResolvedJavaMethod getMethodImpl = mbbClass.findUniqueConcreteMethod(getMethod).getResult();
    Assert.assertNotNull(getMethodImpl);
    StructuredGraph graph = parseForCompile(getMethodImpl);
    HighTierContext highContext = getDefaultHighTierContext();
    new CanonicalizerPhase().apply(graph, highContext);
    new InliningPhase(new InlineEverythingPolicy(), new CanonicalizerPhase()).apply(graph, highContext);
    InstalledCode compiledCode = getCode(getMethodImpl, graph);
    testMappedByteBuffer(mbb -> {
        try {
            return (byte) compiledCode.executeVarargs(mbb);
        } catch (InvalidInstalledCodeException e) {
            Assert.fail();
            return 0;
        }
    });
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InlineEverythingPolicy(org.graalvm.compiler.phases.common.inlining.policy.InlineEverythingPolicy) InvalidInstalledCodeException(jdk.vm.ci.code.InvalidInstalledCodeException) InstalledCode(jdk.vm.ci.code.InstalledCode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) ByteBuffer(java.nio.ByteBuffer) MappedByteBuffer(java.nio.MappedByteBuffer) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) Test(org.junit.Test)

Example 17 with HighTierContext

use of org.graalvm.compiler.phases.tiers.HighTierContext in project graal by oracle.

the class MonitorGraphTest method parseAndProcess.

private StructuredGraph parseAndProcess(String snippet) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
    ParameterNode param = graph.getNodes(ParameterNode.TYPE).first();
    if (param != null) {
        ConstantNode constant = ConstantNode.forInt(0, graph);
        for (Node n : param.usages().snapshot()) {
            if (!(n instanceof FrameState)) {
                n.replaceFirstInput(param, constant);
            }
        }
    }
    Map<Invoke, Double> hints = new HashMap<>();
    for (Invoke invoke : graph.getInvokes()) {
        hints.put(invoke, 1000d);
    }
    HighTierContext context = getDefaultHighTierContext();
    new InliningPhase(hints, new CanonicalizerPhase()).apply(graph, context);
    new CanonicalizerPhase().apply(graph, context);
    new DeadCodeEliminationPhase().apply(graph);
    return graph;
}
Also used : HashMap(java.util.HashMap) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) Node(org.graalvm.compiler.graph.Node) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) FrameState(org.graalvm.compiler.nodes.FrameState) Invoke(org.graalvm.compiler.nodes.Invoke) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)

Example 18 with HighTierContext

use of org.graalvm.compiler.phases.tiers.HighTierContext in project graal by oracle.

the class NodePropertiesTest method testArrayLoad.

@Test
public void testArrayLoad() {
    StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("arrayLoadTest"));
    HighTierContext htc = getDefaultHighTierContext();
    new CanonicalizerPhase().apply(g1, htc);
    GraphCostPhase gc1 = new GraphCostPhase();
    gc1.apply(g1, htc);
    Assert.assertEquals(15, gc1.finalCycles, 25);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) Test(org.junit.Test)

Example 19 with HighTierContext

use of org.graalvm.compiler.phases.tiers.HighTierContext in project graal by oracle.

the class NodePropertiesTest method testSameLoopMoreIterationsCostlier.

@Test
public void testSameLoopMoreIterationsCostlier() {
    HighTierContext htc = getDefaultHighTierContext();
    StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("testLoop01"));
    StructuredGraph g2 = parseForCompile(getResolvedJavaMethod("testLoop02"));
    prepareGraphForLoopFrequencies(g1, htc);
    prepareGraphForLoopFrequencies(g2, htc);
    assertFrequency(g1, ITERATIONS_LOOP_1);
    assertFrequency(g2, ITERATIONS_LOOP_2);
    GraphCostPhase gc1 = new GraphCostPhase();
    GraphCostPhase gc2 = new GraphCostPhase();
    gc1.apply(g1, htc);
    gc2.apply(g2, htc);
    g1.getDebug().log("Test testSameLoopMoreIterationsCostlier --> 1.Graph cycles:%f size:%f vs. 2.Graph cycles:%f size:%f\n", gc1.finalCycles, gc1.finalSize, gc2.finalCycles, gc2.finalSize);
    Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
    Assert.assertTrue(gc2.finalSize == gc1.finalSize);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) Test(org.junit.Test)

Example 20 with HighTierContext

use of org.graalvm.compiler.phases.tiers.HighTierContext in project graal by oracle.

the class NodePropertiesTest method testGraphCost.

@Test
public void testGraphCost() {
    StructuredGraph g1 = parseForCompile(getResolvedJavaMethod("test1Snippet"));
    StructuredGraph g2 = parseForCompile(getResolvedJavaMethod("test2Snippet"));
    HighTierContext htc = getDefaultHighTierContext();
    new CanonicalizerPhase().apply(g1, htc);
    new CanonicalizerPhase().apply(g2, htc);
    GraphCostPhase gc1 = new GraphCostPhase();
    GraphCostPhase gc2 = new GraphCostPhase();
    gc1.apply(g1, htc);
    gc2.apply(g2, htc);
    g1.getDebug().log("Test Graph Cost --> 1.Graph cost:%f vs. 2.Graph cost:%f\n", gc1.finalCycles, gc2.finalCycles);
    Assert.assertTrue(gc2.finalCycles > gc1.finalCycles);
    Assert.assertTrue(gc2.finalSize == gc1.finalSize);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) Test(org.junit.Test)

Aggregations

HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)71 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)60 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)46 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)27 DebugContext (org.graalvm.compiler.debug.DebugContext)18 Test (org.junit.Test)18 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)15 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)13 OptionValues (org.graalvm.compiler.options.OptionValues)13 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)11 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)10 DeadCodeEliminationPhase (org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)10 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)8 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)8 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)8 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)7 PartialEscapePhase (org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase)7 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)6 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)6 PhaseSuite (org.graalvm.compiler.phases.PhaseSuite)6