Search in sources :

Example 1 with CGlobalDataLoadAddressNode

use of com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode in project graal by oracle.

the class CFunctionCallStubMethod method buildGraph.

@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
    NativeLibraries nativeLibraries = CEntryPointCallStubSupport.singleton().getNativeLibraries();
    CFunction annotation = method.getAnnotation(CFunction.class);
    boolean needsTransition = annotation.transition() != Transition.NO_TRANSITION;
    if (purpose == Purpose.PREPARE_RUNTIME_COMPILATION && needsTransition) {
        /*
             * C function calls that need a transition cannot be runtime compiled (and cannot be
             * inlined during runtime compilation). Deoptimization could be required while we are
             * blocked in native code, which means the deoptimization stub would need to do the
             * native-to-Java transition.
             */
        ImageSingletons.lookup(CFunctionFeature.class).warnRuntimeCompilationReachableCFunctionWithTransition(this);
        return null;
    }
    boolean deoptimizationTarget = method instanceof SharedMethod && ((SharedMethod) method).isDeoptTarget();
    HostedGraphKit kit = new HostedGraphKit(debug, providers, method);
    FrameStateBuilder state = kit.getFrameState();
    ValueNode callAddress = kit.unique(new CGlobalDataLoadAddressNode(linkage));
    List<ValueNode> arguments = kit.loadArguments(method.toParameterTypes());
    Signature signature = adaptSignatureAndConvertArguments(method, providers, nativeLibraries, kit, method.getSignature(), arguments);
    state.clearLocals();
    ValueNode returnValue = kit.createCFunctionCall(callAddress, method, arguments, signature, needsTransition, deoptimizationTarget);
    returnValue = adaptReturnValue(method, providers, nativeLibraries, kit, returnValue);
    kit.createReturn(returnValue, signature.getReturnKind());
    assert kit.getGraph().verify();
    return kit.getGraph();
}
Also used : HostedGraphKit(com.oracle.svm.hosted.phases.HostedGraphKit) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) Signature(jdk.vm.ci.meta.Signature) ValueNode(org.graalvm.compiler.nodes.ValueNode) CFunction(org.graalvm.nativeimage.c.function.CFunction) SharedMethod(com.oracle.svm.core.meta.SharedMethod) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) CGlobalDataLoadAddressNode(com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode)

Example 2 with CGlobalDataLoadAddressNode

use of com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode 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)

Aggregations

CGlobalDataLoadAddressNode (com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode)2 CGlobalDataImpl (com.oracle.svm.core.c.CGlobalDataImpl)1 CGlobalDataInfo (com.oracle.svm.core.graal.code.CGlobalDataInfo)1 SharedMethod (com.oracle.svm.core.meta.SharedMethod)1 NativeLibraries (com.oracle.svm.hosted.c.NativeLibraries)1 HostedGraphKit (com.oracle.svm.hosted.phases.HostedGraphKit)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 Signature (jdk.vm.ci.meta.Signature)1 FrameStateBuilder (org.graalvm.compiler.java.FrameStateBuilder)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)1 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)1 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)1 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)1 CFunction (org.graalvm.nativeimage.c.function.CFunction)1