Search in sources :

Example 1 with NodeStateAssignment

use of org.graalvm.compiler.phases.common.SnippetFrameStateAssignment.NodeStateAssignment in project graal by oracle.

the class PlaceholderLogicNode method assignNecessaryFrameStates.

private void assignNecessaryFrameStates(ValueNode replacee, UnmodifiableEconomicMap<Node, Node> duplicates, FixedNode replaceeGraphCFGPredecessor) {
    FrameState stateAfter = null;
    if (replacee instanceof StateSplit && ((StateSplit) replacee).hasSideEffect()) {
        stateAfter = ((StateSplit) replacee).stateAfter();
        GraalError.guarantee(stateAfter != null, "Statesplit with side-effect %s needs a framestate", replacee);
    } else {
        /*
             * We dont have a state split as a replacee, thus we take the prev state as the state
             * after for the node in the snippet.
             */
        stateAfter = GraphUtil.findLastFrameState(replaceeGraphCFGPredecessor);
    }
    final ExceptionObjectNode exceptionObject;
    if (replacee instanceof WithExceptionNode) {
        WithExceptionNode withExceptionNode = (WithExceptionNode) replacee;
        if (withExceptionNode.exceptionEdge() instanceof ExceptionObjectNode) {
            exceptionObject = (ExceptionObjectNode) withExceptionNode.exceptionEdge();
        } else {
            GraalError.guarantee(withExceptionNode.exceptionEdge() instanceof UnreachableBeginNode, "Unexpected exception edge %s", withExceptionNode.exceptionEdge());
            exceptionObject = null;
        }
    } else {
        exceptionObject = null;
    }
    NodeMap<NodeStateAssignment> assignedStateMappings = frameStateAssignment.getStateMapping();
    MapCursor<Node, NodeStateAssignment> stateAssignments = assignedStateMappings.getEntries();
    while (stateAssignments.advance()) {
        Node nodeRequiringState = stateAssignments.getKey();
        if (nodeRequiringState instanceof DeoptBciSupplier) {
            if (replacee instanceof DeoptBciSupplier) {
                ((DeoptBciSupplier) duplicates.get(nodeRequiringState)).setBci(((DeoptBciSupplier) replacee).bci());
            }
        }
        NodeStateAssignment assignment = stateAssignments.getValue();
        switch(assignment) {
            case AFTER_BCI:
                setReplaceeGraphStateAfter(nodeRequiringState, replacee, duplicates, stateAfter);
                break;
            case AFTER_EXCEPTION_BCI:
                if (nodeRequiringState instanceof ExceptionObjectNode) {
                    ExceptionObjectNode newExceptionObject = (ExceptionObjectNode) duplicates.get(nodeRequiringState);
                    rewireExceptionFrameState(exceptionObject, newExceptionObject, newExceptionObject);
                } else if (nodeRequiringState instanceof MergeNode) {
                    MergeNode mergeNode = (MergeNode) duplicates.get(nodeRequiringState);
                    rewireExceptionFrameState(exceptionObject, getExceptionValueFromMerge(mergeNode), mergeNode);
                } else {
                    GraalError.shouldNotReachHere("Unexpected exception state node: " + nodeRequiringState);
                }
                break;
            case BEFORE_BCI:
                FrameState stateBeforeSnippet = GraphUtil.findLastFrameState(replaceeGraphCFGPredecessor);
                ((StateSplit) duplicates.get(nodeRequiringState)).setStateAfter(stateBeforeSnippet.duplicate());
                break;
            case INVALID:
                /*
                     * We cannot assign a proper frame state for this snippet's node since there are
                     * effects which cannot be represented by a single state at the node
                     */
                throw GraalError.shouldNotReachHere("Invalid snippet replacing a node before frame state assignment with node " + nodeRequiringState + " for replacee " + replacee);
            default:
                throw GraalError.shouldNotReachHere("Unknown StateAssigment:" + assignment);
        }
        replacee.graph().getDebug().dump(DebugContext.VERY_DETAILED_LEVEL, replacee.graph(), "After duplicating after state for node %s in snippet", duplicates.get(nodeRequiringState));
    }
}
Also used : MergeNode(org.graalvm.compiler.nodes.MergeNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) FallbackInvokeWithExceptionNode(org.graalvm.compiler.replacements.nodes.FallbackInvokeWithExceptionNode) MacroWithExceptionNode(org.graalvm.compiler.replacements.nodes.MacroWithExceptionNode) WithExceptionNode(org.graalvm.compiler.nodes.WithExceptionNode) DeoptBciSupplier(org.graalvm.compiler.nodes.DeoptBciSupplier) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractBoxingNode(org.graalvm.compiler.nodes.extended.AbstractBoxingNode) UnreachableBeginNode(org.graalvm.compiler.nodes.UnreachableBeginNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) FallbackInvokeWithExceptionNode(org.graalvm.compiler.replacements.nodes.FallbackInvokeWithExceptionNode) AbstractNewObjectNode(org.graalvm.compiler.nodes.java.AbstractNewObjectNode) ExplodeLoopNode(org.graalvm.compiler.replacements.nodes.ExplodeLoopNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) LoadSnippetVarargParameterNode(org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) GuardedNode(org.graalvm.compiler.nodes.extended.GuardedNode) MemoryMapControlSinkNode(org.graalvm.compiler.nodes.MemoryMapControlSinkNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) StartNode(org.graalvm.compiler.nodes.StartNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) MacroWithExceptionNode(org.graalvm.compiler.replacements.nodes.MacroWithExceptionNode) MemoryMapNode(org.graalvm.compiler.nodes.memory.MemoryMapNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) WithExceptionNode(org.graalvm.compiler.nodes.WithExceptionNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) UnreachableBeginNode(org.graalvm.compiler.nodes.UnreachableBeginNode) FrameState(org.graalvm.compiler.nodes.FrameState) NodeStateAssignment(org.graalvm.compiler.phases.common.SnippetFrameStateAssignment.NodeStateAssignment) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Aggregations

Node (org.graalvm.compiler.graph.Node)1 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)1 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)1 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)1 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)1 DeoptBciSupplier (org.graalvm.compiler.nodes.DeoptBciSupplier)1 DeoptimizingNode (org.graalvm.compiler.nodes.DeoptimizingNode)1 EndNode (org.graalvm.compiler.nodes.EndNode)1 FixedNode (org.graalvm.compiler.nodes.FixedNode)1 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)1 FrameState (org.graalvm.compiler.nodes.FrameState)1 IfNode (org.graalvm.compiler.nodes.IfNode)1 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)1 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)1 LogicNode (org.graalvm.compiler.nodes.LogicNode)1 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)1 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)1 MemoryMapControlSinkNode (org.graalvm.compiler.nodes.MemoryMapControlSinkNode)1 MergeNode (org.graalvm.compiler.nodes.MergeNode)1 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)1