Search in sources :

Example 16 with LoweringPhase

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

the class ConditionalEliminationTest14 method test1.

@Test
public void test1() {
    StructuredGraph graph = parseEager("test1Snippet", AllowAssumptions.YES);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    PhaseContext context = new PhaseContext(getProviders());
    /* Convert the LoadIndexNode to ReadNode with floating guards. */
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    /* Convert the ReadNode to FloatingReadNode. */
    new FloatingReadPhase().apply(graph);
    /* Apply the phase that we want to test. */
    new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
    Assert.assertEquals("All guards must be floating", 0, graph.getNodes(FixedGuardNode.TYPE).count());
    Assert.assertEquals("All array accesses must have been lowered", 0, graph.getNodes().filter(LoadIndexedNode.class).count());
    Assert.assertEquals("All reads must be floating", 0, graph.getNodes().filter(ReadNode.class).count());
    Assert.assertEquals("Must have floating reads (3 array accesses, 1 array length)", 4, graph.getNodes().filter(FloatingReadNode.class).count());
    NodeIterable<GuardNode> boundsChecks = graph.getNodes(GuardNode.TYPE).filter(n -> ((GuardNode) n).getReason() == DeoptimizationReason.BoundsCheckException);
    Assert.assertEquals("Must have only 1 bounds check remaining", 1, boundsChecks.count());
    LogicNode condition = boundsChecks.first().getCondition();
    Assert.assertTrue("Bounds check must check for array length 8", condition instanceof IntegerBelowNode && ((IntegerBelowNode) condition).getY().valueEquals(ConstantNode.forInt(8)));
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) GuardNode(org.graalvm.compiler.nodes.GuardNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) LogicNode(org.graalvm.compiler.nodes.LogicNode) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) Test(org.junit.Test)

Example 17 with LoweringPhase

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

the class ConditionalEliminationTest2 method testRedundantCompares.

@Test
public void testRedundantCompares() {
    StructuredGraph graph = parseEager("testRedundantComparesSnippet", AllowAssumptions.YES);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    PhaseContext context = new PhaseContext(getProviders());
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    canonicalizer.apply(graph, context);
    new FloatingReadPhase().apply(graph);
    new ConditionalEliminationPhase(true).apply(graph, context);
    canonicalizer.apply(graph, context);
    assertDeepEquals(1, graph.getNodes().filter(GuardNode.class).count());
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) Test(org.junit.Test)

Example 18 with LoweringPhase

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

the class MacroNode method lowerReplacement.

/**
 * Applies {@linkplain LoweringPhase lowering} to a replacement graph.
 *
 * @param replacementGraph a replacement (i.e., snippet or method substitution) graph
 */
@SuppressWarnings("try")
protected StructuredGraph lowerReplacement(final StructuredGraph replacementGraph, LoweringTool tool) {
    final PhaseContext c = new PhaseContext(tool.getMetaAccess(), tool.getConstantReflection(), tool.getConstantFieldProvider(), tool.getLowerer(), tool.getReplacements(), tool.getStampProvider());
    if (!graph().hasValueProxies()) {
        new RemoveValueProxyPhase().apply(replacementGraph);
    }
    GuardsStage guardsStage = graph().getGuardsStage();
    if (!guardsStage.allowsFloatingGuards()) {
        new GuardLoweringPhase().apply(replacementGraph, null);
        if (guardsStage.areFrameStatesAtDeopts()) {
            new FrameStateAssignmentPhase().apply(replacementGraph);
        }
    }
    DebugContext debug = replacementGraph.getDebug();
    try (DebugContext.Scope s = debug.scope("LoweringSnippetTemplate", replacementGraph)) {
        new LoweringPhase(new CanonicalizerPhase(), tool.getLoweringStage()).apply(replacementGraph, c);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    return replacementGraph;
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) FrameStateAssignmentPhase(org.graalvm.compiler.phases.common.FrameStateAssignmentPhase) RemoveValueProxyPhase(org.graalvm.compiler.phases.common.RemoveValueProxyPhase) GuardsStage(org.graalvm.compiler.nodes.StructuredGraph.GuardsStage) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase)

Example 19 with LoweringPhase

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

the class ConditionalEliminationTest10 method test.

private void test(String snippet, int guardCount) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    PhaseContext context = new PhaseContext(getProviders());
    new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    new ConditionalEliminationPhase(true).apply(graph, context);
    Assert.assertEquals(guardCount, graph.getNodes().filter(GuardNode.class).count());
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 20 with LoweringPhase

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

the class ConditionalEliminationTest2 method testInstanceOfCheckCastLowered.

@Test
public void testInstanceOfCheckCastLowered() {
    StructuredGraph graph = parseEager("testInstanceOfCheckCastSnippet", AllowAssumptions.YES);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    PhaseContext context = new PhaseContext(getProviders());
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    canonicalizer.apply(graph, context);
    new ConditionalEliminationPhase(true).apply(graph, context);
    canonicalizer.apply(graph, context);
    assertDeepEquals(0, graph.getNodes().filter(GuardNode.class).count());
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) Test(org.junit.Test)

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