Search in sources :

Example 1 with LoweringPhase

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

the class ConditionAnchoringTest method test.

public void test(String name, int ids) {
    StructuredGraph graph = parseEager(name, AllowAssumptions.YES);
    NodeIterable<RawLoadNode> unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
    assertThat(unsafeNodes, hasCount(1));
    // lower unsafe load
    PhaseContext context = new PhaseContext(getProviders());
    LoweringPhase lowering = new LoweringPhase(new CanonicalizerPhase(), StandardLoweringStage.HIGH_TIER);
    lowering.apply(graph, context);
    unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
    NodeIterable<ConditionAnchorNode> conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
    NodeIterable<ReadNode> reads = graph.getNodes().filter(ReadNode.class);
    assertThat(unsafeNodes, isEmpty());
    assertThat(conditionAnchors, hasCount(1));
    // 2 * ids id reads, 1 'field' access
    assertThat(reads, hasCount(2 * ids + 1));
    // float reads and canonicalize to give a chance to conditions to GVN
    FloatingReadPhase floatingReadPhase = new FloatingReadPhase();
    floatingReadPhase.apply(graph);
    CanonicalizerPhase canonicalizerPhase = new CanonicalizerPhase();
    canonicalizerPhase.apply(graph, context);
    NodeIterable<FloatingReadNode> floatingReads = graph.getNodes().filter(FloatingReadNode.class);
    // 1 id read, 1 'field' access
    assertThat(floatingReads, hasCount(ids + 1));
    new ConditionalEliminationPhase(false).apply(graph, context);
    floatingReads = graph.getNodes().filter(FloatingReadNode.class).filter(n -> ((FloatingReadNode) n).getLocationIdentity() instanceof ObjectLocationIdentity);
    conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
    assertThat(floatingReads, hasCount(1));
    assertThat(conditionAnchors, isEmpty());
    FloatingReadNode readNode = floatingReads.first();
    assertThat(readNode.getGuard(), instanceOf(BeginNode.class));
    assertThat(readNode.getGuard().asNode().predecessor(), instanceOf(IfNode.class));
}
Also used : RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) Unsafe(sun.misc.Unsafe) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) TruffleGraphBuilderPlugins(org.graalvm.compiler.truffle.compiler.substitutions.TruffleGraphBuilderPlugins) ConditionAnchorNode(org.graalvm.compiler.nodes.ConditionAnchorNode) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) NodeIterableIsEmpty.isEmpty(org.graalvm.compiler.graph.test.matchers.NodeIterableIsEmpty.isEmpty) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) Assert.assertThat(org.junit.Assert.assertThat) InlineInfo.createStandardInlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo) JavaKind(jdk.vm.ci.meta.JavaKind) ObjectLocationIdentity(org.graalvm.compiler.truffle.compiler.nodes.ObjectLocationIdentity) BeginNode(org.graalvm.compiler.nodes.BeginNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) IfNode(org.graalvm.compiler.nodes.IfNode) Test(org.junit.Test) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) NodeIterable(org.graalvm.compiler.graph.iterators.NodeIterable) NodeIterableCount.hasCount(org.graalvm.compiler.graph.test.matchers.NodeIterableCount.hasCount) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) StandardLoweringStage(org.graalvm.compiler.nodes.spi.LoweringTool.StandardLoweringStage) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ConditionAnchorNode(org.graalvm.compiler.nodes.ConditionAnchorNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ObjectLocationIdentity(org.graalvm.compiler.truffle.compiler.nodes.ObjectLocationIdentity) IfNode(org.graalvm.compiler.nodes.IfNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) BeginNode(org.graalvm.compiler.nodes.BeginNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode)

Example 2 with LoweringPhase

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

the class EarlyReadEliminationTest method processMethod.

protected StructuredGraph processMethod(String snippet, boolean doLowering) {
    StructuredGraph graph = parseEager(getResolvedJavaMethod(snippet), AllowAssumptions.NO);
    HighTierContext context = getDefaultHighTierContext();
    new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
    if (doLowering) {
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    }
    new EarlyReadEliminationPhase(new CanonicalizerPhase()).apply(graph, context);
    return graph;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) EarlyReadEliminationPhase(org.graalvm.compiler.virtual.phases.ea.EarlyReadEliminationPhase)

Example 3 with LoweringPhase

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

the class UnsafeReadEliminationTest method testPartialEscapeReadElimination.

public void testPartialEscapeReadElimination(StructuredGraph graph, int reads, int writes) {
    OptionValues options = graph.getOptions();
    PhaseContext context = getDefaultHighTierContext();
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    canonicalizer.apply(graph, context);
    new PartialEscapePhase(true, true, canonicalizer, null, options).apply(graph, context);
    Assert.assertEquals(3, graph.getNodes().filter(UnsafeAccessNode.class).count());
    // after lowering the same applies for reads and writes
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    canonicalizer.apply(graph, context);
    new PartialEscapePhase(true, true, canonicalizer, null, options).apply(graph, context);
    Assert.assertEquals(reads, graph.getNodes().filter(ReadNode.class).count());
    Assert.assertEquals(writes, graph.getNodes().filter(WriteNode.class).count());
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) PartialEscapePhase(org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase) OptionValues(org.graalvm.compiler.options.OptionValues) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 4 with LoweringPhase

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

the class LockEliminationTest method getGraph.

private StructuredGraph getGraph(String snippet) {
    ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
    StructuredGraph graph = parseEager(method, AllowAssumptions.YES);
    HighTierContext context = getDefaultHighTierContext();
    new CanonicalizerPhase().apply(graph, context);
    new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
    new CanonicalizerPhase().apply(graph, context);
    new DeadCodeEliminationPhase().apply(graph);
    new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    new LockEliminationPhase().apply(graph);
    return graph;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) LockEliminationPhase(org.graalvm.compiler.phases.common.LockEliminationPhase) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 5 with LoweringPhase

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

the class IfCanonicalizerTest method testCombinedIf.

private void testCombinedIf(String snippet, int count) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    PhaseContext context = new PhaseContext(getProviders());
    new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    new FloatingReadPhase().apply(graph);
    MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
    new GuardLoweringPhase().apply(graph, midContext);
    new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, midContext);
    new CanonicalizerPhase().apply(graph, context);
    assertDeepEquals(count, graph.getNodes().filter(IfNode.class).count());
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase)

Aggregations

LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)31 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)30 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)27 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)19 DebugContext (org.graalvm.compiler.debug.DebugContext)13 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)12 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)12 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)10 MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)8 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)7 ConditionalEliminationPhase (org.graalvm.compiler.phases.common.ConditionalEliminationPhase)6 Test (org.junit.Test)6 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)5 Node (org.graalvm.compiler.graph.Node)5 OptionValues (org.graalvm.compiler.options.OptionValues)5 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 FrameStateAssignmentPhase (org.graalvm.compiler.phases.common.FrameStateAssignmentPhase)4 List (java.util.List)3 FloatingReadNode (org.graalvm.compiler.nodes.memory.FloatingReadNode)3 ReadNode (org.graalvm.compiler.nodes.memory.ReadNode)3