Search in sources :

Example 11 with StateSplit

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

the class GraphBuilderContext method addPush.

/**
 * Adds a node with a non-void kind to the graph, pushes it to the stack. If the returned node
 * is a {@link StateSplit} with a null {@linkplain StateSplit#stateAfter() frame state}, the
 * frame state is initialized.
 *
 * @param kind the kind to use when type checking this operation
 * @param value the value to add to the graph and push to the stack
 * @return a node equivalent to {@code value} in the graph
 */
default <T extends ValueNode> T addPush(JavaKind kind, T value) {
    T equivalentValue = value.graph() != null ? value : append(value);
    push(kind, equivalentValue);
    if (equivalentValue instanceof StateSplit) {
        StateSplit stateSplit = (StateSplit) equivalentValue;
        if (stateSplit.stateAfter() == null && stateSplit.hasSideEffect()) {
            setStateAfter(stateSplit);
        }
    }
    return equivalentValue;
}
Also used : StateSplit(org.graalvm.compiler.nodes.StateSplit)

Example 12 with StateSplit

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

the class GraphUtil method removeFixedWithUnusedInputs.

public static void removeFixedWithUnusedInputs(FixedWithNextNode fixed) {
    if (fixed instanceof StateSplit) {
        FrameState stateAfter = ((StateSplit) fixed).stateAfter();
        if (stateAfter != null) {
            ((StateSplit) fixed).setStateAfter(null);
            if (stateAfter.hasNoUsages()) {
                killWithUnusedFloatingInputs(stateAfter);
            }
        }
    }
    unlinkFixedNode(fixed);
    killWithUnusedFloatingInputs(fixed);
}
Also used : FrameState(org.graalvm.compiler.nodes.FrameState) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Example 13 with StateSplit

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

the class SchedulingTest2 method testValueProxyInputs.

@Test
public void testValueProxyInputs() {
    StructuredGraph graph = parseEager("testSnippet", AllowAssumptions.YES);
    DebugContext debug = graph.getDebug();
    ReturnNode returnNode = graph.getNodes(ReturnNode.TYPE).first();
    BeginNode beginNode = graph.add(new BeginNode());
    returnNode.replaceAtPredecessor(beginNode);
    beginNode.setNext(returnNode);
    debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.EARLIEST_WITH_GUARD_ORDER);
    schedulePhase.apply(graph);
    ScheduleResult schedule = graph.getLastSchedule();
    BlockMap<List<Node>> blockToNodesMap = schedule.getBlockToNodesMap();
    NodeMap<Block> nodeToBlock = schedule.getNodeToBlockMap();
    assertDeepEquals(2, schedule.getCFG().getBlocks().length);
    for (BinaryArithmeticNode<?> node : graph.getNodes().filter(BinaryArithmeticNode.class)) {
        if (node instanceof AddNode) {
            assertTrue(node.toString() + " expected: " + nodeToBlock.get(beginNode) + " but was: " + nodeToBlock.get(node), nodeToBlock.get(node) != nodeToBlock.get(beginNode));
        }
    }
    for (FrameState fs : graph.getNodes(FrameState.TYPE)) {
        Block block = nodeToBlock.get(fs);
        assertTrue(fs.toString(), block == schedule.getCFG().getStartBlock());
        for (Node usage : fs.usages()) {
            if (usage instanceof StateSplit && ((StateSplit) usage).stateAfter() == fs) {
                assertTrue(usage.toString(), nodeToBlock.get(usage) == block);
                if (usage != block.getBeginNode()) {
                    List<Node> map = blockToNodesMap.get(block);
                    assertTrue(map.indexOf(fs) + " < " + map.indexOf(usage), map.indexOf(fs) < map.indexOf(usage));
                }
            }
        }
    }
    PhaseContext context = new PhaseContext(getProviders());
    new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
    MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
    new GuardLoweringPhase().apply(graph, midContext);
    FrameStateAssignmentPhase phase = new FrameStateAssignmentPhase();
    phase.apply(graph);
    schedulePhase.apply(graph);
    schedule = graph.getLastSchedule();
    blockToNodesMap = schedule.getBlockToNodesMap();
    nodeToBlock = schedule.getNodeToBlockMap();
    for (FrameState fs : graph.getNodes(FrameState.TYPE)) {
        Block block = nodeToBlock.get(fs);
        assertTrue(fs.toString(), block == schedule.getCFG().getStartBlock());
        for (Node usage : fs.usages()) {
            if ((usage instanceof StateSplit && ((StateSplit) usage).stateAfter() == fs) || (usage instanceof DeoptDuring && ((DeoptDuring) usage).stateDuring() == fs)) {
                assertTrue(usage.toString(), nodeToBlock.get(usage) == block);
                if (usage != block.getBeginNode()) {
                    List<Node> map = blockToNodesMap.get(block);
                    assertTrue(map.indexOf(fs) + " < " + map.indexOf(usage), map.indexOf(fs) < map.indexOf(usage));
                }
            }
        }
    }
}
Also used : FrameStateAssignmentPhase(org.graalvm.compiler.phases.common.FrameStateAssignmentPhase) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) AddNode(org.graalvm.compiler.nodes.calc.AddNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) BinaryArithmeticNode(org.graalvm.compiler.nodes.calc.BinaryArithmeticNode) Node(org.graalvm.compiler.graph.Node) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) FrameState(org.graalvm.compiler.nodes.FrameState) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) BeginNode(org.graalvm.compiler.nodes.BeginNode) DeoptDuring(org.graalvm.compiler.nodes.DeoptimizingNode.DeoptDuring) Block(org.graalvm.compiler.nodes.cfg.Block) List(java.util.List) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) AddNode(org.graalvm.compiler.nodes.calc.AddNode) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) StateSplit(org.graalvm.compiler.nodes.StateSplit) Test(org.junit.Test)

Example 14 with StateSplit

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

the class CFGPrinter method printNode.

private void printNode(Node node, boolean unscheduled) {
    assert !printedNodes.isMarked(node);
    printedNodes.mark(node);
    if (!(node instanceof ValuePhiNode)) {
        for (Node input : node.inputs()) {
            if (!inFixedSchedule(input) && !printedNodes.isMarked(input)) {
                printNode(input, true);
            }
        }
    }
    if (unscheduled) {
        assert lir == null && schedule == null : "unscheduled nodes can only be present before LIR generation";
        out.print("f ").print(HOVER_START).print("u").print(HOVER_SEP).print("unscheduled").print(HOVER_END).println(COLUMN_END);
    } else if (node instanceof FixedWithNextNode) {
        out.print("f ").print(HOVER_START).print("#").print(HOVER_SEP).print("fixed with next").print(HOVER_END).println(COLUMN_END);
    } else if (node instanceof FixedNode) {
        out.print("f ").print(HOVER_START).print("*").print(HOVER_SEP).print("fixed").print(HOVER_END).println(COLUMN_END);
    } else if (node instanceof FloatingNode) {
        out.print("f ").print(HOVER_START).print("~").print(HOVER_SEP).print("floating").print(HOVER_END).println(COLUMN_END);
    }
    out.print("tid ").print(nodeToString(node)).println(COLUMN_END);
    if (nodeLirGenerator != null) {
        Value operand = nodeLirGenerator.hasOperand(node) ? nodeLirGenerator.operand(node) : null;
        if (operand != null) {
            out.print("result ").print(operand.toString()).println(COLUMN_END);
        }
    }
    if (node instanceof StateSplit) {
        StateSplit stateSplit = (StateSplit) node;
        if (stateSplit.stateAfter() != null) {
            String state = stateToString(stateSplit.stateAfter());
            out.print("st ").print(HOVER_START).print("st").print(HOVER_SEP).print(state).print(HOVER_END).println(COLUMN_END);
        }
    }
    Map<Object, Object> props = new TreeMap<>(node.getDebugProperties());
    out.print("d ").print(HOVER_START).print("d").print(HOVER_SEP);
    out.println("=== Debug Properties ===");
    for (Map.Entry<Object, Object> entry : props.entrySet()) {
        out.print(entry.getKey().toString()).print(": ").print(entry.getValue() == null ? "[null]" : entry.getValue().toString()).println();
    }
    out.println("=== Inputs ===");
    printNamedNodes(node, node.inputPositions().iterator(), "", "\n", null);
    out.println("=== Succesors ===");
    printNamedNodes(node, node.successorPositions().iterator(), "", "\n", null);
    out.println("=== Usages ===");
    if (!node.hasNoUsages()) {
        for (Node usage : node.usages()) {
            out.print(nodeToString(usage)).print(" ");
        }
        out.println();
    }
    out.println("=== Predecessor ===");
    out.print(nodeToString(node.predecessor())).print(" ");
    out.print(HOVER_END).println(COLUMN_END);
    out.print("instruction ");
    out.print(HOVER_START).print(node.getNodeClass().shortName()).print(HOVER_SEP).print(node.getClass().getName()).print(HOVER_END).print(" ");
    printNamedNodes(node, node.inputPositions().iterator(), "", "", "#NDF");
    printNamedNodes(node, node.successorPositions().iterator(), "#", "", "#NDF");
    for (Map.Entry<Object, Object> entry : props.entrySet()) {
        String key = entry.getKey().toString();
        if (key.startsWith("data.") && !key.equals("data.stamp")) {
            out.print(key.substring("data.".length())).print(": ").print(entry.getValue() == null ? "[null]" : entry.getValue().toString()).print(" ");
        }
    }
    out.print(COLUMN_END).print(' ').println(COLUMN_END);
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) TreeMap(java.util.TreeMap) Value(jdk.vm.ci.meta.Value) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) Map(java.util.Map) NodeMap(org.graalvm.compiler.graph.NodeMap) NodeBitMap(org.graalvm.compiler.graph.NodeBitMap) TreeMap(java.util.TreeMap) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Example 15 with StateSplit

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

the class InliningUtil method handleMissingAfterExceptionFrameState.

public static FrameState handleMissingAfterExceptionFrameState(FrameState nonReplaceableFrameState, Invoke invoke, EconomicMap<Node, Node> replacements, boolean alwaysDuplicateStateAfter) {
    StructuredGraph graph = nonReplaceableFrameState.graph();
    NodeWorkList workList = graph.createNodeWorkList();
    workList.add(nonReplaceableFrameState);
    for (Node node : workList) {
        FrameState fs = (FrameState) node;
        for (Node usage : fs.usages().snapshot()) {
            if (!usage.isAlive()) {
                continue;
            }
            if (usage instanceof FrameState) {
                workList.add(usage);
            } else {
                StateSplit stateSplit = (StateSplit) usage;
                FixedNode fixedStateSplit = stateSplit.asNode();
                if (fixedStateSplit instanceof AbstractMergeNode) {
                    AbstractMergeNode merge = (AbstractMergeNode) fixedStateSplit;
                    while (merge.isAlive()) {
                        AbstractEndNode end = merge.forwardEnds().first();
                        DeoptimizeNode deoptimizeNode = addDeoptimizeNode(graph, DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler);
                        end.replaceAtPredecessor(deoptimizeNode);
                        GraphUtil.killCFG(end);
                    }
                } else if (fixedStateSplit instanceof ExceptionObjectNode) {
                    // The target invoke does not have an exception edge. This means that the
                    // bytecode parser made the wrong assumption of making an
                    // InvokeWithExceptionNode for the partial intrinsic exit. We therefore
                    // replace the InvokeWithExceptionNode with a normal
                    // InvokeNode -- the deoptimization occurs when the invoke throws.
                    InvokeWithExceptionNode oldInvoke = (InvokeWithExceptionNode) fixedStateSplit.predecessor();
                    FrameState oldFrameState = oldInvoke.stateAfter();
                    InvokeNode newInvoke = oldInvoke.replaceWithInvoke();
                    newInvoke.setStateAfter(oldFrameState.duplicate());
                    if (replacements != null) {
                        replacements.put(oldInvoke, newInvoke);
                    }
                    handleAfterBciFrameState(newInvoke.stateAfter(), invoke, alwaysDuplicateStateAfter);
                } else {
                    FixedNode deoptimizeNode = addDeoptimizeNode(graph, DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler);
                    if (fixedStateSplit instanceof AbstractBeginNode) {
                        deoptimizeNode = BeginNode.begin(deoptimizeNode);
                    }
                    fixedStateSplit.replaceAtPredecessor(deoptimizeNode);
                    GraphUtil.killCFG(fixedStateSplit);
                }
            }
        }
    }
    return nonReplaceableFrameState;
}
Also used : 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) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) FrameState(org.graalvm.compiler.nodes.FrameState) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) NodeWorkList(org.graalvm.compiler.graph.NodeWorkList) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Aggregations

StateSplit (org.graalvm.compiler.nodes.StateSplit)15 Node (org.graalvm.compiler.graph.Node)11 FrameState (org.graalvm.compiler.nodes.FrameState)11 ValueNode (org.graalvm.compiler.nodes.ValueNode)11 FixedNode (org.graalvm.compiler.nodes.FixedNode)10 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)9 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)8 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)7 PhiNode (org.graalvm.compiler.nodes.PhiNode)7 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)6 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)6 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)6 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)6 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)6 EndNode (org.graalvm.compiler.nodes.EndNode)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 ExceptionObjectNode (org.graalvm.compiler.nodes.java.ExceptionObjectNode)5 BeginNode (org.graalvm.compiler.nodes.BeginNode)4 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)4 KillingBeginNode (org.graalvm.compiler.nodes.KillingBeginNode)4