Search in sources :

Example 21 with PhaseContext

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

the class PEGraphDecoderTest method test.

@Test
@SuppressWarnings("try")
public void test() {
    ResolvedJavaMethod testMethod = getResolvedJavaMethod(PEGraphDecoderTest.class, "doTest", Object.class);
    StructuredGraph targetGraph = null;
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope scope = debug.scope("GraphPETest", testMethod)) {
        GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true).withUnresolvedIsError(true);
        registerPlugins(graphBuilderConfig.getPlugins().getInvocationPlugins());
        targetGraph = new StructuredGraph.Builder(getInitialOptions(), debug, AllowAssumptions.YES).method(testMethod).build();
        CachingPEGraphDecoder decoder = new CachingPEGraphDecoder(getTarget().arch, targetGraph, getProviders(), graphBuilderConfig, OptimisticOptimizations.NONE, AllowAssumptions.YES, null, null, new InlineInvokePlugin[] { new InlineAll() }, null, null, null, null);
        decoder.decode(testMethod, false);
        debug.dump(DebugContext.BASIC_LEVEL, targetGraph, "Target Graph");
        targetGraph.verify();
        PhaseContext context = new PhaseContext(getProviders());
        new CanonicalizerPhase().apply(targetGraph, context);
        targetGraph.verify();
    } catch (Throwable ex) {
        if (targetGraph != null) {
            debug.dump(DebugContext.BASIC_LEVEL, targetGraph, ex.toString());
        }
        debug.handle(ex);
    }
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) CachingPEGraphDecoder(org.graalvm.compiler.replacements.CachingPEGraphDecoder) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) Test(org.junit.Test)

Example 22 with PhaseContext

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

the class HotSpotInvokeDynamicPluginTest method test.

private void test(String name, int expectedResolves, int expectedStubCalls) {
    StructuredGraph graph = parseEager(name, AllowAssumptions.NO, new OptionValues(getInitialOptions(), GraalOptions.GeneratePIC, true));
    MidTierContext midTierContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    Assert.assertEquals(expectedResolves, graph.getNodes().filter(ResolveDynamicConstantNode.class).count());
    Assert.assertEquals(0, graph.getNodes().filter(ResolveDynamicStubCall.class).count());
    PhaseContext context = new PhaseContext(getProviders());
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    new GuardLoweringPhase().apply(graph, midTierContext);
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
    new FrameStateAssignmentPhase().apply(graph);
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.LOW_TIER).apply(graph, context);
    Assert.assertEquals(0, graph.getNodes().filter(ResolveDynamicConstantNode.class).count());
    Assert.assertEquals(expectedStubCalls, graph.getNodes().filter(ResolveDynamicStubCall.class).count());
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) FrameStateAssignmentPhase(org.graalvm.compiler.phases.common.FrameStateAssignmentPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) OptionValues(org.graalvm.compiler.options.OptionValues) 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)

Example 23 with PhaseContext

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

the class ArraysSubstitutionsTest method testCanonicalEqual.

@Test
public void testCanonicalEqual() {
    StructuredGraph graph = parseEager("testCanonicalEqualSnippet", 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() == 1);
}
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 24 with PhaseContext

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

the class GraphEncoderTest method testStringMethods.

public void testStringMethods(boolean canonicalize) {
    /* Encode and decode all methods of java.lang.String. */
    List<StructuredGraph> originalGraphs = new ArrayList<>();
    for (Method method : String.class.getDeclaredMethods()) {
        ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(method);
        if (javaMethod.hasBytecodes()) {
            StructuredGraph originalGraph = parseEager(javaMethod, AllowAssumptions.YES);
            if (canonicalize) {
                PhaseContext context = new PhaseContext(getProviders());
                new CanonicalizerPhase().apply(originalGraph, context);
            }
            originalGraphs.add(originalGraph);
        }
    }
    GraphEncoder encoder = new GraphEncoder(getTarget().arch);
    for (StructuredGraph originalGraph : originalGraphs) {
        encoder.prepare(originalGraph);
    }
    encoder.finishPrepare();
    Map<StructuredGraph, Integer> startOffsets = new HashMap<>();
    for (StructuredGraph originalGraph : originalGraphs) {
        startOffsets.put(originalGraph, encoder.encode(originalGraph));
    }
    for (StructuredGraph originalGraph : originalGraphs) {
        EncodedGraph encodedGraph = new EncodedGraph(encoder.getEncoding(), startOffsets.get(originalGraph), encoder.getObjects(), encoder.getNodeClasses(), originalGraph);
        GraphEncoder.verifyEncoding(originalGraph, encodedGraph, getTarget().arch);
    }
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HashMap(java.util.HashMap) EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph) ArrayList(java.util.ArrayList) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) GraphEncoder(org.graalvm.compiler.nodes.GraphEncoder) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 25 with PhaseContext

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

the class CompareCanonicalizerTest method testCanonicalComparison.

@Test
public void testCanonicalComparison() {
    StructuredGraph referenceGraph = parseEager("referenceCanonicalComparison", AllowAssumptions.NO);
    for (int i = 1; i < 4; i++) {
        StructuredGraph graph = parseEager("canonicalCompare" + i, AllowAssumptions.NO);
        assertEquals(referenceGraph, graph);
    }
    new CanonicalizerPhase().apply(referenceGraph, new PhaseContext(getProviders()));
    for (int i = 1; i < 4; i++) {
        StructuredGraph graph = getCanonicalizedGraph("canonicalCompare" + i);
        assertEquals(referenceGraph, graph);
    }
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) Test(org.junit.Test)

Aggregations

PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)60 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)59 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)56 DebugContext (org.graalvm.compiler.debug.DebugContext)24 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)19 Test (org.junit.Test)18 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)8 ConditionalEliminationPhase (org.graalvm.compiler.phases.common.ConditionalEliminationPhase)7 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)7 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)6 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)6 FrameState (org.graalvm.compiler.nodes.FrameState)6 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)6 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)5 Node (org.graalvm.compiler.graph.Node)5 OptionValues (org.graalvm.compiler.options.OptionValues)5 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)5 IterativeConditionalEliminationPhase (org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase)4 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)4 PartialEscapePhase (org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase)4