Search in sources :

Example 21 with InliningPhase

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

the class ArraysSubstitutionsTest method testCanonicalLength.

@Test
public void testCanonicalLength() {
    StructuredGraph graph = parseEager("testCanonicalLengthSnippet", AllowAssumptions.NO);
    HighTierContext context = new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL);
    new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    Assert.assertTrue(graph.getNodes(ReturnNode.TYPE).first().result().asJavaConstant().asLong() == 0);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) Test(org.junit.Test)

Example 22 with InliningPhase

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

the class BitOpNodesTest method parseAndInline.

/**
 * Parse and optimize {@code name}. If {@code expectedClass} is non-null and a node of that type
 * isn't found simply return null. Otherwise return the node returned by the graph.
 *
 * @param name
 * @param expectedClass
 * @return the returned value or null if {@code expectedClass} is not found in the graph.
 */
private ValueNode parseAndInline(String name, Class<? extends ValueNode> expectedClass) {
    StructuredGraph graph = parseEager(name, AllowAssumptions.YES);
    HighTierContext context = getDefaultHighTierContext();
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    canonicalizer.apply(graph, context);
    new InliningPhase(canonicalizer).apply(graph, context);
    canonicalizer.apply(graph, context);
    Assert.assertEquals(1, graph.getNodes(ReturnNode.TYPE).count());
    if (expectedClass != null) {
        if (graph.getNodes().filter(expectedClass).count() == 0) {
            return null;
        }
    }
    return graph.getNodes(ReturnNode.TYPE).first().result();
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase)

Example 23 with InliningPhase

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

the class MethodSubstitutionTest method testGraph.

@SuppressWarnings("try")
protected StructuredGraph testGraph(final String snippet, String name) {
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope s = debug.scope("MethodSubstitutionTest", getResolvedJavaMethod(snippet))) {
        StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
        HighTierContext context = getDefaultHighTierContext();
        debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
        new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
        debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
        new CanonicalizerPhase().apply(graph, context);
        new DeadCodeEliminationPhase().apply(graph);
        // Try to ensure any macro nodes are lowered to expose any resulting invokes
        if (graph.getNodes().filter(MacroNode.class).isNotEmpty()) {
            new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
        }
        if (graph.getNodes().filter(MacroNode.class).isNotEmpty()) {
            new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
        }
        assertNotInGraph(graph, MacroNode.class);
        if (name != null) {
            for (Node node : graph.getNodes()) {
                if (node instanceof Invoke) {
                    Invoke invoke = (Invoke) node;
                    if (invoke.callTarget() instanceof MethodCallTargetNode) {
                        MethodCallTargetNode call = (MethodCallTargetNode) invoke.callTarget();
                        assertTrue(!call.targetMethod().getName().equals(name), "Unexpected invoke of intrinsic %s", call.targetMethod());
                    }
                }
            }
        } else {
            assertNotInGraph(graph, Invoke.class);
        }
        return graph;
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : MacroNode(org.graalvm.compiler.replacements.nodes.MacroNode) Node(org.graalvm.compiler.graph.Node) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) Invoke(org.graalvm.compiler.nodes.Invoke) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) MacroNode(org.graalvm.compiler.replacements.nodes.MacroNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) 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 24 with InliningPhase

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

the class PEAReadEliminationTest method processMethod.

protected StructuredGraph processMethod(final String snippet) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
    HighTierContext context = getDefaultHighTierContext();
    new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
    new PartialEscapePhase(false, true, new CanonicalizerPhase(), null, graph.getOptions()).apply(graph, context);
    return graph;
}
Also used : PartialEscapePhase(org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase)

Example 25 with InliningPhase

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

the class PoorMansEATest method test.

@SuppressWarnings("try")
private void test(final String snippet) {
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope s = debug.scope("PoorMansEATest", new DebugDumpScope(snippet))) {
        StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
        HighTierContext highTierContext = getDefaultHighTierContext();
        new InliningPhase(new CanonicalizerPhase()).apply(graph, highTierContext);
        PhaseContext context = new PhaseContext(getProviders());
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
        // remove framestates in order to trigger the simplification.
        cleanup: for (FrameState fs : graph.getNodes(FrameState.TYPE).snapshot()) {
            for (Node input : fs.inputs()) {
                if (input instanceof NewInstanceNode) {
                    fs.replaceAtUsages(null);
                    fs.safeDelete();
                    continue cleanup;
                }
            }
        }
        new CanonicalizerPhase().apply(graph, context);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) Node(org.graalvm.compiler.graph.Node) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) AbstractNewObjectNode(org.graalvm.compiler.nodes.java.AbstractNewObjectNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) FrameState(org.graalvm.compiler.nodes.FrameState) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase)

Aggregations

CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)27 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)27 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)26 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)24 DebugContext (org.graalvm.compiler.debug.DebugContext)9 DeadCodeEliminationPhase (org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)9 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)8 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)7 PartialEscapePhase (org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase)7 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)5 Test (org.junit.Test)5 MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)4 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)4 HashMap (java.util.HashMap)3 Node (org.graalvm.compiler.graph.Node)3 WriteBarrierAdditionPhase (org.graalvm.compiler.hotspot.phases.WriteBarrierAdditionPhase)3 Invoke (org.graalvm.compiler.nodes.Invoke)3 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)3 G1PostWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier)2 G1PreWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier)2