Search in sources :

Example 16 with InvocationPlugin

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

the class CGlobalDataFeature method registerInvocationPlugins.

@Override
public void registerInvocationPlugins(Providers providers, SnippetReflectionProvider snippetReflection, InvocationPlugins invocationPlugins, boolean hosted) {
    Registration r = new Registration(invocationPlugins, CGlobalData.class);
    r.register1("get", Receiver.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            VMError.guarantee(receiver.get().isConstant(), "Accessed CGlobalData is not a compile-time constant: " + b.getMethod().asStackTraceElement(b.bci()));
            CGlobalDataImpl<?> data = (CGlobalDataImpl<?>) SubstrateObjectConstant.asObject(receiver.get().asConstant());
            CGlobalDataInfo info = CGlobalDataFeature.this.map.get(data);
            b.addPush(targetMethod.getSignature().getReturnKind(), new CGlobalDataLoadAddressNode(info));
            return true;
        }
    });
}
Also used : CGlobalDataImpl(com.oracle.svm.core.c.CGlobalDataImpl) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) CGlobalDataInfo(com.oracle.svm.core.graal.code.CGlobalDataInfo) CGlobalDataLoadAddressNode(com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 17 with InvocationPlugin

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

the class BytecodeParser method tryInvocationPlugin.

@SuppressWarnings("try")
protected boolean tryInvocationPlugin(InvokeKind invokeKind, ValueNode[] args, ResolvedJavaMethod targetMethod, JavaKind resultType, JavaType returnType) {
    InvocationPlugin plugin = graphBuilderConfig.getPlugins().getInvocationPlugins().lookupInvocation(targetMethod);
    if (plugin != null) {
        if (intrinsicContext != null && intrinsicContext.isCallToOriginal(targetMethod)) {
            // method should be called.
            assert !targetMethod.hasBytecodes() : "TODO: when does this happen?";
            return false;
        }
        InvocationPluginReceiver pluginReceiver = invocationPluginReceiver.init(targetMethod, args);
        IntrinsicGuard intrinsicGuard = null;
        if (invokeKind.isIndirect()) {
            intrinsicGuard = guardIntrinsic(args, targetMethod, pluginReceiver);
            if (intrinsicGuard == null) {
                return false;
            } else if (intrinsicGuard.nonIntrinsicBranch == null) {
                assert lastInstr instanceof FixedGuardNode;
            }
        }
        InvocationPluginAssertions assertions = Assertions.assertionsEnabled() ? new InvocationPluginAssertions(plugin, args, targetMethod, resultType) : null;
        try (DebugCloseable context = openNodeContext(targetMethod)) {
            if (plugin.execute(this, targetMethod, pluginReceiver, args)) {
                afterInvocationPluginExecution(true, assertions, intrinsicGuard, invokeKind, args, targetMethod, resultType, returnType);
                return true;
            } else {
                afterInvocationPluginExecution(false, assertions, intrinsicGuard, invokeKind, args, targetMethod, resultType, returnType);
            }
        }
    }
    return false;
}
Also used : InvocationPluginReceiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 18 with InvocationPlugin

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

the class SubstrateReplacements method makeInvocationPlugins.

@Platforms(Platform.HOSTED_ONLY.class)
private static InvocationPlugins makeInvocationPlugins(GraphBuilderConfiguration.Plugins plugins, Builder builder, Function<Object, Object> objectReplacer) {
    Map<ResolvedJavaMethod, InvocationPlugin> result = new HashMap<>(builder.delayedInvocationPluginMethods.size());
    for (ResolvedJavaMethod method : builder.delayedInvocationPluginMethods) {
        ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) objectReplacer.apply(method);
        InvocationPlugin plugin = plugins.getInvocationPlugins().lookupInvocation(replacedMethod);
        assert plugin != null : "expected invocation plugin for " + replacedMethod;
        result.put(replacedMethod, plugin);
    }
    return new InvocationPlugins(result, null);
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) HashMap(java.util.HashMap) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Platforms(org.graalvm.nativeimage.Platforms)

Example 19 with InvocationPlugin

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

the class PEGraphDecoder method tryInvocationPlugin.

protected boolean tryInvocationPlugin(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
    if (invocationPlugins == null || invocationPlugins.isEmpty()) {
        return false;
    }
    Invoke invoke = invokeData.invoke;
    ResolvedJavaMethod targetMethod = callTarget.targetMethod();
    InvocationPlugin invocationPlugin = getInvocationPlugin(targetMethod);
    if (invocationPlugin == null) {
        return false;
    }
    ValueNode[] arguments = callTarget.arguments().toArray(new ValueNode[0]);
    FixedWithNextNode invokePredecessor = (FixedWithNextNode) invoke.asNode().predecessor();
    /*
         * Remove invoke from graph so that invocation plugin can append nodes to the predecessor.
         */
    invoke.asNode().replaceAtPredecessor(null);
    PEMethodScope inlineScope = new PEMethodScope(graph, methodScope, loopScope, null, targetMethod, invokeData, methodScope.inliningDepth + 1, loopExplosionPlugin, arguments);
    PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(inlineScope, invokePredecessor);
    InvocationPluginReceiver invocationPluginReceiver = new InvocationPluginReceiver(graphBuilderContext);
    if (invocationPlugin.execute(graphBuilderContext, targetMethod, invocationPluginReceiver.init(targetMethod, arguments), arguments)) {
        if (graphBuilderContext.invokeConsumed) {
        /* Nothing to do. */
        } else if (graphBuilderContext.lastInstr != null) {
            registerNode(loopScope, invokeData.invokeOrderId, graphBuilderContext.pushedNode, true, true);
            invoke.asNode().replaceAtUsages(graphBuilderContext.pushedNode);
            graphBuilderContext.lastInstr.setNext(nodeAfterInvoke(methodScope, loopScope, invokeData, AbstractBeginNode.prevBegin(graphBuilderContext.lastInstr)));
            deleteInvoke(invoke);
        } else {
            assert graphBuilderContext.pushedNode == null : "Why push a node when the invoke does not return anyway?";
            invoke.asNode().replaceAtUsages(null);
            deleteInvoke(invoke);
        }
        return true;
    } else {
        /* Intrinsification failed, restore original state: invoke is in Graph. */
        invokePredecessor.setNext(invoke.asNode());
        return false;
    }
}
Also used : InvocationPluginReceiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 20 with InvocationPlugin

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

the class SPARCGraphBuilderPlugins method registerIntegerLongPlugins.

private static void registerIntegerLongPlugins(InvocationPlugins plugins, Class<?> substituteDeclaringClass, JavaKind kind, BytecodeProvider bytecodeProvider) {
    Class<?> declaringClass = kind.toBoxedJavaClass();
    Class<?> type = kind.toJavaClass();
    Registration r = new Registration(plugins, declaringClass, bytecodeProvider);
    r.registerMethodSubstitution(substituteDeclaringClass, "numberOfLeadingZeros", type);
    r.registerMethodSubstitution(substituteDeclaringClass, "numberOfTrailingZeros", type);
    r.register1("bitCount", type, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.push(JavaKind.Int, b.append(new BitCountNode(value).canonical(null)));
            return true;
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) BitCountNode(org.graalvm.compiler.replacements.nodes.BitCountNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)92 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)89 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)83 ValueNode (org.graalvm.compiler.nodes.ValueNode)74 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)66 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)57 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)13 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)13 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)9 LogicNode (org.graalvm.compiler.nodes.LogicNode)9 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)8 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)7 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 JavaKind (jdk.vm.ci.meta.JavaKind)6 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)6 ResolvedJavaSymbol (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol)6 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)5 GetClassNode (org.graalvm.compiler.nodes.extended.GetClassNode)4 AnalysisArraysCopyOfNode (com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode)3 Stamp (org.graalvm.compiler.core.common.type.Stamp)3