Search in sources :

Example 1 with CompilationResultBuilderFactory

use of org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory in project graal by oracle.

the class HotSpotTruffleCompilerImpl method compileTruffleCallBoundaryMethod.

/**
 * Compiles a method denoted as a
 * {@linkplain HotSpotTruffleCompilerRuntime#getTruffleCallBoundaryMethods() Truffle call
 * boundary}. The compiled code has a special entry point generated by an
 * {@link TruffleCallBoundaryInstrumentationFactory}.
 */
private CompilationResult compileTruffleCallBoundaryMethod(ResolvedJavaMethod javaMethod, CompilationIdentifier compilationId, DebugContext debug) {
    Suites newSuites = this.suites.copy();
    removeInliningPhase(newSuites);
    OptionValues options = TruffleCompilerOptions.getOptions();
    StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.NO).method(javaMethod).compilationId(compilationId).build();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    Plugins plugins = new Plugins(new InvocationPlugins());
    HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) providers.getCodeCache();
    boolean infoPoints = codeCache.shouldDebugNonSafepoints();
    GraphBuilderConfiguration newConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true).withNodeSourcePosition(infoPoints);
    new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), newConfig, OptimisticOptimizations.ALL, null).apply(graph);
    PhaseSuite<HighTierContext> graphBuilderSuite = getGraphBuilderSuite(codeCache, backend.getSuites());
    CompilationResultBuilderFactory factory = getTruffleCallBoundaryInstrumentationFactory(backend.getTarget().arch.getName());
    return compileGraph(graph, javaMethod, providers, backend, graphBuilderSuite, OptimisticOptimizations.ALL, graph.getProfilingInfo(), newSuites, lirSuites, new CompilationResult(compilationId), factory);
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) HotSpotCodeCacheProvider(jdk.vm.ci.hotspot.HotSpotCodeCacheProvider) OptionValues(org.graalvm.compiler.options.OptionValues) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) CompilationResult(org.graalvm.compiler.code.CompilationResult) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) CompilationResultBuilderFactory(org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 2 with CompilationResultBuilderFactory

use of org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory 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)

Aggregations

CompilationResult (org.graalvm.compiler.code.CompilationResult)2 CompilationResultBuilderFactory (org.graalvm.compiler.lir.asm.CompilationResultBuilderFactory)2 LIRSuites (org.graalvm.compiler.lir.phases.LIRSuites)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 OptionValues (org.graalvm.compiler.options.OptionValues)2 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)2 Suites (org.graalvm.compiler.phases.tiers.Suites)2 HotSpotCodeCacheProvider (jdk.vm.ci.hotspot.HotSpotCodeCacheProvider)1 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)1 ProfilingInfo (jdk.vm.ci.meta.ProfilingInfo)1 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)1 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)1 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)1 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)1 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)1 OptimisticOptimizations (org.graalvm.compiler.phases.OptimisticOptimizations)1