Search in sources :

Example 11 with MidTierContext

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

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

the class LoopPartialUnrollTest method createSuites.

@Override
protected Suites createSuites(OptionValues opts) {
    Suites suites = super.createSuites(opts).copy();
    PhaseSuite<MidTierContext> mid = suites.getMidTier();
    ListIterator<BasePhase<? super MidTierContext>> iter = mid.findPhase(LoopPartialUnrollPhase.class);
    BasePhase<? super MidTierContext> partialUnoll = iter.previous();
    if (iter.previous().getClass() != FrameStateAssignmentPhase.class) {
        // Ensure LoopPartialUnrollPhase runs immediately after FrameStateAssignment, so it gets
        // priority over other optimizations in these tests.
        mid.findPhase(LoopPartialUnrollPhase.class).remove();
        ListIterator<BasePhase<? super MidTierContext>> fsa = mid.findPhase(FrameStateAssignmentPhase.class);
        fsa.add(partialUnoll);
    }
    return suites;
}
Also used : MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) LoopPartialUnrollPhase(org.graalvm.compiler.loop.phases.LoopPartialUnrollPhase) BasePhase(org.graalvm.compiler.phases.BasePhase) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 13 with MidTierContext

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

the class GraalCompiler method emitFrontEnd.

/**
 * Builds the graph, optimizes it.
 */
@SuppressWarnings("try")
public static void emitFrontEnd(Providers providers, TargetProvider target, StructuredGraph graph, PhaseSuite<HighTierContext> graphBuilderSuite, OptimisticOptimizations optimisticOpts, ProfilingInfo profilingInfo, Suites suites) {
    DebugContext debug = graph.getDebug();
    try (DebugContext.Scope s = debug.scope("FrontEnd");
        DebugCloseable a = FrontEnd.start(debug)) {
        HighTierContext highTierContext = new HighTierContext(providers, graphBuilderSuite, optimisticOpts);
        if (graph.start().next() == null) {
            graphBuilderSuite.apply(graph, highTierContext);
            new DeadCodeEliminationPhase(DeadCodeEliminationPhase.Optionality.Optional).apply(graph);
            debug.dump(DebugContext.BASIC_LEVEL, graph, "After parsing");
        } else {
            debug.dump(DebugContext.INFO_LEVEL, graph, "initial state");
        }
        suites.getHighTier().apply(graph, highTierContext);
        graph.maybeCompress();
        debug.dump(DebugContext.BASIC_LEVEL, graph, "After high tier");
        MidTierContext midTierContext = new MidTierContext(providers, target, optimisticOpts, profilingInfo);
        suites.getMidTier().apply(graph, midTierContext);
        graph.maybeCompress();
        debug.dump(DebugContext.BASIC_LEVEL, graph, "After mid tier");
        LowTierContext lowTierContext = new LowTierContext(providers, target);
        suites.getLowTier().apply(graph, lowTierContext);
        debug.dump(DebugContext.BASIC_LEVEL, graph, "After low tier");
        debug.dump(DebugContext.BASIC_LEVEL, graph.getLastSchedule(), "Final HIR schedule");
        graph.logInliningTree();
    } catch (Throwable e) {
        throw debug.handle(e);
    } finally {
        graph.checkCancellation();
    }
}
Also used : MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) LowTierContext(org.graalvm.compiler.phases.tiers.LowTierContext) DebugContext(org.graalvm.compiler.debug.DebugContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)

Aggregations

MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)13 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)9 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)9 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)8 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)8 DebugContext (org.graalvm.compiler.debug.DebugContext)7 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)6 OptionValues (org.graalvm.compiler.options.OptionValues)5 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)5 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)4 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)4 WriteBarrierAdditionPhase (org.graalvm.compiler.hotspot.phases.WriteBarrierAdditionPhase)3 BasePhase (org.graalvm.compiler.phases.BasePhase)3 Suites (org.graalvm.compiler.phases.tiers.Suites)3 List (java.util.List)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)2 G1PostWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier)2 G1PreWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier)2 SerialWriteBarrier (org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier)2