Search in sources :

Example 1 with LoopFragmentInside

use of org.graalvm.compiler.nodes.loop.LoopFragmentInside 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 = this.createCanonicalizerPhase();
        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);
        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 = getDefaultMidTierContext().getLoopsDataProvider().getLoopsData(graph);
            dataCounted.detectedCountedLoops();
            assertTrue(!dataCounted.countedLoops().isEmpty(), "must have counted loops");
            for (LoopEx loop : dataCounted.countedLoops()) {
                LoopFragmentInside newSegment = loop.inside().duplicate();
                newSegment.insertWithinAfter(loop, null);
            }
            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.nodes.loop.LoopsData) OptionValues(org.graalvm.compiler.options.OptionValues) LoopFragmentInside(org.graalvm.compiler.nodes.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.nodes.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 2 with LoopFragmentInside

use of org.graalvm.compiler.nodes.loop.LoopFragmentInside in project graal by oracle.

the class LoopTransformations method partialUnroll.

public static void partialUnroll(LoopEx loop, EconomicMap<LoopBeginNode, OpaqueNode> opaqueUnrolledStrides) {
    assert loop.loopBegin().isMainLoop();
    loop.loopBegin().graph().getDebug().log("LoopPartialUnroll %s", loop);
    adaptCountedLoopExitProbability(loop.counted().getCountedExit(), loop.localLoopFrequency() / 2D);
    LoopFragmentInside newSegment = loop.inside().duplicate();
    newSegment.insertWithinAfter(loop, opaqueUnrolledStrides);
}
Also used : LoopFragmentInside(org.graalvm.compiler.nodes.loop.LoopFragmentInside)

Example 3 with LoopFragmentInside

use of org.graalvm.compiler.nodes.loop.LoopFragmentInside in project graal by oracle.

the class LoopTransformations method peel.

public static LoopFragmentInside peel(LoopEx loop) {
    loop.detectCounted();
    double frequencyBefore = -1D;
    AbstractBeginNode countedExit = null;
    if (loop.isCounted()) {
        frequencyBefore = loop.localLoopFrequency();
        countedExit = loop.counted().getCountedExit();
    }
    LoopFragmentInside inside = loop.inside().duplicate();
    inside.insertBefore(loop);
    loop.loopBegin().incrementPeelings();
    if (countedExit != null) {
        adaptCountedLoopExitProbability(countedExit, frequencyBefore - 1D);
    }
    return inside;
}
Also used : LoopFragmentInside(org.graalvm.compiler.nodes.loop.LoopFragmentInside) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Aggregations

LoopFragmentInside (org.graalvm.compiler.nodes.loop.LoopFragmentInside)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1 LoopEx (org.graalvm.compiler.nodes.loop.LoopEx)1 LoopsData (org.graalvm.compiler.nodes.loop.LoopsData)1 OptionValues (org.graalvm.compiler.options.OptionValues)1 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)1 ConditionalEliminationPhase (org.graalvm.compiler.phases.common.ConditionalEliminationPhase)1 DeadCodeEliminationPhase (org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)1 DeoptimizationGroupingPhase (org.graalvm.compiler.phases.common.DeoptimizationGroupingPhase)1 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)1 FrameStateAssignmentPhase (org.graalvm.compiler.phases.common.FrameStateAssignmentPhase)1 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)1 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)1 RemoveValueProxyPhase (org.graalvm.compiler.phases.common.RemoveValueProxyPhase)1 MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)1