Search in sources :

Example 1 with ParameterPlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin 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 2 with ParameterPlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin in project graal by oracle.

the class PartialEvaluator method doGraphPE.

protected void doGraphPE(CompilableTruffleAST compilable, StructuredGraph graph, HighTierContext tierContext, TruffleInliningPlan inliningDecision) {
    LoopExplosionPlugin loopExplosionPlugin = new PELoopExplosionPlugin();
    ParameterPlugin parameterPlugin = new InterceptReceiverPlugin(compilable);
    ReplacementsImpl replacements = (ReplacementsImpl) providers.getReplacements();
    InlineInvokePlugin[] inlineInvokePlugins;
    InlineInvokePlugin inlineInvokePlugin = new PEInlineInvokePlugin(inliningDecision);
    HistogramInlineInvokePlugin histogramPlugin = null;
    if (TruffleCompilerOptions.getValue(PrintTruffleExpansionHistogram)) {
        histogramPlugin = new HistogramInlineInvokePlugin(graph);
        inlineInvokePlugins = new InlineInvokePlugin[] { replacements, inlineInvokePlugin, histogramPlugin };
    } else {
        inlineInvokePlugins = new InlineInvokePlugin[] { replacements, inlineInvokePlugin };
    }
    SourceLanguagePositionProvider sourceLanguagePosition = new TruffleSourceLanguagePositionProvider(inliningDecision);
    PEGraphDecoder decoder = createGraphDecoder(graph, tierContext, loopExplosionPlugin, decodingInvocationPlugins, inlineInvokePlugins, parameterPlugin, nodePlugins, callInlinedMethod, sourceLanguagePosition);
    decoder.decode(graph.method(), graph.trackNodeSourcePosition());
    if (TruffleCompilerOptions.getValue(PrintTruffleExpansionHistogram)) {
        histogramPlugin.print(compilable);
    }
}
Also used : SourceLanguagePositionProvider(org.graalvm.compiler.graph.SourceLanguagePositionProvider) ParameterPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin) ReplacementsImpl(org.graalvm.compiler.replacements.ReplacementsImpl) LoopExplosionPlugin(org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin) CachingPEGraphDecoder(org.graalvm.compiler.replacements.CachingPEGraphDecoder) PEGraphDecoder(org.graalvm.compiler.replacements.PEGraphDecoder) HistogramInlineInvokePlugin(org.graalvm.compiler.truffle.compiler.debug.HistogramInlineInvokePlugin) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) HistogramInlineInvokePlugin(org.graalvm.compiler.truffle.compiler.debug.HistogramInlineInvokePlugin)

Example 3 with ParameterPlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin in project graal by oracle.

the class FrameStateBuilder method initializeForMethodStart.

public void initializeForMethodStart(Assumptions assumptions, boolean eagerResolve, Plugins plugins) {
    int javaIndex = 0;
    int index = 0;
    ResolvedJavaMethod method = getMethod();
    ResolvedJavaType originalType = method.getDeclaringClass();
    if (!method.isStatic()) {
        // add the receiver
        FloatingNode receiver = null;
        StampPair receiverStamp = null;
        if (plugins != null) {
            receiverStamp = plugins.getOverridingStamp(tool, originalType, true);
        }
        if (receiverStamp == null) {
            receiverStamp = StampFactory.forDeclaredType(assumptions, originalType, true);
        }
        if (plugins != null) {
            for (ParameterPlugin plugin : plugins.getParameterPlugins()) {
                receiver = plugin.interceptParameter(tool, index, receiverStamp);
                if (receiver != null) {
                    break;
                }
            }
        }
        if (receiver == null) {
            receiver = new ParameterNode(javaIndex, receiverStamp);
        }
        locals[javaIndex] = graph.addOrUniqueWithInputs(receiver);
        javaIndex = 1;
        index = 1;
    }
    Signature sig = method.getSignature();
    int max = sig.getParameterCount(false);
    ResolvedJavaType accessingClass = originalType;
    for (int i = 0; i < max; i++) {
        JavaType type = sig.getParameterType(i, accessingClass);
        if (eagerResolve) {
            type = type.resolve(accessingClass);
        }
        JavaKind kind = type.getJavaKind();
        StampPair stamp = null;
        if (plugins != null) {
            stamp = plugins.getOverridingStamp(tool, type, false);
        }
        if (stamp == null) {
            stamp = StampFactory.forDeclaredType(assumptions, type, false);
        }
        FloatingNode param = null;
        if (plugins != null) {
            for (ParameterPlugin plugin : plugins.getParameterPlugins()) {
                param = plugin.interceptParameter(tool, index, stamp);
                if (param != null) {
                    break;
                }
            }
        }
        if (param == null) {
            param = new ParameterNode(index, stamp);
        }
        locals[javaIndex] = graph.addOrUniqueWithInputs(param);
        javaIndex++;
        if (kind.needsTwoSlots()) {
            locals[javaIndex] = TWO_SLOT_MARKER;
            javaIndex++;
        }
        index++;
    }
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ParameterPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) Signature(jdk.vm.ci.meta.Signature) StampPair(org.graalvm.compiler.core.common.type.StampPair) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

ParameterPlugin (org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 PEGraphDecoder (org.graalvm.compiler.replacements.PEGraphDecoder)2 JavaKind (jdk.vm.ci.meta.JavaKind)1 JavaType (jdk.vm.ci.meta.JavaType)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 Signature (jdk.vm.ci.meta.Signature)1 BytecodeProvider (org.graalvm.compiler.bytecode.BytecodeProvider)1 StampPair (org.graalvm.compiler.core.common.type.StampPair)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 SourceLanguagePositionProvider (org.graalvm.compiler.graph.SourceLanguagePositionProvider)1 EncodedGraph (org.graalvm.compiler.nodes.EncodedGraph)1 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1 FloatingNode (org.graalvm.compiler.nodes.calc.FloatingNode)1 InlineInvokePlugin (org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin)1 LoopExplosionPlugin (org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin)1 CachingPEGraphDecoder (org.graalvm.compiler.replacements.CachingPEGraphDecoder)1 ConstantBindingParameterPlugin (org.graalvm.compiler.replacements.ConstantBindingParameterPlugin)1 ReplacementsImpl (org.graalvm.compiler.replacements.ReplacementsImpl)1