Search in sources :

Example 26 with LoweringPhase

use of org.graalvm.compiler.phases.common.LoweringPhase 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 27 with LoweringPhase

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

the class LoopPartialUnrollTest method buildGraph.

@SuppressWarnings("try")
public StructuredGraph buildGraph(String name, boolean partialUnroll) {
    CompilationIdentifier id = new CompilationIdentifier() {

        @Override
        public String toString(Verbosity verbosity) {
            return name;
        }
    };
    ResolvedJavaMethod method = getResolvedJavaMethod(name);
    OptionValues options = new OptionValues(getInitialOptions(), DefaultLoopPolicies.Options.UnrollMaxIterations, 2);
    StructuredGraph graph = parse(builder(method, StructuredGraph.AllowAssumptions.YES, id, options), getEagerGraphBuilderSuite());
    try (DebugContext.Scope buildScope = graph.getDebug().scope(name, method, graph)) {
        MidTierContext context = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, null);
        CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
        canonicalizer.apply(graph, context);
        new RemoveValueProxyPhase().apply(graph);
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
        new FloatingReadPhase().apply(graph);
        new DeadCodeEliminationPhase().apply(graph);
        new ConditionalEliminationPhase(true).apply(graph, context);
        ComputeLoopFrequenciesClosure.compute(graph);
        new GuardLoweringPhase().apply(graph, context);
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
        new FrameStateAssignmentPhase().apply(graph);
        new DeoptimizationGroupingPhase().apply(graph, context);
        canonicalizer.apply(graph, context);
        new ConditionalEliminationPhase(true).apply(graph, context);
        if (partialUnroll) {
            LoopsData dataCounted = new LoopsData(graph);
            dataCounted.detectedCountedLoops();
            for (LoopEx loop : dataCounted.countedLoops()) {
                LoopFragmentInside newSegment = loop.inside().duplicate();
                newSegment.insertWithinAfter(loop, false);
            }
            canonicalizer.apply(graph, getDefaultMidTierContext());
        }
        new DeadCodeEliminationPhase().apply(graph);
        canonicalizer.apply(graph, context);
        graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "before compare");
        return graph;
    } catch (Throwable e) {
        throw getDebugContext().handle(e);
    }
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) FrameStateAssignmentPhase(org.graalvm.compiler.phases.common.FrameStateAssignmentPhase) LoopsData(org.graalvm.compiler.loop.LoopsData) OptionValues(org.graalvm.compiler.options.OptionValues) LoopFragmentInside(org.graalvm.compiler.loop.LoopFragmentInside) RemoveValueProxyPhase(org.graalvm.compiler.phases.common.RemoveValueProxyPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LoopEx(org.graalvm.compiler.loop.LoopEx) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DeoptimizationGroupingPhase(org.graalvm.compiler.phases.common.DeoptimizationGroupingPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 28 with LoweringPhase

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

the class ReplacementsParseTest method testGraph.

@SuppressWarnings("try")
private void testGraph(String name) {
    StructuredGraph graph = parseEager(name, StructuredGraph.AllowAssumptions.YES);
    try (DebugContext.Scope s0 = graph.getDebug().scope(name, graph)) {
        for (OpaqueNode node : graph.getNodes().filter(OpaqueNode.class)) {
            node.replaceAndDelete(node.getValue());
        }
        HighTierContext context = getDefaultHighTierContext();
        CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
        new FloatingReadPhase().apply(graph);
        canonicalizer.apply(graph, context);
        new DeadCodeEliminationPhase().apply(graph);
        new GuardLoweringPhase().apply(graph, getDefaultMidTierContext());
        new FrameStateAssignmentPhase().apply(graph);
    } catch (Throwable e) {
        throw graph.getDebug().handle(e);
    }
}
Also used : FrameStateAssignmentPhase(org.graalvm.compiler.phases.common.FrameStateAssignmentPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) 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) OpaqueNode(org.graalvm.compiler.nodes.debug.OpaqueNode) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase)

Example 29 with LoweringPhase

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

the class IntegerExactFoldTest method testFoldingAfterLowering.

@Test
public void testFoldingAfterLowering() {
    StructuredGraph graph = prepareGraph();
    Node originalNode = graph.getNodes().filter(x -> x instanceof IntegerExactArithmeticNode).first();
    assertNotNull("original node must be in the graph", originalNode);
    graph.setGuardsStage(GuardsStage.FIXED_DEOPTS);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    PhaseContext context = new PhaseContext(getProviders());
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    IntegerExactArithmeticSplitNode loweredNode = graph.getNodes().filter(IntegerExactArithmeticSplitNode.class).first();
    assertNotNull("the lowered node must be in the graph", loweredNode);
    loweredNode.getX().setStamp(StampFactory.forInteger(bits, lowerBoundA, upperBoundA));
    loweredNode.getY().setStamp(StampFactory.forInteger(bits, lowerBoundB, upperBoundB));
    new CanonicalizerPhase().apply(graph, context);
    ValueNode node = findNode(graph);
    boolean overflowExpected = node instanceof IntegerExactArithmeticSplitNode;
    IntegerStamp resultStamp = (IntegerStamp) node.stamp(NodeView.DEFAULT);
    operation.verifyOverflow(lowerBoundA, upperBoundA, lowerBoundB, upperBoundB, bits, overflowExpected, resultStamp);
}
Also used : GuardsStage(org.graalvm.compiler.nodes.StructuredGraph.GuardsStage) LoweringTool(org.graalvm.compiler.nodes.spi.LoweringTool) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) ArrayList(java.util.ArrayList) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) Parameterized(org.junit.runners.Parameterized) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) IntegerExactArithmeticSplitNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) NodeView(org.graalvm.compiler.nodes.NodeView) Test(org.junit.Test) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) List(java.util.List) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Node(org.graalvm.compiler.graph.Node) Assert(org.junit.Assert) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) IntegerExactArithmeticSplitNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ValueNode(org.graalvm.compiler.nodes.ValueNode) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) IntegerExactArithmeticSplitNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) Test(org.junit.Test)

Example 30 with LoweringPhase

use of org.graalvm.compiler.phases.common.LoweringPhase 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

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