Search in sources :

Example 46 with PhaseContext

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

the class ReassociateAndCanonicalTest method test.

private <T extends Node & IterableNodeType> void test(String test, String ref) {
    StructuredGraph testGraph = parseEager(test, AllowAssumptions.NO);
    new CanonicalizerPhase().apply(testGraph, new PhaseContext(getProviders()));
    StructuredGraph refGraph = parseEager(ref, AllowAssumptions.NO);
    new CanonicalizerPhase().apply(refGraph, new PhaseContext(getProviders()));
    assertEquals(testGraph, refGraph);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 47 with PhaseContext

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

the class IfCanonicalizerTest method test.

private void test(String snippet) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    DebugContext debug = graph.getDebug();
    ParameterNode param = graph.getNodes(ParameterNode.TYPE).iterator().next();
    ConstantNode constant = ConstantNode.forInt(0, graph);
    for (Node n : param.usages().snapshot()) {
        if (!(n instanceof FrameState)) {
            n.replaceFirstInput(param, constant);
        }
    }
    debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    for (FrameState fs : param.usages().filter(FrameState.class).snapshot()) {
        fs.replaceFirstInput(param, null);
        param.safeDelete();
    }
    StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES);
    assertEquals(referenceGraph, graph);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IfNode(org.graalvm.compiler.nodes.IfNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Node(org.graalvm.compiler.graph.Node) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) FrameState(org.graalvm.compiler.nodes.FrameState)

Example 48 with PhaseContext

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

the class IntegerEqualsCanonicalizerTest method getCanonicalizedGraph.

private StructuredGraph getCanonicalizedGraph(String snippet) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    for (FrameState state : graph.getNodes(FrameState.TYPE).snapshot()) {
        state.replaceAtUsages(null);
        state.safeDelete();
    }
    return graph;
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) FrameState(org.graalvm.compiler.nodes.FrameState)

Example 49 with PhaseContext

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

the class ConditionalEliminationTestBase method testProxies.

public void testProxies(String snippet, int expectedProxiesCreated) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    PhaseContext context = new PhaseContext(getProviders());
    CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase();
    canonicalizer1.disableSimplification();
    canonicalizer1.apply(graph, context);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    canonicalizer.apply(graph, context);
    int baseProxyCount = graph.getNodes().filter(ProxyNode.class).count();
    new ConditionalEliminationPhase(true).apply(graph, context);
    canonicalizer.apply(graph, context);
    new SchedulePhase(graph.getOptions()).apply(graph, context);
    int actualProxiesCreated = graph.getNodes().filter(ProxyNode.class).count() - baseProxyCount;
    Assert.assertEquals(expectedProxiesCreated, actualProxiesCreated);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 50 with PhaseContext

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

the class ConditionalEliminationTestBase method testConditionalElimination.

@SuppressWarnings("try")
protected void testConditionalElimination(String snippet, String referenceSnippet, boolean applyConditionalEliminationOnReference, boolean applyLowering) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    DebugContext debug = graph.getDebug();
    debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    PhaseContext context = new PhaseContext(getProviders());
    CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase();
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    try (DebugContext.Scope scope = debug.scope("ConditionalEliminationTest", graph)) {
        prepareGraph(graph, canonicalizer1, context, applyLowering);
        new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
        canonicalizer.apply(graph, context);
        canonicalizer.apply(graph, context);
    } catch (Throwable t) {
        debug.handle(t);
    }
    StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.YES);
    try (DebugContext.Scope scope = debug.scope("ConditionalEliminationTest.ReferenceGraph", referenceGraph)) {
        prepareGraph(referenceGraph, canonicalizer, context, applyLowering);
        if (applyConditionalEliminationOnReference) {
            new ConditionalEliminationPhase(true).apply(referenceGraph, context);
        }
        canonicalizer.apply(referenceGraph, context);
        canonicalizer.apply(referenceGraph, context);
    } catch (Throwable t) {
        debug.handle(t);
    }
    assertEquals(referenceGraph, graph);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) IterativeConditionalEliminationPhase(org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext)

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