Search in sources :

Example 1 with SubstrateSafepointInsertionPhase

use of com.oracle.svm.core.graal.phases.SubstrateSafepointInsertionPhase in project graal by oracle.

the class NativeImageGenerator method modifySuites.

@SuppressWarnings("unused")
private static Suites modifySuites(SubstrateBackend backend, Suites suites, FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, SnippetReflectionProvider snippetReflection, boolean hosted, boolean firstTier) {
    Providers runtimeCallProviders = backend.getProviders();
    PhaseSuite<HighTierContext> highTier = suites.getHighTier();
    PhaseSuite<MidTierContext> midTier = suites.getMidTier();
    PhaseSuite<LowTierContext> lowTier = suites.getLowTier();
    final boolean economy = firstTier || SubstrateOptions.useEconomyCompilerConfig();
    ListIterator<BasePhase<? super HighTierContext>> position;
    if (hosted) {
        position = GraalConfiguration.hostedInstance().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());
    }
    lowTier.addBeforeLast(new OptimizeExceptionPathsPhase());
    BasePhase<CoreProviders> addressLoweringPhase = backend.newAddressLoweringPhase(runtimeCallProviders.getCodeCache());
    if (economy) {
        lowTier.findPhase(ExpandLogicPhase.class, true).add(addressLoweringPhase);
    } else {
        lowTier.findPhase(UseTrappingNullChecksPhase.class).add(addressLoweringPhase);
    }
    if (SubstrateOptions.MultiThreaded.getValue()) {
        /*
             * Graal inserts only loop safepoints. We want a SafepointNode also before every return.
             * Our safepoint insertion phase inserts both kinds of safepoints.
             */
        midTier.findPhase(LoopSafepointInsertionPhase.class).set(new SubstrateSafepointInsertionPhase());
    } 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.removePhase(ConvertDeoptimizeToGuardPhase.class);
        midTier.removePhase(DeoptimizationGroupingPhase.class);
    } else {
        if (economy) {
            ListIterator<BasePhase<? super MidTierContext>> it = midTier.findPhase(FrameStateAssignmentPhase.class);
            it.add(new CollectDeoptimizationSourcePositionsPhase());
            // On SVM, the economy configuration requires a canonicalization run at the end of
            // mid tier.
            it = midTier.findLastPhase();
            it.add(CanonicalizerPhase.create());
        } 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));
    if (hosted && ImageBuildStatistics.Options.CollectImageBuildStatistics.getValue(HostedOptionValues.singleton())) {
        highTier.prependPhase(new ImageBuildStatisticsCounterPhase(ImageBuildStatistics.CheckCountLocation.BEFORE_HIGH_TIER));
        highTier.prependPhase(CanonicalizerPhase.create());
        highTier.findLastPhase().add(CanonicalizerPhase.create());
        highTier.findLastPhase().add(new ImageBuildStatisticsCounterPhase(ImageBuildStatistics.CheckCountLocation.AFTER_HIGH_TIER));
    }
    return suites;
}
Also used : UseTrappingNullChecksPhase(org.graalvm.compiler.phases.common.UseTrappingNullChecksPhase) LowTierContext(org.graalvm.compiler.phases.tiers.LowTierContext) LoopSafepointInsertionPhase(org.graalvm.compiler.phases.common.LoopSafepointInsertionPhase) DeadStoreRemovalPhase(com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase) Providers(org.graalvm.compiler.phases.util.Providers) CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) RemoveUnwindPhase(com.oracle.svm.core.graal.phases.RemoveUnwindPhase) OptimizeExceptionPathsPhase(com.oracle.svm.core.graal.phases.OptimizeExceptionPathsPhase) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) CoreProviders(org.graalvm.compiler.nodes.spi.CoreProviders) ImageBuildStatisticsCounterPhase(com.oracle.svm.hosted.phases.ImageBuildStatisticsCounterPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) ExpandLogicPhase(org.graalvm.compiler.phases.common.ExpandLogicPhase) SubstrateSafepointInsertionPhase(com.oracle.svm.core.graal.phases.SubstrateSafepointInsertionPhase) CollectDeoptimizationSourcePositionsPhase(com.oracle.svm.core.graal.phases.CollectDeoptimizationSourcePositionsPhase) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) VerifyNoGuardsPhase(com.oracle.svm.hosted.phases.VerifyNoGuardsPhase) BasePhase(org.graalvm.compiler.phases.BasePhase)

Aggregations

HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)1 CollectDeoptimizationSourcePositionsPhase (com.oracle.svm.core.graal.phases.CollectDeoptimizationSourcePositionsPhase)1 DeadStoreRemovalPhase (com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase)1 OptimizeExceptionPathsPhase (com.oracle.svm.core.graal.phases.OptimizeExceptionPathsPhase)1 RemoveUnwindPhase (com.oracle.svm.core.graal.phases.RemoveUnwindPhase)1 SubstrateSafepointInsertionPhase (com.oracle.svm.core.graal.phases.SubstrateSafepointInsertionPhase)1 ImageBuildStatisticsCounterPhase (com.oracle.svm.hosted.phases.ImageBuildStatisticsCounterPhase)1 VerifyNoGuardsPhase (com.oracle.svm.hosted.phases.VerifyNoGuardsPhase)1 CoreProviders (org.graalvm.compiler.nodes.spi.CoreProviders)1 BasePhase (org.graalvm.compiler.phases.BasePhase)1 ExpandLogicPhase (org.graalvm.compiler.phases.common.ExpandLogicPhase)1 LoopSafepointInsertionPhase (org.graalvm.compiler.phases.common.LoopSafepointInsertionPhase)1 UseTrappingNullChecksPhase (org.graalvm.compiler.phases.common.UseTrappingNullChecksPhase)1 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)1 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)1 LowTierContext (org.graalvm.compiler.phases.tiers.LowTierContext)1 MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)1 Providers (org.graalvm.compiler.phases.util.Providers)1