Search in sources :

Example 61 with HighTierContext

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

the class ArraysSubstitutionsTest method testVirtualNotEqual.

@Test
public void testVirtualNotEqual() {
    StructuredGraph graph = parseEager("testVirtualNotEqualSnippet", AllowAssumptions.NO);
    HighTierContext context = getDefaultHighTierContext();
    new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    new PartialEscapePhase(false, new CanonicalizerPhase(), graph.getOptions()).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) 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) Test(org.junit.Test)

Example 62 with HighTierContext

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

the class ArraysSubstitutionsTest method testVirtualEqual.

@Test
public void testVirtualEqual() {
    StructuredGraph graph = parseEager("testVirtualEqualSnippet", AllowAssumptions.NO);
    HighTierContext context = new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL);
    new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    new PartialEscapePhase(false, new CanonicalizerPhase(), graph.getOptions()).apply(graph, context);
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    Assert.assertTrue(graph.getNodes(ReturnNode.TYPE).first().result().asJavaConstant().asLong() == 1);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) 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) Test(org.junit.Test)

Example 63 with HighTierContext

use of org.graalvm.compiler.phases.tiers.HighTierContext 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 64 with HighTierContext

use of org.graalvm.compiler.phases.tiers.HighTierContext 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 65 with HighTierContext

use of org.graalvm.compiler.phases.tiers.HighTierContext 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)

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