Search in sources :

Example 26 with ReturnNode

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

the class CEntryPointCallStubMethod method inlinePrologueAndEpilogue.

private static void inlinePrologueAndEpilogue(SubstrateGraphKit kit, InvokeNode prologueInvoke, InvokeNode epilogueInvoke, JavaKind returnKind) {
    assert (prologueInvoke != null) == (epilogueInvoke != null);
    if (prologueInvoke != null) {
        kit.inline(prologueInvoke);
        NodeIterable<CEntryPointPrologueBailoutNode> bailoutNodes = kit.getGraph().getNodes().filter(CEntryPointPrologueBailoutNode.class);
        for (CEntryPointPrologueBailoutNode node : bailoutNodes) {
            ValueNode result = node.getResult();
            switch(returnKind) {
                case Float:
                    assert result.getStackKind().isNumericFloat();
                    result = kit.unique(new FloatConvertNode(FloatConvert.D2F, result));
                    break;
                case Byte:
                case Char:
                case Short:
                case Int:
                    assert result.getStackKind().isNumericInteger();
                    result = kit.unique(new NarrowNode(result, returnKind.getBitCount()));
                    break;
                default:
                    // no conversion necessary
                    break;
            }
            ReturnNode returnNode = kit.add(new ReturnNode(result));
            node.replaceAndDelete(returnNode);
        }
        if (epilogueInvoke.isAlive()) {
            kit.inline(epilogueInvoke);
        }
    }
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CEntryPointPrologueBailoutNode(com.oracle.svm.core.graal.nodes.CEntryPointPrologueBailoutNode) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode)

Example 27 with ReturnNode

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

the class ProbabilityDirectiveTest method returnValue.

private static int returnValue(AbstractBeginNode b) {
    ControlFlowAnchorNode anchor = (ControlFlowAnchorNode) b.next();
    ReturnNode returnNode = (ReturnNode) anchor.next();
    return returnNode.result().asJavaConstant().asInt();
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) ControlFlowAnchorNode(org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode)

Example 28 with ReturnNode

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

the class BytecodeParser method genReturn.

protected void genReturn(ValueNode returnVal, JavaKind returnKind) {
    if (parsingIntrinsic() && returnVal != null) {
        if (returnVal instanceof StateSplit) {
            StateSplit stateSplit = (StateSplit) returnVal;
            FrameState stateAfter = stateSplit.stateAfter();
            if (stateSplit.hasSideEffect()) {
                assert stateSplit != null;
                if (stateAfter.bci == BytecodeFrame.AFTER_BCI) {
                    assert stateAfter.usages().count() == 1;
                    assert stateAfter.usages().first() == stateSplit;
                    stateAfter.replaceAtUsages(graph.add(new FrameState(BytecodeFrame.AFTER_BCI, returnVal)));
                    GraphUtil.killWithUnusedFloatingInputs(stateAfter);
                } else {
                    /*
                         * This must be the return value from within a partial intrinsification.
                         */
                    assert !BytecodeFrame.isPlaceholderBci(stateAfter.bci);
                }
            } else {
                assert stateAfter == null;
            }
        }
    }
    ValueNode realReturnVal = processReturnValue(returnVal, returnKind);
    frameState.setRethrowException(false);
    frameState.clearStack();
    beforeReturn(realReturnVal, returnKind);
    if (parent == null) {
        append(new ReturnNode(realReturnVal));
    } else {
        if (returnDataList == null) {
            returnDataList = new ArrayList<>();
        }
        returnDataList.add(new ReturnToCallerData(realReturnVal, lastInstr));
        lastInstr = null;
    }
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameState(org.graalvm.compiler.nodes.FrameState) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Example 29 with ReturnNode

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

the class MethodTypeFlow method computeReturnedParamter.

private ParameterNode computeReturnedParamter() {
    if (graphRef == null) {
        // Some methods, e.g., native ones, don't have a graph.
        return null;
    }
    ParameterNode retParam = null;
    for (ParameterNode param : graphRef.getNodes(ParameterNode.TYPE)) {
        if (param.stamp(NodeView.DEFAULT) instanceof ObjectStamp) {
            boolean returnsParameter = true;
            NodeIterable<ReturnNode> retIterable = graphRef.getNodes(ReturnNode.TYPE);
            returnsParameter &= retIterable.count() > 0;
            for (ReturnNode ret : retIterable) {
                returnsParameter &= ret.result() == param;
            }
            if (returnsParameter) {
                retParam = param;
            }
        }
    }
    return retParam;
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp)

Example 30 with ReturnNode

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

the class MethodSafepointInsertionPhase method run.

@Override
protected void run(StructuredGraph graph) {
    if (graph.method().getAnnotation(Uninterruptible.class) != null) {
        /*
             * If a method is annotated with {@link Uninterruptible}, then I do not want a test for
             * a safepoint at the return.
             */
        return;
    }
    if (graph.method().getAnnotation(CFunction.class) != null) {
        /*
             * If a method transfers from Java to C, then the return transition (if any) contains
             * the safepoint test and one is not needed at the return of the transferring method.
             */
        return;
    }
    if (((SharedMethod) graph.method()).isEntryPoint()) {
        /*
             * If a method is transferring from C to Java, then no safepoint test is needed at the
             * return of the transferring method.
             */
        return;
    }
    for (ReturnNode returnNode : graph.getNodes(ReturnNode.TYPE)) {
        SafepointNode safepointNode = graph.add(new SafepointNode());
        graph.addBeforeFixed(returnNode, safepointNode);
    }
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) SafepointNode(org.graalvm.compiler.nodes.SafepointNode) CFunction(org.graalvm.nativeimage.c.function.CFunction) SharedMethod(com.oracle.svm.core.meta.SharedMethod)

Aggregations

ReturnNode (org.graalvm.compiler.nodes.ReturnNode)40 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)22 ValueNode (org.graalvm.compiler.nodes.ValueNode)12 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)11 DebugContext (org.graalvm.compiler.debug.DebugContext)10 Node (org.graalvm.compiler.graph.Node)10 FixedNode (org.graalvm.compiler.nodes.FixedNode)10 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)8 Test (org.junit.Test)8 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)7 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)7 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)7 FrameState (org.graalvm.compiler.nodes.FrameState)7 MergeNode (org.graalvm.compiler.nodes.MergeNode)7 StartNode (org.graalvm.compiler.nodes.StartNode)7 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 PhiNode (org.graalvm.compiler.nodes.PhiNode)6 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)5 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)4 BeginNode (org.graalvm.compiler.nodes.BeginNode)4