Search in sources :

Example 6 with SubstrateBackend

use of com.oracle.svm.core.graal.code.SubstrateBackend in project graal by oracle.

the class LLVMFeature method afterRegistration.

@Override
public void afterRegistration(AfterRegistrationAccess access) {
    ImageSingletons.add(SubstrateBackendFactory.class, new SubstrateBackendFactory() {

        @Override
        public SubstrateBackend newBackend(Providers newProviders) {
            return new SubstrateLLVMBackend(newProviders);
        }
    });
    ImageSingletons.add(SubstrateLoweringProviderFactory.class, SubstrateLLVMLoweringProvider::new);
    ImageSingletons.add(NativeImageCodeCacheFactory.class, new NativeImageCodeCacheFactory() {

        @Override
        public NativeImageCodeCache newCodeCache(CompileQueue compileQueue, NativeImageHeap heap, Platform platform, Path tempDir) {
            return new LLVMNativeImageCodeCache(compileQueue.getCompilations(), heap, platform, tempDir);
        }
    });
    ImageSingletons.add(ExceptionUnwind.class, LLVMExceptionUnwind.createRaiseExceptionHandler());
    ImageSingletons.add(TargetGraphBuilderPlugins.class, new LLVMGraphBuilderPlugins());
    ImageSingletons.add(SubstrateSuitesCreatorProvider.class, new SubstrateSuitesCreatorProvider());
}
Also used : Path(java.nio.file.Path) CompileQueue(com.oracle.svm.hosted.code.CompileQueue) Platform(org.graalvm.nativeimage.Platform) NativeImageHeap(com.oracle.svm.hosted.image.NativeImageHeap) NativeImageCodeCache(com.oracle.svm.hosted.image.NativeImageCodeCache) SubstrateBackendFactory(com.oracle.svm.core.graal.code.SubstrateBackendFactory) Providers(org.graalvm.compiler.phases.util.Providers) SubstrateBackend(com.oracle.svm.core.graal.code.SubstrateBackend) NativeImageCodeCacheFactory(com.oracle.svm.hosted.image.NativeImageCodeCacheFactory) SubstrateLLVMLoweringProvider(com.oracle.svm.core.graal.llvm.lowering.SubstrateLLVMLoweringProvider) SubstrateSuitesCreatorProvider(com.oracle.svm.core.graal.code.SubstrateSuitesCreatorProvider) LLVMGraphBuilderPlugins(com.oracle.svm.core.graal.llvm.replacements.LLVMGraphBuilderPlugins)

Example 7 with SubstrateBackend

use of com.oracle.svm.core.graal.code.SubstrateBackend in project graal by oracle.

the class SharedRuntimeConfigurationBuilder method build.

public SharedRuntimeConfigurationBuilder build() {
    EnumMap<ConfigKind, RegisterConfig> registerConfigs = new EnumMap<>(ConfigKind.class);
    for (ConfigKind config : ConfigKind.values()) {
        registerConfigs.put(config, ImageSingletons.lookup(SubstrateRegisterConfigFactory.class).newRegisterFactory(config, metaAccess, ConfigurationValues.getTarget(), SubstrateOptions.PreserveFramePointer.getValue()));
    }
    wordTypes = new SubstrateWordTypes(metaAccess, FrameAccess.getWordKind());
    Providers p = createProviders(null, null, null, null, null, null, null, null, null, null, null);
    StampProvider stampProvider = createStampProvider(p);
    p = createProviders(null, null, null, null, null, null, stampProvider, null, null, null, null);
    ConstantReflectionProvider constantReflection = createConstantReflectionProvider(p);
    p = createProviders(null, constantReflection, null, null, null, null, stampProvider, null, null, null, null);
    ConstantFieldProvider constantFieldProvider = createConstantFieldProvider(p);
    SnippetReflectionProvider snippetReflection = createSnippetReflectionProvider();
    ForeignCallsProvider foreignCalls = createForeignCallsProvider(registerConfigs.get(ConfigKind.NORMAL));
    p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, null, null, stampProvider, snippetReflection, null, null, null);
    BarrierSet barrierSet = ImageSingletons.lookup(Heap.class).createBarrierSet(metaAccess);
    PlatformConfigurationProvider platformConfig = new SubstratePlatformConfigurationProvider(barrierSet);
    MetaAccessExtensionProvider metaAccessExtensionProvider = new SubstrateMetaAccessExtensionProvider();
    p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, null, null, stampProvider, snippetReflection, platformConfig, metaAccessExtensionProvider, null);
    LoweringProvider lowerer = createLoweringProvider(p);
    p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, lowerer, null, stampProvider, snippetReflection, platformConfig, metaAccessExtensionProvider, null);
    Replacements replacements = createReplacements(p, snippetReflection);
    p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider, snippetReflection, platformConfig, metaAccessExtensionProvider, null);
    LoopsDataProvider loopsDataProvider = originalLoopsDataProvider;
    p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider, snippetReflection, platformConfig, metaAccessExtensionProvider, loopsDataProvider);
    EnumMap<ConfigKind, SubstrateBackend> backends = new EnumMap<>(ConfigKind.class);
    for (ConfigKind config : ConfigKind.values()) {
        CodeCacheProvider codeCacheProvider = createCodeCacheProvider(registerConfigs.get(config));
        Providers newProviders = createProviders(codeCacheProvider, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider, snippetReflection, platformConfig, metaAccessExtensionProvider, loopsDataProvider);
        backends.put(config, GraalConfiguration.runtimeInstance().createBackend(newProviders));
    }
    runtimeConfig = new RuntimeConfiguration(p, snippetReflection, backends, wordTypes);
    return this;
}
Also used : ForeignCallsProvider(org.graalvm.compiler.core.common.spi.ForeignCallsProvider) SubstrateForeignCallsProvider(com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider) SubstratePlatformConfigurationProvider(com.oracle.svm.core.graal.code.SubstratePlatformConfigurationProvider) RegisterConfig(jdk.vm.ci.code.RegisterConfig) SubstrateStampProvider(com.oracle.svm.core.graal.meta.SubstrateStampProvider) StampProvider(org.graalvm.compiler.nodes.spi.StampProvider) Replacements(org.graalvm.compiler.nodes.spi.Replacements) ConfigKind(com.oracle.svm.core.graal.meta.SubstrateRegisterConfig.ConfigKind) SubstrateLoweringProvider(com.oracle.svm.core.graal.meta.SubstrateLoweringProvider) LoweringProvider(org.graalvm.compiler.nodes.spi.LoweringProvider) Providers(org.graalvm.compiler.phases.util.Providers) SubstrateBackend(com.oracle.svm.core.graal.code.SubstrateBackend) CodeCacheProvider(jdk.vm.ci.code.CodeCacheProvider) SubstrateWordTypes(com.oracle.svm.core.graal.word.SubstrateWordTypes) Heap(com.oracle.svm.core.heap.Heap) RuntimeConfiguration(com.oracle.svm.core.graal.meta.RuntimeConfiguration) SubstrateMetaAccessExtensionProvider(com.oracle.svm.core.graal.code.SubstrateMetaAccessExtensionProvider) MetaAccessExtensionProvider(org.graalvm.compiler.core.common.spi.MetaAccessExtensionProvider) BarrierSet(org.graalvm.compiler.nodes.gc.BarrierSet) SubstrateMetaAccessExtensionProvider(com.oracle.svm.core.graal.code.SubstrateMetaAccessExtensionProvider) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) SubstrateSnippetReflectionProvider(com.oracle.svm.core.graal.meta.SubstrateSnippetReflectionProvider) LoopsDataProvider(org.graalvm.compiler.nodes.spi.LoopsDataProvider) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) EnumMap(java.util.EnumMap) ConstantFieldProvider(org.graalvm.compiler.core.common.spi.ConstantFieldProvider) PlatformConfigurationProvider(org.graalvm.compiler.nodes.spi.PlatformConfigurationProvider) SubstratePlatformConfigurationProvider(com.oracle.svm.core.graal.code.SubstratePlatformConfigurationProvider)

Example 8 with SubstrateBackend

use of com.oracle.svm.core.graal.code.SubstrateBackend 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 + "]");
    }
    try {
        SubstrateBackend backend = config.lookupBackend(method);
        StructuredGraph graph = method.compilationInfo.graph;
        VMError.guarantee(graph != null, "The following method is reachable during compilation, but was not seen during Bytecode parsing: " + 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 = backend.newCompilationResult(compilationIdentifier, method.format("%H.%n(%p)"));
            try (Indent indent = debug.logAndIndent("compile %s", method)) {
                GraalCompiler.compileGraph(graph, method, backend.getProviders(), backend, null, getOptimisticOpts(), method.getProfilingInfo(), suites, lirSuites, result, new HostedCompilationResultBuilderFactory(), false);
            }
            method.compilationInfo.numNodesAfterCompilation = graph.getNodeCount();
            if (method.compilationInfo.isDeoptTarget()) {
                assert verifyDeoptTarget(method, result);
            }
            ensureCalleesCompiled(method, reason, result);
            /* 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 : Indent(org.graalvm.compiler.debug.Indent) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) DebugContext(org.graalvm.compiler.debug.DebugContext) CompilationResult(org.graalvm.compiler.code.CompilationResult) SubstrateBackend(com.oracle.svm.core.graal.code.SubstrateBackend) LIRSuites(org.graalvm.compiler.lir.phases.LIRSuites) Suites(org.graalvm.compiler.phases.tiers.Suites)

Example 9 with SubstrateBackend

use of com.oracle.svm.core.graal.code.SubstrateBackend in project graal by oracle.

the class SubstrateAArch64Feature method afterRegistration.

@Override
public void afterRegistration(AfterRegistrationAccess access) {
    ImageSingletons.add(SubstrateRegisterConfigFactory.class, new SubstrateRegisterConfigFactory() {

        @Override
        public RegisterConfig newRegisterFactory(ConfigKind config, MetaAccessProvider metaAccess, TargetDescription target, Boolean preserveFramePointer) {
            return new SubstrateAArch64RegisterConfig(config, metaAccess, target, preserveFramePointer);
        }
    });
    ImageSingletons.add(ReservedRegisters.class, new AArch64ReservedRegisters());
    if (!SubstrateOptions.useLLVMBackend()) {
        AArch64CalleeSavedRegisters.createAndRegister();
        ImageSingletons.add(SubstrateBackendFactory.class, new SubstrateBackendFactory() {

            @Override
            public SubstrateBackend newBackend(Providers newProviders) {
                return new SubstrateAArch64Backend(newProviders);
            }
        });
        ImageSingletons.add(SubstrateLoweringProviderFactory.class, new SubstrateLoweringProviderFactory() {

            @Override
            public DefaultJavaLoweringProvider newLoweringProvider(MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls, PlatformConfigurationProvider platformConfig, MetaAccessExtensionProvider metaAccessExtensionProvider, TargetDescription target) {
                return new SubstrateAArch64LoweringProvider(metaAccess, foreignCalls, platformConfig, metaAccessExtensionProvider, target);
            }
        });
        ImageSingletons.add(TargetGraphBuilderPlugins.class, new AArch64GraphBuilderPlugins());
        ImageSingletons.add(SubstrateSuitesCreatorProvider.class, new SubstrateAArch64SuitesCreatorProvider());
    }
}
Also used : ForeignCallsProvider(org.graalvm.compiler.core.common.spi.ForeignCallsProvider) RegisterConfig(jdk.vm.ci.code.RegisterConfig) TargetDescription(jdk.vm.ci.code.TargetDescription) SubstrateBackendFactory(com.oracle.svm.core.graal.code.SubstrateBackendFactory) ConfigKind(com.oracle.svm.core.graal.meta.SubstrateRegisterConfig.ConfigKind) Providers(org.graalvm.compiler.phases.util.Providers) SubstrateBackend(com.oracle.svm.core.graal.code.SubstrateBackend) MetaAccessExtensionProvider(org.graalvm.compiler.core.common.spi.MetaAccessExtensionProvider) AArch64GraphBuilderPlugins(org.graalvm.compiler.replacements.aarch64.AArch64GraphBuilderPlugins) SubstrateRegisterConfigFactory(com.oracle.svm.core.graal.code.SubstrateRegisterConfigFactory) DefaultJavaLoweringProvider(org.graalvm.compiler.replacements.DefaultJavaLoweringProvider) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) SubstrateLoweringProviderFactory(com.oracle.svm.core.graal.code.SubstrateLoweringProviderFactory) PlatformConfigurationProvider(org.graalvm.compiler.nodes.spi.PlatformConfigurationProvider)

Aggregations

SubstrateBackend (com.oracle.svm.core.graal.code.SubstrateBackend)9 Providers (org.graalvm.compiler.phases.util.Providers)5 LIRSuites (org.graalvm.compiler.lir.phases.LIRSuites)4 Suites (org.graalvm.compiler.phases.tiers.Suites)4 SubstrateBackendFactory (com.oracle.svm.core.graal.code.SubstrateBackendFactory)3 ConfigKind (com.oracle.svm.core.graal.meta.SubstrateRegisterConfig.ConfigKind)3 RegisterConfig (jdk.vm.ci.code.RegisterConfig)3 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)3 ForeignCallsProvider (org.graalvm.compiler.core.common.spi.ForeignCallsProvider)3 MetaAccessExtensionProvider (org.graalvm.compiler.core.common.spi.MetaAccessExtensionProvider)3 PlatformConfigurationProvider (org.graalvm.compiler.nodes.spi.PlatformConfigurationProvider)3 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 SubstrateLoweringProviderFactory (com.oracle.svm.core.graal.code.SubstrateLoweringProviderFactory)2 SubstrateRegisterConfigFactory (com.oracle.svm.core.graal.code.SubstrateRegisterConfigFactory)2 RuntimeConfiguration (com.oracle.svm.core.graal.meta.RuntimeConfiguration)2 SubstrateReplacements (com.oracle.svm.core.graal.meta.SubstrateReplacements)2 SubstrateWordTypes (com.oracle.svm.core.graal.word.SubstrateWordTypes)2 TargetDescription (jdk.vm.ci.code.TargetDescription)2 DefaultJavaLoweringProvider (org.graalvm.compiler.replacements.DefaultJavaLoweringProvider)2 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)1