Search in sources :

Example 1 with ConstantBindingParameterPlugin

use of org.graalvm.compiler.replacements.ConstantBindingParameterPlugin in project graal by oracle.

the class SnippetStub method getGraph.

@Override
@SuppressWarnings("try")
protected StructuredGraph getGraph(DebugContext debug, CompilationIdentifier compilationId) {
    Plugins defaultPlugins = providers.getGraphBuilderPlugins();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    SnippetReflectionProvider snippetReflection = providers.getSnippetReflection();
    Plugins plugins = new Plugins(defaultPlugins);
    plugins.prependParameterPlugin(new ConstantBindingParameterPlugin(makeConstArgs(), metaAccess, snippetReflection));
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
    // Stubs cannot have optimistic assumptions since they have
    // to be valid for the entire run of the VM.
    final StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).compilationId(compilationId).build();
    try (DebugContext.Scope outer = debug.scope("SnippetStub", graph)) {
        graph.disableUnsafeAccessTracking();
        IntrinsicContext initialIntrinsicContext = new IntrinsicContext(method, method, getReplacementsBytecodeProvider(), INLINE_AFTER_PARSING);
        GraphBuilderPhase.Instance instance = new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialIntrinsicContext);
        instance.apply(graph);
        for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
            int index = param.index();
            if (method.getParameterAnnotation(NonNullParameter.class, index) != null) {
                param.setStamp(param.stamp(NodeView.DEFAULT).join(StampFactory.objectNonNull()));
            }
        }
        new RemoveValueProxyPhase().apply(graph);
        graph.setGuardsStage(GuardsStage.FLOATING_GUARDS);
        CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
        PhaseContext context = new PhaseContext(providers);
        canonicalizer.apply(graph, context);
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    return graph;
}
Also used : RemoveValueProxyPhase(org.graalvm.compiler.phases.common.RemoveValueProxyPhase) IntrinsicContext(org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) ConstantBindingParameterPlugin(org.graalvm.compiler.replacements.ConstantBindingParameterPlugin) NonNullParameter(org.graalvm.compiler.api.replacements.Snippet.NonNullParameter) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 2 with ConstantBindingParameterPlugin

use of org.graalvm.compiler.replacements.ConstantBindingParameterPlugin in project graal by oracle.

the class SubstrateReplacements method getSnippet.

@Override
public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry, Object[] args, boolean trackNodeSourcePosition, NodeSourcePosition replaceePosition) {
    Integer startOffset = snippetStartOffsets.get(method);
    if (startOffset == null) {
        throw VMError.shouldNotReachHere("snippet not found: " + method.format("%H.%n(%p)"));
    }
    ParameterPlugin parameterPlugin = null;
    if (args != null) {
        parameterPlugin = new ConstantBindingParameterPlugin(args, providers.getMetaAccess(), snippetReflection);
    }
    EncodedGraph encodedGraph = new EncodedGraph(snippetEncoding, startOffset, snippetObjects, snippetNodeClasses, null, null, null, false, trackNodeSourcePosition);
    try (DebugContext debug = openDebugContext("SVMSnippet_", method)) {
        StructuredGraph result = new StructuredGraph.Builder(options, debug).method(method).trackNodeSourcePosition(trackNodeSourcePosition).build();
        PEGraphDecoder graphDecoder = new PEGraphDecoder(ConfigurationValues.getTarget().arch, result, providers.getMetaAccess(), providers.getConstantReflection(), providers.getConstantFieldProvider(), providers.getStampProvider(), null, snippetInvocationPlugins, new InlineInvokePlugin[0], parameterPlugin, null, null, null) {

            @Override
            protected EncodedGraph lookupEncodedGraph(ResolvedJavaMethod lookupMethod, ResolvedJavaMethod originalMethod, BytecodeProvider intrinsicBytecodeProvider, boolean track) {
                if (lookupMethod.equals(method)) {
                    assert !track || encodedGraph.trackNodeSourcePosition();
                    return encodedGraph;
                } else {
                    throw VMError.shouldNotReachHere(method.format("%H.%n(%p)"));
                }
            }
        };
        graphDecoder.decode(method, trackNodeSourcePosition);
        assert result.verify();
        return result;
    }
}
Also used : ConstantBindingParameterPlugin(org.graalvm.compiler.replacements.ConstantBindingParameterPlugin) ParameterPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph) PEGraphDecoder(org.graalvm.compiler.replacements.PEGraphDecoder) BytecodeProvider(org.graalvm.compiler.bytecode.BytecodeProvider) DebugContext(org.graalvm.compiler.debug.DebugContext) ConstantBindingParameterPlugin(org.graalvm.compiler.replacements.ConstantBindingParameterPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 3 with ConstantBindingParameterPlugin

use of org.graalvm.compiler.replacements.ConstantBindingParameterPlugin in project graal by oracle.

the class StringIndexOfConstantTest method editGraphBuilderConfiguration.

@Override
protected GraphBuilderConfiguration editGraphBuilderConfiguration(GraphBuilderConfiguration conf) {
    if (constantArgs != null) {
        ConstantBindingParameterPlugin constantBinding = new ConstantBindingParameterPlugin(constantArgs, this.getMetaAccess(), this.getSnippetReflection());
        conf.getPlugins().appendParameterPlugin(constantBinding);
    }
    return super.editGraphBuilderConfiguration(conf);
}
Also used : ConstantBindingParameterPlugin(org.graalvm.compiler.replacements.ConstantBindingParameterPlugin)

Aggregations

ConstantBindingParameterPlugin (org.graalvm.compiler.replacements.ConstantBindingParameterPlugin)3 DebugContext (org.graalvm.compiler.debug.DebugContext)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 NonNullParameter (org.graalvm.compiler.api.replacements.Snippet.NonNullParameter)1 SnippetReflectionProvider (org.graalvm.compiler.api.replacements.SnippetReflectionProvider)1 BytecodeProvider (org.graalvm.compiler.bytecode.BytecodeProvider)1 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)1 EncodedGraph (org.graalvm.compiler.nodes.EncodedGraph)1 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)1 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)1 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)1 IntrinsicContext (org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext)1 ParameterPlugin (org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin)1 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)1 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)1 RemoveValueProxyPhase (org.graalvm.compiler.phases.common.RemoveValueProxyPhase)1 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)1 PEGraphDecoder (org.graalvm.compiler.replacements.PEGraphDecoder)1