Search in sources :

Example 1 with Replacements

use of org.graalvm.compiler.nodes.spi.Replacements in project graal by oracle.

the class ObjectCloneNode method getLoweredSnippetGraph.

@Override
@SuppressWarnings("try")
protected StructuredGraph getLoweredSnippetGraph(LoweringTool tool) {
    ResolvedJavaType type = StampTool.typeOrNull(getObject());
    if (type != null) {
        if (type.isArray()) {
            Method method = ObjectCloneSnippets.arrayCloneMethods.get(type.getComponentType().getJavaKind());
            if (method != null) {
                final ResolvedJavaMethod snippetMethod = tool.getMetaAccess().lookupJavaMethod(method);
                final Replacements replacements = tool.getReplacements();
                StructuredGraph snippetGraph = null;
                DebugContext debug = getDebug();
                try (DebugContext.Scope s = debug.scope("ArrayCloneSnippet", snippetMethod)) {
                    snippetGraph = replacements.getSnippet(snippetMethod, null, graph().trackNodeSourcePosition(), this.getNodeSourcePosition());
                } catch (Throwable e) {
                    throw debug.handle(e);
                }
                assert snippetGraph != null : "ObjectCloneSnippets should be installed";
                assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
                return lowerReplacement((StructuredGraph) snippetGraph.copy(getDebug()), tool);
            }
            assert false : "unhandled array type " + type.getComponentType().getJavaKind();
        } else {
            Assumptions assumptions = graph().getAssumptions();
            type = getConcreteType(getObject().stamp(NodeView.DEFAULT));
            if (type != null) {
                StructuredGraph newGraph = new StructuredGraph.Builder(graph().getOptions(), graph().getDebug(), AllowAssumptions.ifNonNull(assumptions)).build();
                ParameterNode param = newGraph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(getObject().stamp(NodeView.DEFAULT))));
                NewInstanceNode newInstance = newGraph.add(new NewInstanceNode(type, true));
                newGraph.addAfterFixed(newGraph.start(), newInstance);
                ReturnNode returnNode = newGraph.add(new ReturnNode(newInstance));
                newGraph.addAfterFixed(newInstance, returnNode);
                for (ResolvedJavaField field : type.getInstanceFields(true)) {
                    LoadFieldNode load = newGraph.add(LoadFieldNode.create(newGraph.getAssumptions(), param, field));
                    newGraph.addBeforeFixed(returnNode, load);
                    newGraph.addBeforeFixed(returnNode, newGraph.add(new StoreFieldNode(newInstance, field, load)));
                }
                assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
                return lowerReplacement(newGraph, tool);
            }
        }
    }
    assert getConcreteType(stamp(NodeView.DEFAULT)) == null;
    return null;
}
Also used : StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Replacements(org.graalvm.compiler.nodes.spi.Replacements) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) DebugContext(org.graalvm.compiler.debug.DebugContext) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) Assumptions(jdk.vm.ci.meta.Assumptions) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with Replacements

use of org.graalvm.compiler.nodes.spi.Replacements in project graal by oracle.

the class HotSpotGraalCompiler method getIntrinsicGraph.

/**
 * Gets a graph produced from the intrinsic for a given method that can be compiled and
 * installed for the method.
 *
 * @param method
 * @param compilationId
 * @param options
 * @param debug
 * @return an intrinsic graph that can be compiled and installed for {@code method} or null
 */
@SuppressWarnings("try")
public StructuredGraph getIntrinsicGraph(ResolvedJavaMethod method, HotSpotProviders providers, CompilationIdentifier compilationId, OptionValues options, DebugContext debug) {
    Replacements replacements = providers.getReplacements();
    Bytecode subst = replacements.getSubstitutionBytecode(method);
    if (subst != null) {
        ResolvedJavaMethod substMethod = subst.getMethod();
        assert !substMethod.equals(method);
        StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(substMethod).compilationId(compilationId).build();
        try (DebugContext.Scope scope = debug.scope("GetIntrinsicGraph", graph)) {
            Plugins plugins = new Plugins(providers.getGraphBuilderPlugins());
            GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
            IntrinsicContext initialReplacementContext = new IntrinsicContext(method, substMethod, subst.getOrigin(), ROOT_COMPILATION);
            new GraphBuilderPhase.Instance(providers.getMetaAccess(), providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialReplacementContext).apply(graph);
            assert !graph.isFrozen();
            return graph;
        } catch (Throwable e) {
            debug.handle(e);
        }
    }
    return null;
}
Also used : Replacements(org.graalvm.compiler.nodes.spi.Replacements) IntrinsicContext(org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Bytecode(org.graalvm.compiler.bytecode.Bytecode) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 3 with Replacements

use of org.graalvm.compiler.nodes.spi.Replacements in project graal by oracle.

the class SharedRuntimeConfigurationBuilder method build.

public SharedRuntimeConfigurationBuilder build() {
    wordTypes = new WordTypes(metaAccess, FrameAccess.getWordKind());
    Providers p = createProviders(null, null, null, null, null, null, null, null);
    StampProvider stampProvider = createStampProvider(p);
    p = createProviders(null, null, null, null, null, null, stampProvider, null);
    ConstantReflectionProvider constantReflection = createConstantReflectionProvider(p);
    ConstantFieldProvider constantFieldProvider = createConstantFieldProvider(p);
    createProviders(null, constantReflection, constantFieldProvider, null, null, null, stampProvider, null);
    SnippetReflectionProvider snippetReflection = createSnippetReflectionProvider();
    createProviders(null, constantReflection, constantFieldProvider, null, null, null, stampProvider, snippetReflection);
    ForeignCallsProvider foreignCalls = createForeignCallsProvider();
    p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, null, null, stampProvider, snippetReflection);
    LoweringProvider lowerer = createLoweringProvider(p);
    p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, lowerer, null, stampProvider, snippetReflection);
    Replacements replacements = createReplacements(p, snippetReflection);
    p = createProviders(null, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider, snippetReflection);
    EnumMap<ConfigKind, Backend> backends = new EnumMap<>(ConfigKind.class);
    for (ConfigKind config : ConfigKind.values()) {
        RegisterConfig registerConfig = new SubstrateAMD64RegisterConfig(config, metaAccess, ConfigurationValues.getTarget());
        CodeCacheProvider codeCacheProvider = createCodeCacheProvider(registerConfig);
        Providers newProviders = createProviders(codeCacheProvider, constantReflection, constantFieldProvider, foreignCalls, lowerer, replacements, stampProvider, snippetReflection);
        backends.put(config, GraalConfiguration.instance().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) SubstrateStampProvider(com.oracle.svm.core.graal.meta.SubstrateStampProvider) StampProvider(org.graalvm.compiler.nodes.spi.StampProvider) RegisterConfig(jdk.vm.ci.code.RegisterConfig) SubstrateAMD64RegisterConfig(com.oracle.svm.core.graal.code.amd64.SubstrateAMD64RegisterConfig) Replacements(org.graalvm.compiler.nodes.spi.Replacements) WordTypes(org.graalvm.compiler.word.WordTypes) SubstrateAMD64RegisterConfig(com.oracle.svm.core.graal.code.amd64.SubstrateAMD64RegisterConfig) LoweringProvider(org.graalvm.compiler.nodes.spi.LoweringProvider) SubstrateLoweringProvider(com.oracle.svm.core.graal.meta.SubstrateLoweringProvider) ConfigKind(com.oracle.svm.core.graal.code.amd64.SubstrateAMD64RegisterConfig.ConfigKind) Providers(org.graalvm.compiler.phases.util.Providers) SubstrateCodeCacheProvider(com.oracle.svm.core.graal.meta.SubstrateCodeCacheProvider) CodeCacheProvider(jdk.vm.ci.code.CodeCacheProvider) RuntimeConfiguration(com.oracle.svm.core.graal.meta.RuntimeConfiguration) SubstrateSnippetReflectionProvider(com.oracle.svm.core.graal.meta.SubstrateSnippetReflectionProvider) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) Backend(org.graalvm.compiler.core.target.Backend) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) EnumMap(java.util.EnumMap) ConstantFieldProvider(org.graalvm.compiler.core.common.spi.ConstantFieldProvider)

Aggregations

Replacements (org.graalvm.compiler.nodes.spi.Replacements)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 SubstrateAMD64RegisterConfig (com.oracle.svm.core.graal.code.amd64.SubstrateAMD64RegisterConfig)1 ConfigKind (com.oracle.svm.core.graal.code.amd64.SubstrateAMD64RegisterConfig.ConfigKind)1 RuntimeConfiguration (com.oracle.svm.core.graal.meta.RuntimeConfiguration)1 SubstrateCodeCacheProvider (com.oracle.svm.core.graal.meta.SubstrateCodeCacheProvider)1 SubstrateForeignCallsProvider (com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider)1 SubstrateLoweringProvider (com.oracle.svm.core.graal.meta.SubstrateLoweringProvider)1 SubstrateSnippetReflectionProvider (com.oracle.svm.core.graal.meta.SubstrateSnippetReflectionProvider)1 SubstrateStampProvider (com.oracle.svm.core.graal.meta.SubstrateStampProvider)1 Method (java.lang.reflect.Method)1 EnumMap (java.util.EnumMap)1 CodeCacheProvider (jdk.vm.ci.code.CodeCacheProvider)1 RegisterConfig (jdk.vm.ci.code.RegisterConfig)1 Assumptions (jdk.vm.ci.meta.Assumptions)1 ConstantReflectionProvider (jdk.vm.ci.meta.ConstantReflectionProvider)1 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1