Search in sources :

Example 6 with Suites

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

the class NestedLoop_EA method createSuites.

@Override
protected Suites createSuites(OptionValues options) {
    Suites suites = super.createSuites(options);
    ListIterator<BasePhase<? super HighTierContext>> position = suites.getHighTier().findPhase(PartialEscapePhase.class);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    // incremental canonicalizer of PEA is missing some important canonicalization (TODO?)
    position.add(canonicalizer);
    position.add(new PartialEscapePhase(true, canonicalizer, options));
    return suites;
}
Also used : PartialEscapePhase(org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) BasePhase(org.graalvm.compiler.phases.BasePhase) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 7 with Suites

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

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

the class Stub method buildCompilationResult.

@SuppressWarnings("try")
private CompilationResult buildCompilationResult(DebugContext debug, final Backend backend) {
    CompilationIdentifier compilationId = getStubCompilationId();
    final StructuredGraph graph = getGraph(debug, compilationId);
    CompilationResult compResult = new CompilationResult(compilationId, toString(), GeneratePIC.getValue(options));
    // Stubs cannot be recompiled so they cannot be compiled with assumptions
    assert graph.getAssumptions() == null;
    if (!(graph.start() instanceof StubStartNode)) {
        StubStartNode newStart = graph.add(new StubStartNode(Stub.this));
        newStart.setStateAfter(graph.start().stateAfter());
        graph.replaceFixed(graph.start(), newStart);
    }
    try (DebugContext.Scope s0 = debug.scope("StubCompilation", graph, providers.getCodeCache())) {
        Suites suites = createSuites();
        emitFrontEnd(providers, backend, graph, providers.getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL, DefaultProfilingInfo.get(TriState.UNKNOWN), suites);
        LIRSuites lirSuites = createLIRSuites();
        emitBackEnd(graph, Stub.this, getInstalledCodeOwner(), backend, compResult, CompilationResultBuilderFactory.Default, getRegisterConfig(), lirSuites);
        assert checkStubInvariants(compResult);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    return compResult;
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) StubStartNode(org.graalvm.compiler.hotspot.nodes.StubStartNode) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) CompilationResult(org.graalvm.compiler.code.CompilationResult) DebugContext(org.graalvm.compiler.debug.DebugContext) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 9 with Suites

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

the class InvokeGraal method compileAndInstallMethod.

/**
 * The simplest way to compile a method, using the default behavior for everything.
 */
@SuppressWarnings("try")
protected InstalledCode compileAndInstallMethod(ResolvedJavaMethod method) {
    /* Create a unique compilation identifier, visible in IGV. */
    CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
    OptionValues options = getInitialOptions();
    DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
    try (DebugContext.Scope s = debug.scope("compileAndInstallMethod", new DebugDumpScope(String.valueOf(compilationId), true))) {
        /*
             * The graph that is compiled. We leave it empty (no nodes added yet). This means that
             * it will be filled according to the graphBuilderSuite defined below. We also specify
             * that we want the compilation to make optimistic assumptions about runtime state such
             * as the loaded class hierarchy.
             */
        StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(method).compilationId(compilationId).build();
        /*
             * The phases used to build the graph. Usually this is just the GraphBuilderPhase. If
             * the graph already contains nodes, it is ignored.
             */
        PhaseSuite<HighTierContext> graphBuilderSuite = backend.getSuites().getDefaultGraphBuilderSuite();
        /*
             * The optimization phases that are applied to the graph. This is the main configuration
             * point for Graal. Add or remove phases to customize your compilation.
             */
        Suites suites = backend.getSuites().getDefaultSuites(options);
        /*
             * The low-level phases that are applied to the low-level representation.
             */
        LIRSuites lirSuites = backend.getSuites().getDefaultLIRSuites(options);
        /*
             * We want Graal to perform all speculative optimistic optimizations, using the
             * profiling information that comes with the method (collected by the interpreter) for
             * speculation.
             */
        OptimisticOptimizations optimisticOpts = OptimisticOptimizations.ALL;
        ProfilingInfo profilingInfo = graph.getProfilingInfo(method);
        /* The default class and configuration for compilation results. */
        CompilationResult compilationResult = new CompilationResult(graph.compilationId());
        CompilationResultBuilderFactory factory = CompilationResultBuilderFactory.Default;
        /* Invoke the whole Graal compilation pipeline. */
        GraalCompiler.compileGraph(graph, method, providers, backend, graphBuilderSuite, optimisticOpts, profilingInfo, suites, lirSuites, compilationResult, factory);
        /*
             * Install the compilation result into the VM, i.e., copy the byte[] array that contains
             * the machine code into an actual executable memory location.
             */
        return backend.addInstalledCode(debug, method, asCompilationRequest(compilationId), compilationResult);
    } catch (Throwable ex) {
        throw debug.handle(ex);
    }
}
Also used : CompilationIdentifier(org.graalvm.compiler.core.common.CompilationIdentifier) OptionValues(org.graalvm.compiler.options.OptionValues) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) ProfilingInfo(jdk.vm.ci.meta.ProfilingInfo) DebugContext(org.graalvm.compiler.debug.DebugContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) CompilationResult(org.graalvm.compiler.code.CompilationResult) OptimisticOptimizations(org.graalvm.compiler.phases.OptimisticOptimizations) CompilationResultBuilderFactory(org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 10 with Suites

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

the class SPARCSuitesCreator method createSuites.

@Override
public Suites createSuites(OptionValues options) {
    Suites s = super.createSuites(options);
    ListIterator<BasePhase<? super LowTierContext>> l = s.getLowTier().findPhase(ExpandLogicPhase.class);
    while (PhaseSuite.findNextPhase(l, ExpandLogicPhase.class)) {
    // Search for last occurrence of ExpandLogicPhase
    }
    l.previous();
    l.add(new SPARCIntegerCompareCanonicalizationPhase());
    return s;
}
Also used : LowTierContext(org.graalvm.compiler.phases.tiers.LowTierContext) BasePhase(org.graalvm.compiler.phases.BasePhase) Suites(org.graalvm.compiler.phases.tiers.Suites)

Aggregations

Suites (org.graalvm.compiler.phases.tiers.Suites)16 LIRSuites (org.graalvm.compiler.lir.phases.LIRSuites)10 BasePhase (org.graalvm.compiler.phases.BasePhase)8 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)7 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)6 CompilationResult (org.graalvm.compiler.code.CompilationResult)4 DebugContext (org.graalvm.compiler.debug.DebugContext)4 OptionValues (org.graalvm.compiler.options.OptionValues)4 LowTierContext (org.graalvm.compiler.phases.tiers.LowTierContext)4 Backend (org.graalvm.compiler.core.target.Backend)3 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)3 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)3 MidTierContext (org.graalvm.compiler.phases.tiers.MidTierContext)3 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 ProfilingInfo (jdk.vm.ci.meta.ProfilingInfo)2 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)2 CompilationResultBuilderFactory (org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory)2 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)2 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)2 OptimisticOptimizations (org.graalvm.compiler.phases.OptimisticOptimizations)2