Search in sources :

Example 1 with MidTierContext

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

the class HotSpotSuitesProvider method createSuites.

@Override
public Suites createSuites(OptionValues options) {
    Suites ret = defaultSuitesCreator.createSuites(options);
    if (ImmutableCode.getValue(options)) {
        // lowering introduces class constants, therefore it must be after lowering
        ret.getHighTier().appendPhase(new LoadJavaMirrorWithKlassPhase(config));
        if (VerifyPhases.getValue(options)) {
            ret.getHighTier().appendPhase(new AheadOfTimeVerificationPhase());
        }
        if (GeneratePIC.getValue(options)) {
            ListIterator<BasePhase<? super HighTierContext>> highTierLowering = ret.getHighTier().findPhase(LoweringPhase.class);
            highTierLowering.previous();
            highTierLowering.add(new EliminateRedundantInitializationPhase());
            if (HotSpotAOTProfilingPlugin.Options.TieredAOT.getValue(options)) {
                highTierLowering.add(new FinalizeProfileNodesPhase(HotSpotAOTProfilingPlugin.Options.TierAInvokeInlineeNotifyFreqLog.getValue(options)));
            }
            ListIterator<BasePhase<? super MidTierContext>> midTierLowering = ret.getMidTier().findPhase(LoweringPhase.class);
            midTierLowering.add(new ReplaceConstantNodesPhase());
            // Replace inlining policy
            if (Inline.getValue(options)) {
                ListIterator<BasePhase<? super HighTierContext>> iter = ret.getHighTier().findPhase(InliningPhase.class);
                InliningPhase inlining = (InliningPhase) iter.previous();
                CanonicalizerPhase canonicalizer = inlining.getCanonicalizer();
                iter.set(new InliningPhase(new AOTInliningPolicy(null), canonicalizer));
            }
        }
    }
    ret.getMidTier().appendPhase(new WriteBarrierAdditionPhase(config));
    if (VerifyPhases.getValue(options)) {
        ret.getMidTier().appendPhase(new WriteBarrierVerificationPhase(config));
    }
    return ret;
}
Also used : EliminateRedundantInitializationPhase(org.graalvm.compiler.hotspot.phases.aot.EliminateRedundantInitializationPhase) WriteBarrierVerificationPhase(org.graalvm.compiler.hotspot.phases.WriteBarrierVerificationPhase) WriteBarrierAdditionPhase(org.graalvm.compiler.hotspot.phases.WriteBarrierAdditionPhase) FinalizeProfileNodesPhase(org.graalvm.compiler.hotspot.phases.profiling.FinalizeProfileNodesPhase) AOTInliningPolicy(org.graalvm.compiler.hotspot.phases.aot.AOTInliningPolicy) ReplaceConstantNodesPhase(org.graalvm.compiler.hotspot.phases.aot.ReplaceConstantNodesPhase) AheadOfTimeVerificationPhase(org.graalvm.compiler.hotspot.phases.AheadOfTimeVerificationPhase) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) LoadJavaMirrorWithKlassPhase(org.graalvm.compiler.hotspot.phases.LoadJavaMirrorWithKlassPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) BasePhase(org.graalvm.compiler.phases.BasePhase) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 2 with MidTierContext

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

the class IfCanonicalizerTest method testCombinedIf.

private void testCombinedIf(String snippet, int count) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    PhaseContext context = new PhaseContext(getProviders());
    new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    new FloatingReadPhase().apply(graph);
    MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
    new GuardLoweringPhase().apply(graph, midContext);
    new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, midContext);
    new CanonicalizerPhase().apply(graph, context);
    assertDeepEquals(count, graph.getNodes().filter(IfNode.class).count());
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) 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) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase)

Example 3 with MidTierContext

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

the class ImplicitNullCheckTest method test.

@SuppressWarnings("try")
private void test(final String snippet) {
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope s = debug.scope("FloatingReadTest", new DebugDumpScope(snippet))) {
        StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
        PhaseContext context = new PhaseContext(getProviders());
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
        new FloatingReadPhase().apply(graph);
        MidTierContext midTierContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
        new GuardLoweringPhase().apply(graph, midTierContext);
        Assert.assertEquals(0, graph.getNodes(DeoptimizeNode.TYPE).count());
        Assert.assertTrue(graph.getNodes().filter(ReadNode.class).first().canNullCheck());
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) DebugContext(org.graalvm.compiler.debug.DebugContext) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase)

Example 4 with MidTierContext

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

the class NativeImageGenerator method createSuites.

public static Suites createSuites(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, SnippetReflectionProvider snippetReflection, boolean hosted) {
    Providers runtimeCallProviders = runtimeConfig.getBackendForNormalMethod().getProviders();
    OptionValues options = hosted ? HostedOptionValues.singleton() : RuntimeOptionValues.singleton();
    Suites suites = GraalConfiguration.instance().createSuites(options, hosted);
    PhaseSuite<HighTierContext> highTier = suites.getHighTier();
    PhaseSuite<MidTierContext> midTier = suites.getMidTier();
    PhaseSuite<LowTierContext> lowTier = suites.getLowTier();
    ListIterator<BasePhase<? super HighTierContext>> position;
    if (hosted) {
        position = GraalConfiguration.instance().createHostedInliners(highTier);
    } else {
        /* Find the runtime inliner. */
        position = highTier.findPhase(InliningPhase.class);
    }
    if (position != null) {
        /* These two phases must be after all method inlining. */
        position.add(new DeadStoreRemovalPhase());
        position.add(new RemoveUnwindPhase());
    } else {
        /* There is no inlining, so prepend them in reverse order. */
        highTier.prependPhase(new RemoveUnwindPhase());
        highTier.prependPhase(new DeadStoreRemovalPhase());
    }
    highTier.appendPhase(new StackValuePhase());
    lowTier.addBeforeLast(new OptimizeExceptionCallsPhase());
    CompressEncoding compressEncoding = ImageSingletons.lookup(CompressEncoding.class);
    SubstrateAMD64RegisterConfig registerConfig = (SubstrateAMD64RegisterConfig) runtimeCallProviders.getCodeCache().getRegisterConfig();
    SubstrateAMD64AddressLowering addressLowering = new SubstrateAMD64AddressLowering(compressEncoding, registerConfig);
    lowTier.findPhase(FixReadsPhase.class).add(new AddressLoweringPhase(addressLowering));
    if (SubstrateOptions.MultiThreaded.getValue()) {
        /*
             * Graal inserts only loop safepoints. We want a SafepointNode also before every return.
             */
        midTier.findPhase(LoopSafepointInsertionPhase.class).add(new MethodSafepointInsertionPhase());
    } else {
        /* No need for safepoints when we have only one thread. */
        VMError.guarantee(midTier.removePhase(LoopSafepointInsertionPhase.class));
    }
    if (hosted) {
        lowTier.appendPhase(new VerifyNoGuardsPhase());
        /* Disable the Graal method inlining, since we have our own inlining system. */
        highTier.removePhase(InliningPhase.class);
        /* Remove phases that are not suitable for AOT compilation. */
        highTier.findPhase(ConvertDeoptimizeToGuardPhase.class, true).remove();
        midTier.findPhase(DeoptimizationGroupingPhase.class).remove();
    } else {
        ListIterator<BasePhase<? super MidTierContext>> it = midTier.findPhase(DeoptimizationGroupingPhase.class);
        it.previous();
        it.add(new CollectDeoptimizationSourcePositionsPhase());
    }
    featureHandler.forEachGraalFeature(feature -> feature.registerGraalPhases(runtimeCallProviders, snippetReflection, suites, hosted));
    return suites;
}
Also used : LowTierContext(org.graalvm.compiler.phases.tiers.LowTierContext) HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) RuntimeOptionValues(com.oracle.svm.core.option.RuntimeOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) StackValuePhase(com.oracle.svm.core.graal.stackvalue.StackValuePhase) CompressEncoding(org.graalvm.compiler.core.common.CompressEncoding) SubstrateAMD64RegisterConfig(com.oracle.svm.core.graal.code.amd64.SubstrateAMD64RegisterConfig) DeadStoreRemovalPhase(com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase) Providers(org.graalvm.compiler.phases.util.Providers) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) RemoveUnwindPhase(com.oracle.svm.core.graal.phases.RemoveUnwindPhase) SubstrateAMD64AddressLowering(com.oracle.svm.core.graal.code.amd64.SubstrateAMD64AddressLowering) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) OptimizeExceptionCallsPhase(com.oracle.svm.core.graal.phases.OptimizeExceptionCallsPhase) BasePhase(org.graalvm.compiler.phases.BasePhase) AddressLoweringPhase(org.graalvm.compiler.phases.common.AddressLoweringPhase) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites) LoopSafepointInsertionPhase(org.graalvm.compiler.phases.common.LoopSafepointInsertionPhase) ConvertDeoptimizeToGuardPhase(org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase) FixReadsPhase(org.graalvm.compiler.phases.common.FixReadsPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) MethodSafepointInsertionPhase(com.oracle.svm.core.graal.phases.MethodSafepointInsertionPhase) DeoptimizationGroupingPhase(org.graalvm.compiler.phases.common.DeoptimizationGroupingPhase) CollectDeoptimizationSourcePositionsPhase(com.oracle.svm.core.graal.phases.CollectDeoptimizationSourcePositionsPhase) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) VerifyNoGuardsPhase(com.oracle.svm.hosted.phases.VerifyNoGuardsPhase)

Example 5 with MidTierContext

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

the class WriteBarrierAdditionTest method testHelper.

@SuppressWarnings("try")
private void testHelper(final String snippetName, final int expectedBarriers) throws Exception, SecurityException {
    ResolvedJavaMethod snippet = getResolvedJavaMethod(snippetName);
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope s = debug.scope("WriteBarrierAdditionTest", snippet)) {
        StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO, debug);
        HighTierContext highContext = getDefaultHighTierContext();
        MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
        new InliningPhase(new InlineEverythingPolicy(), new CanonicalizerPhase()).apply(graph, highContext);
        new CanonicalizerPhase().apply(graph, highContext);
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, highContext);
        new GuardLoweringPhase().apply(graph, midContext);
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, midContext);
        new WriteBarrierAdditionPhase(config).apply(graph);
        debug.dump(DebugContext.BASIC_LEVEL, graph, "After Write Barrier Addition");
        int barriers = 0;
        if (config.useG1GC) {
            barriers = graph.getNodes().filter(G1ReferentFieldReadBarrier.class).count() + graph.getNodes().filter(G1PreWriteBarrier.class).count() + graph.getNodes().filter(G1PostWriteBarrier.class).count();
        } else {
            barriers = graph.getNodes().filter(SerialWriteBarrier.class).count();
        }
        if (expectedBarriers != barriers) {
            Assert.assertEquals(getScheduledGraphString(graph), expectedBarriers, barriers);
        }
        for (WriteNode write : graph.getNodes().filter(WriteNode.class)) {
            if (config.useG1GC) {
                if (write.getBarrierType() != BarrierType.NONE) {
                    Assert.assertEquals(1, write.successors().count());
                    Assert.assertTrue(write.next() instanceof G1PostWriteBarrier);
                    Assert.assertTrue(write.predecessor() instanceof G1PreWriteBarrier);
                }
            } else {
                if (write.getBarrierType() != BarrierType.NONE) {
                    Assert.assertEquals(1, write.successors().count());
                    Assert.assertTrue(write.next() instanceof SerialWriteBarrier);
                }
            }
        }
        for (ReadNode read : graph.getNodes().filter(ReadNode.class)) {
            if (read.getBarrierType() != BarrierType.NONE) {
                Assert.assertTrue(read.getAddress() instanceof OffsetAddressNode);
                JavaConstant constDisp = ((OffsetAddressNode) read.getAddress()).getOffset().asJavaConstant();
                Assert.assertNotNull(constDisp);
                Assert.assertEquals(referentOffset, constDisp.asLong());
                Assert.assertTrue(config.useG1GC);
                Assert.assertEquals(BarrierType.PRECISE, read.getBarrierType());
                Assert.assertTrue(read.next() instanceof G1ReferentFieldReadBarrier);
            }
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : InlineEverythingPolicy(org.graalvm.compiler.phases.common.inlining.policy.InlineEverythingPolicy) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) WriteBarrierAdditionPhase(org.graalvm.compiler.hotspot.phases.WriteBarrierAdditionPhase) G1PreWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier) JavaConstant(jdk.vm.ci.meta.JavaConstant) DebugContext(org.graalvm.compiler.debug.DebugContext) SerialWriteBarrier(org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier) G1ReferentFieldReadBarrier(org.graalvm.compiler.hotspot.nodes.G1ReferentFieldReadBarrier) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) G1PostWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

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