Search in sources :

Example 16 with ForeignCallNode

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

the class DefaultJavaLoweringProvider method lowerUnaryMath.

private void lowerUnaryMath(UnaryMathIntrinsicNode math, LoweringTool tool) {
    if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
        return;
    }
    ResolvedJavaMethod method = math.graph().method();
    if (method != null) {
        if (method.getAnnotation(Snippet.class) != null) {
            /*
                 * In the context of the snippet use the LIR lowering instead of the Node lowering.
                 */
            return;
        }
        if (method.getName().equalsIgnoreCase(math.getOperation().name()) && tool.getMetaAccess().lookupJavaType(Math.class).equals(method.getDeclaringClass())) {
            /*
                 * A root compilation of the intrinsic method should emit the full assembly
                 * implementation.
                 */
            return;
        }
    }
    ForeignCallDescriptor foreignCall = toForeignCall(math.getOperation());
    if (foreignCall != null) {
        StructuredGraph graph = math.graph();
        ForeignCallNode call = math.graph().add(new ForeignCallNode(foreignCalls, foreignCall, math.getValue()));
        graph.addAfterFixed(tool.lastFixedNode(), call);
        math.replaceAtUsages(call);
    }
}
Also used : ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) ForeignCallDescriptor(org.graalvm.compiler.core.common.spi.ForeignCallDescriptor) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Snippet(org.graalvm.compiler.api.replacements.Snippet) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 17 with ForeignCallNode

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

the class InvokeNode method intrinsify.

@Override
public void intrinsify(Node node) {
    assert !(node instanceof ValueNode) || node.isAllowedUsageType(InputType.Value) == isAllowedUsageType(InputType.Value) : "replacing " + this + " with " + node;
    CallTargetNode call = callTarget;
    FrameState currentStateAfter = stateAfter();
    if (node instanceof StateSplit) {
        StateSplit stateSplit = (StateSplit) node;
        stateSplit.setStateAfter(currentStateAfter);
    }
    if (node instanceof ForeignCallNode) {
        ForeignCallNode foreign = (ForeignCallNode) node;
        foreign.setBci(bci());
    }
    if (node instanceof FixedWithNextNode) {
        graph().replaceFixedWithFixed(this, (FixedWithNextNode) node);
    } else if (node instanceof ControlSinkNode) {
        this.replaceAtPredecessor(node);
        this.replaceAtUsages(null);
        GraphUtil.killCFG(this);
        return;
    } else {
        graph().replaceFixed(this, node);
    }
    GraphUtil.killWithUnusedFloatingInputs(call);
    if (currentStateAfter.hasNoUsages()) {
        GraphUtil.killWithUnusedFloatingInputs(currentStateAfter);
    }
}
Also used : ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode)

Example 18 with ForeignCallNode

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

the class InliningUtil method handleAfterBciFrameState.

private static FrameState handleAfterBciFrameState(FrameState frameState, Invoke invoke, boolean alwaysDuplicateStateAfter) {
    FrameState stateAtReturn = invoke.stateAfter();
    JavaKind invokeReturnKind = invoke.asNode().getStackKind();
    FrameState stateAfterReturn = stateAtReturn;
    if (frameState.getCode() == null) {
        // that was parsed for post-parse intrinsification
        for (Node usage : frameState.usages()) {
            if (usage instanceof ForeignCallNode) {
                // A foreign call inside an intrinsic needs to have
                // the BCI of the invoke being intrinsified
                ForeignCallNode foreign = (ForeignCallNode) usage;
                foreign.setBci(invoke.bci());
            }
        }
    }
    // value (top of stack)
    assert !frameState.rethrowException() : frameState;
    if (frameState.stackSize() > 0 && (alwaysDuplicateStateAfter || stateAfterReturn.stackAt(0) != frameState.stackAt(0))) {
        // A non-void return value.
        stateAfterReturn = stateAtReturn.duplicateModified(invokeReturnKind, invokeReturnKind, frameState.stackAt(0));
    } else {
        // A void return value.
        stateAfterReturn = stateAtReturn.duplicate();
    }
    assert stateAfterReturn.bci != BytecodeFrame.UNKNOWN_BCI;
    // Return value does no longer need to be limited by the monitor exit.
    for (MonitorExitNode n : frameState.usages().filter(MonitorExitNode.class)) {
        n.clearEscapedReturnValue();
    }
    frameState.replaceAndDelete(stateAfterReturn);
    return stateAfterReturn;
}
Also used : ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) PiNode(org.graalvm.compiler.nodes.PiNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) KillingBeginNode(org.graalvm.compiler.nodes.KillingBeginNode) StartNode(org.graalvm.compiler.nodes.StartNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) FrameState(org.graalvm.compiler.nodes.FrameState) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

ForeignCallNode (org.graalvm.compiler.nodes.extended.ForeignCallNode)18 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)7 ValueNode (org.graalvm.compiler.nodes.ValueNode)7 ForeignCallDescriptor (org.graalvm.compiler.core.common.spi.ForeignCallDescriptor)5 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)5 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)4 Node (org.graalvm.compiler.graph.Node)3 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)3 StartNode (org.graalvm.compiler.nodes.StartNode)3 Snippet (org.graalvm.compiler.api.replacements.Snippet)2 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)2 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)2 BeginNode (org.graalvm.compiler.nodes.BeginNode)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 EndNode (org.graalvm.compiler.nodes.EndNode)2 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)2 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)2 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)2