Search in sources :

Example 96 with CanonicalizerPhase

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

the class LoopUnswitchTest method test.

@SuppressWarnings("try")
private void test(String snippet, String referenceSnippet) {
    DebugContext debug = getDebugContext();
    final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
    final StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
    new LoopUnswitchingPhase(new DefaultLoopPolicies()).apply(graph);
    // Framestates create comparison problems
    graph.clearAllStateAfter();
    referenceGraph.clearAllStateAfter();
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    new CanonicalizerPhase().apply(referenceGraph, new PhaseContext(getProviders()));
    try (DebugContext.Scope s = debug.scope("Test", new DebugDumpScope("Test:" + snippet))) {
        assertEquals(referenceGraph, graph);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) DefaultLoopPolicies(org.graalvm.compiler.loop.DefaultLoopPolicies) LoopUnswitchingPhase(org.graalvm.compiler.loop.phases.LoopUnswitchingPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 97 with CanonicalizerPhase

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

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

the class LoopPartialUnrollTest method testDuplicateBody.

public void testDuplicateBody(String reference, String test) {
    StructuredGraph referenceGraph = buildGraph(reference, false);
    StructuredGraph testGraph = buildGraph(test, true);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    canonicalizer.apply(testGraph, getDefaultMidTierContext());
    canonicalizer.apply(referenceGraph, getDefaultMidTierContext());
    assertEquals(referenceGraph, testGraph);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 99 with CanonicalizerPhase

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

the class PointerTest method assertNumWordCasts.

private void assertNumWordCasts(String snippetName, int expectedWordCasts) {
    HighTierContext context = new HighTierContext(getProviders(), null, OptimisticOptimizations.ALL);
    StructuredGraph graph = parseEager(snippetName, AllowAssumptions.YES);
    new CanonicalizerPhase().apply(graph, context);
    Assert.assertEquals(expectedWordCasts, graph.getNodes().filter(WordCastNode.class).count());
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext)

Example 100 with CanonicalizerPhase

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

Aggregations

CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)114 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)98 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)60 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)48 DebugContext (org.graalvm.compiler.debug.DebugContext)34 Test (org.junit.Test)33 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)31 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)27 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)17 DeadCodeEliminationPhase (org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)16 PartialEscapePhase (org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase)14 Node (org.graalvm.compiler.graph.Node)12 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)12 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)10 OptionValues (org.graalvm.compiler.options.OptionValues)10 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)10 ConditionalEliminationPhase (org.graalvm.compiler.phases.common.ConditionalEliminationPhase)9 MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)9 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)8 Invoke (org.graalvm.compiler.nodes.Invoke)8