Search in sources :

Example 11 with Suites

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

the class CompileQueue method defaultCompileFunction.

@SuppressWarnings("try")
private CompilationResult defaultCompileFunction(DebugContext debug, HostedMethod method, CompilationIdentifier compilationIdentifier, CompileReason reason, RuntimeConfiguration config) {
    if (NativeImageOptions.PrintAOTCompilation.getValue()) {
        System.out.println("Compiling " + method.format("%r %H.%n(%p)") + "  [" + reason + "]");
    }
    Backend backend = config.lookupBackend(method);
    StructuredGraph graph = method.compilationInfo.graph;
    assert graph != null : method;
    /* Operate on a copy, to keep the original graph intact for later inlining. */
    graph = graph.copyWithIdentifier(compilationIdentifier, debug);
    /* Check that graph is in good shape before compilation. */
    assert GraphOrder.assertSchedulableGraph(graph);
    try (DebugContext.Scope s = debug.scope("Compiling", graph, method, this)) {
        if (deoptimizeAll && method.compilationInfo.canDeoptForTesting) {
            insertDeoptTests(method, graph);
        }
        method.compilationInfo.numNodesBeforeCompilation = graph.getNodeCount();
        method.compilationInfo.numDeoptEntryPoints = graph.getNodes().filter(DeoptEntryNode.class).count();
        method.compilationInfo.numDuringCallEntryPoints = graph.getNodes(MethodCallTargetNode.TYPE).snapshot().stream().map(MethodCallTargetNode::invoke).filter(invoke -> method.compilationInfo.isDeoptEntry(invoke.bci(), true, false)).count();
        Suites suites = method.compilationInfo.isDeoptTarget() ? deoptTargetSuites : regularSuites;
        LIRSuites lirSuites = method.compilationInfo.isDeoptTarget() ? deoptTargetLIRSuites : regularLIRSuites;
        CompilationResult result = new CompilationResult(compilationIdentifier, method.format("%H.%n(%p)")) {

            @Override
            public void close() {
            /*
                     * Do nothing, we do not want our CompilationResult to be closed because we
                     * aggregate all data items and machine code in the native image heap.
                     */
            }
        };
        try (Indent indent = debug.logAndIndent("compile %s", method)) {
            GraalCompiler.compileGraph(graph, method, backend.getProviders(), backend, null, optimisticOpts, method.getProfilingInfo(), suites, lirSuites, result, new HostedCompilationResultBuilderFactory());
        }
        method.getProfilingInfo().setCompilerIRSize(StructuredGraph.class, method.compilationInfo.graph.getNodeCount());
        method.compilationInfo.numNodesAfterCompilation = graph.getNodeCount();
        if (method.compilationInfo.isDeoptTarget()) {
            assert verifyDeoptTarget(method, result);
        }
        for (Infopoint infopoint : result.getInfopoints()) {
            if (infopoint instanceof Call) {
                Call call = (Call) infopoint;
                HostedMethod callTarget = (HostedMethod) call.target;
                if (call.direct) {
                    ensureCompiled(callTarget, new DirectCallReason(method, reason));
                } else if (callTarget != null && callTarget.getImplementations() != null) {
                    for (HostedMethod impl : callTarget.getImplementations()) {
                        ensureCompiled(impl, new VirtualCallReason(method, callTarget, reason));
                    }
                }
            }
        }
        /* Shrink resulting code array to minimum size, to reduze memory footprint. */
        if (result.getTargetCode().length > result.getTargetCodeSize()) {
            result.setTargetCode(Arrays.copyOf(result.getTargetCode(), result.getTargetCodeSize()), result.getTargetCodeSize());
        }
        return result;
    } catch (Throwable ex) {
        GraalError error = ex instanceof GraalError ? (GraalError) ex : new GraalError(ex);
        error.addContext("method: " + method.format("%r %H.%n(%p)") + "  [" + reason + "]");
        throw error;
    }
}
Also used : Call(jdk.vm.ci.code.site.Call) Indent(org.graalvm.compiler.debug.Indent) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) Infopoint(jdk.vm.ci.code.site.Infopoint) DebugContext(org.graalvm.compiler.debug.DebugContext) Backend(org.graalvm.compiler.core.target.Backend) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) CompilationResult(org.graalvm.compiler.code.CompilationResult) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 12 with Suites

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

the class RuntimeStrengthenStampsPhase method beforeAnalysis.

@Override
public void beforeAnalysis(BeforeAnalysisAccess c) {
    BeforeAnalysisAccessImpl config = (BeforeAnalysisAccessImpl) c;
    GraalSupport.allocatePhaseStatisticsCache();
    populateMatchRuleRegistry();
    Function<Providers, Backend> backendProvider = GraalSupport.getRuntimeBackendProvider();
    Providers originalProviders = GraalAccess.getOriginalProviders();
    runtimeConfigBuilder = new SubstrateRuntimeConfigurationBuilder(RuntimeOptionValues.singleton(), config.getHostVM(), config.getUniverse(), config.getMetaAccess(), originalProviders.getConstantReflection(), backendProvider).build();
    RuntimeConfiguration runtimeConfig = runtimeConfigBuilder.getRuntimeConfig();
    Providers runtimeProviders = runtimeConfig.getProviders();
    WordTypes wordTypes = runtimeConfigBuilder.getWordTypes();
    hostedProviders = new HostedProviders(runtimeProviders.getMetaAccess(), runtimeProviders.getCodeCache(), runtimeProviders.getConstantReflection(), runtimeProviders.getConstantFieldProvider(), runtimeProviders.getForeignCalls(), runtimeProviders.getLowerer(), runtimeProviders.getReplacements(), runtimeProviders.getStampProvider(), runtimeConfig.getSnippetReflection(), wordTypes);
    SubstrateGraalRuntime graalRuntime = new SubstrateGraalRuntime();
    objectReplacer.setGraalRuntime(graalRuntime);
    ImageSingletons.add(GraalRuntime.class, graalRuntime);
    RuntimeSupport.getRuntimeSupport().addShutdownHook(new GraalSupport.GraalShutdownHook());
    FeatureHandler featureHandler = config.getFeatureHandler();
    NativeImageGenerator.registerGraphBuilderPlugins(featureHandler, runtimeConfig, hostedProviders, config.getMetaAccess(), config.getUniverse(), null, null, config.getNativeLibraries(), config.getImageClassLoader(), false, false);
    DebugContext debug = DebugContext.forCurrentThread();
    NativeImageGenerator.registerReplacements(debug, featureHandler, runtimeConfig, runtimeConfig.getProviders(), runtimeConfig.getSnippetReflection(), false);
    featureHandler.forEachGraalFeature(feature -> feature.registerCodeObserver(runtimeConfig));
    Suites suites = NativeImageGenerator.createSuites(featureHandler, runtimeConfig, runtimeConfig.getSnippetReflection(), false);
    LIRSuites lirSuites = NativeImageGenerator.createLIRSuites(featureHandler, runtimeConfig.getProviders(), false);
    GraalSupport.setRuntimeConfig(runtimeConfig, suites, lirSuites);
    NodeClass<?>[] snippetNodeClasses = ((SubstrateReplacements) runtimeProviders.getReplacements()).getSnippetNodeClasses();
    for (NodeClass<?> nodeClass : snippetNodeClasses) {
        config.getMetaAccess().lookupJavaType(nodeClass.getClazz()).registerAsAllocated(null);
    }
    /* Initialize configuration with reasonable default values. */
    graphBuilderConfig = GraphBuilderConfiguration.getDefault(hostedProviders.getGraphBuilderPlugins()).withBytecodeExceptionMode(BytecodeExceptionMode.ExplicitOnly);
    includeCalleePredicate = GraalFeature::defaultIncludeCallee;
    optimisticOpts = OptimisticOptimizations.ALL.remove(OptimisticOptimizations.Optimization.UseLoopLimitChecks);
    methods = new LinkedHashMap<>();
    graphEncoder = new GraphEncoder(ConfigurationValues.getTarget().arch);
    /*
         * Ensure that all snippet methods have their SubstrateMethod object created by the object
         * replacer, to avoid corner cases later when writing the native image.
         */
    for (ResolvedJavaMethod method : ((SubstrateReplacements) runtimeProviders.getReplacements()).getSnippetMethods()) {
        objectReplacer.apply(method);
    }
}
Also used : BeforeAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl) SubstrateGraalRuntime(com.oracle.svm.graal.SubstrateGraalRuntime) GraalSupport(com.oracle.svm.graal.GraalSupport) WordTypes(org.graalvm.compiler.word.WordTypes) DebugContext(org.graalvm.compiler.debug.DebugContext) GraphEncoder(org.graalvm.compiler.nodes.GraphEncoder) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Providers(org.graalvm.compiler.phases.util.Providers) RuntimeConfiguration(com.oracle.svm.core.graal.meta.RuntimeConfiguration) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) NodeClass(org.graalvm.compiler.graph.NodeClass) Backend(org.graalvm.compiler.core.target.Backend) SubstrateReplacements(com.oracle.svm.core.graal.meta.SubstrateReplacements) FeatureHandler(com.oracle.svm.hosted.FeatureHandler) SubstrateRuntimeConfigurationBuilder(com.oracle.svm.graal.meta.SubstrateRuntimeConfigurationBuilder) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 13 with Suites

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

the class AddressLoweringHotSpotSuitesProvider method createSuites.

@Override
public Suites createSuites(OptionValues options) {
    Suites suites = super.createSuites(options);
    ListIterator<BasePhase<? super LowTierContext>> findPhase = suites.getLowTier().findPhase(FixReadsPhase.class);
    if (findPhase == null) {
        findPhase = suites.getLowTier().findPhase(ExpandLogicPhase.class);
    }
    findPhase.add(new AddressLoweringPhase(addressLowering));
    return suites;
}
Also used : LowTierContext(org.graalvm.compiler.phases.tiers.LowTierContext) ExpandLogicPhase(org.graalvm.compiler.phases.common.ExpandLogicPhase) BasePhase(org.graalvm.compiler.phases.BasePhase) AddressLoweringPhase(org.graalvm.compiler.phases.common.AddressLoweringPhase) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 14 with Suites

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

the class GraalCompilerTest method createSuites.

protected Suites createSuites(OptionValues opts) {
    Suites ret = backend.getSuites().getDefaultSuites(opts).copy();
    ListIterator<BasePhase<? super HighTierContext>> iter = ret.getHighTier().findPhase(ConvertDeoptimizeToGuardPhase.class, true);
    if (iter == null) {
        /*
             * in the economy configuration, we don't have the ConvertDeoptimizeToGuard phase, so we
             * just select the first CanonicalizerPhase in HighTier
             */
        iter = ret.getHighTier().findPhase(CanonicalizerPhase.class);
    }
    iter.add(new Phase() {

        @Override
        protected void run(StructuredGraph graph) {
            ComputeLoopFrequenciesClosure.compute(graph);
        }

        @Override
        public float codeSizeIncrease() {
            return NodeSize.IGNORE_SIZE_CONTRACT_FACTOR;
        }

        @Override
        protected CharSequence getName() {
            return "ComputeLoopFrequenciesPhase";
        }
    });
    ret.getHighTier().appendPhase(new Phase() {

        @Override
        protected void run(StructuredGraph graph) {
            assert checkHighTierGraph(graph) : "failed HighTier graph check";
        }

        @Override
        public float codeSizeIncrease() {
            return NodeSize.IGNORE_SIZE_CONTRACT_FACTOR;
        }

        @Override
        protected CharSequence getName() {
            return "CheckGraphPhase";
        }
    });
    ret.getMidTier().appendPhase(new Phase() {

        @Override
        protected void run(StructuredGraph graph) {
            assert checkMidTierGraph(graph) : "failed MidTier graph check";
        }

        @Override
        public float codeSizeIncrease() {
            return NodeSize.IGNORE_SIZE_CONTRACT_FACTOR;
        }

        @Override
        protected CharSequence getName() {
            return "CheckGraphPhase";
        }
    });
    ret.getLowTier().appendPhase(new Phase() {

        @Override
        protected void run(StructuredGraph graph) {
            assert checkLowTierGraph(graph) : "failed LowTier graph check";
        }

        @Override
        public float codeSizeIncrease() {
            return NodeSize.IGNORE_SIZE_CONTRACT_FACTOR;
        }

        @Override
        protected CharSequence getName() {
            return "CheckGraphPhase";
        }
    });
    return ret;
}
Also used : BasePhase(org.graalvm.compiler.phases.BasePhase) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) Phase(org.graalvm.compiler.phases.Phase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ConvertDeoptimizeToGuardPhase(org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) BasePhase(org.graalvm.compiler.phases.BasePhase) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 15 with Suites

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

the class EnumSwitchTest method createSuites.

@Override
protected Suites createSuites(OptionValues options) {
    Suites ret = super.createSuites(options);
    ret.getHighTier().prependPhase(new Phase() {

        @Override
        protected void run(StructuredGraph graph) {
            /* Array load from the enum switch map. */
            assertTrue(graph.getNodes().filter(LoadIndexedNode.class).count() == 1);
            /* The actual switch. */
            assertTrue(graph.getNodes().filter(IntegerSwitchNode.class).count() == 1);
        }

        @Override
        protected CharSequence getName() {
            return "CheckGraphPhase";
        }
    });
    ret.getHighTier().findPhase(RemoveValueProxyPhase.class).add(new Phase() {

        @Override
        protected void run(StructuredGraph graph) {
            /* Re-writing of the switch cases eliminates the array load. */
            assertTrue(graph.getNodes().filter(LoadIndexedNode.class).count() == 0);
            /* The switch is still there. */
            assertTrue(graph.getNodes().filter(IntegerSwitchNode.class).count() == 1);
        }

        @Override
        protected CharSequence getName() {
            return "CheckGraphPhase";
        }
    });
    return ret;
}
Also used : Phase(org.graalvm.compiler.phases.Phase) RemoveValueProxyPhase(org.graalvm.compiler.phases.common.RemoveValueProxyPhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) RemoveValueProxyPhase(org.graalvm.compiler.phases.common.RemoveValueProxyPhase) 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