Search in sources :

Example 91 with CanonicalizerPhase

use of org.graalvm.compiler.phases.common.CanonicalizerPhase in project graal by oracle.

the class InvokeHintsTest method test.

private void test(String snippet) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
    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);
    StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.NO);
    assertEquals(referenceGraph, graph);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HashMap(java.util.HashMap) 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) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 92 with CanonicalizerPhase

use of org.graalvm.compiler.phases.common.CanonicalizerPhase in project graal by oracle.

the class ConditionalEliminationTestBase method testProxies.

public void testProxies(String snippet, int expectedProxiesCreated) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    PhaseContext context = new PhaseContext(getProviders());
    CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase();
    canonicalizer1.disableSimplification();
    canonicalizer1.apply(graph, context);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    canonicalizer.apply(graph, context);
    int baseProxyCount = graph.getNodes().filter(ProxyNode.class).count();
    new ConditionalEliminationPhase(true).apply(graph, context);
    canonicalizer.apply(graph, context);
    new SchedulePhase(graph.getOptions()).apply(graph, context);
    int actualProxiesCreated = graph.getNodes().filter(ProxyNode.class).count() - baseProxyCount;
    Assert.assertEquals(expectedProxiesCreated, actualProxiesCreated);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 93 with CanonicalizerPhase

use of org.graalvm.compiler.phases.common.CanonicalizerPhase in project graal by oracle.

the class ConditionalEliminationTestBase method testConditionalElimination.

@SuppressWarnings("try")
protected void testConditionalElimination(String snippet, String referenceSnippet, boolean applyConditionalEliminationOnReference, boolean applyLowering) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    DebugContext debug = graph.getDebug();
    debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    PhaseContext context = new PhaseContext(getProviders());
    CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase();
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    try (DebugContext.Scope scope = debug.scope("ConditionalEliminationTest", graph)) {
        prepareGraph(graph, canonicalizer1, context, applyLowering);
        new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
        canonicalizer.apply(graph, context);
        canonicalizer.apply(graph, context);
    } catch (Throwable t) {
        debug.handle(t);
    }
    StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.YES);
    try (DebugContext.Scope scope = debug.scope("ConditionalEliminationTest.ReferenceGraph", referenceGraph)) {
        prepareGraph(referenceGraph, canonicalizer, context, applyLowering);
        if (applyConditionalEliminationOnReference) {
            new ConditionalEliminationPhase(true).apply(referenceGraph, context);
        }
        canonicalizer.apply(referenceGraph, context);
        canonicalizer.apply(referenceGraph, context);
    } catch (Throwable t) {
        debug.handle(t);
    }
    assertEquals(referenceGraph, graph);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 94 with CanonicalizerPhase

use of org.graalvm.compiler.phases.common.CanonicalizerPhase in project graal by oracle.

the class LockEliminationTest method testLock.

@Test
public void testLock() {
    test("testSynchronizedSnippet", new A(), new A());
    StructuredGraph graph = getGraph("testSynchronizedSnippet");
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    new LockEliminationPhase().apply(graph);
    assertDeepEquals(1, graph.getNodes().filter(RawMonitorEnterNode.class).count());
    assertDeepEquals(1, graph.getNodes().filter(MonitorExitNode.class).count());
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) LockEliminationPhase(org.graalvm.compiler.phases.common.LockEliminationPhase) Test(org.junit.Test)

Example 95 with CanonicalizerPhase

use of org.graalvm.compiler.phases.common.CanonicalizerPhase in project graal by oracle.

the class LockEliminationTest method testSynchronizedMethod.

@Test
public void testSynchronizedMethod() {
    test("testSynchronizedMethodSnippet", new A());
    StructuredGraph graph = getGraph("testSynchronizedMethodSnippet");
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    new LockEliminationPhase().apply(graph);
    assertDeepEquals(1, graph.getNodes().filter(RawMonitorEnterNode.class).count());
    assertDeepEquals(1, graph.getNodes().filter(MonitorExitNode.class).count());
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) LockEliminationPhase(org.graalvm.compiler.phases.common.LockEliminationPhase) Test(org.junit.Test)

Aggregations

CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)114 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)98 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)60 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)48 DebugContext (org.graalvm.compiler.debug.DebugContext)34 Test (org.junit.Test)33 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)31 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)27 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)17 DeadCodeEliminationPhase (org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)16 PartialEscapePhase (org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase)14 Node (org.graalvm.compiler.graph.Node)12 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)12 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)10 OptionValues (org.graalvm.compiler.options.OptionValues)10 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)10 ConditionalEliminationPhase (org.graalvm.compiler.phases.common.ConditionalEliminationPhase)9 MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)9 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)8 Invoke (org.graalvm.compiler.nodes.Invoke)8