Search in sources :

Example 21 with ValuePhiNode

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

the class CFGPrinter method scheduleInputs.

private void scheduleInputs(Node node, Block nodeBlock) {
    if (node instanceof ValuePhiNode) {
        PhiNode phi = (PhiNode) node;
        Block phiBlock = latestScheduling.get(phi.merge());
        assert phiBlock != null;
        for (Block pred : phiBlock.getPredecessors()) {
            schedule(phi.valueAt((AbstractEndNode) pred.getEndNode()), pred);
        }
    } else {
        for (Node input : node.inputs()) {
            schedule(input, nodeBlock);
        }
    }
}
Also used : ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) 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) Block(org.graalvm.compiler.nodes.cfg.Block)

Example 22 with ValuePhiNode

use of org.graalvm.compiler.nodes.ValuePhiNode 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 23 with ValuePhiNode

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

the class UseTrappingNullChecksPhase method tryUseTrappingNullCheck.

private static void tryUseTrappingNullCheck(MetaAccessProvider metaAccessProvider, DynamicDeoptimizeNode deopt, long implicitNullCheckLimit) {
    Node predecessor = deopt.predecessor();
    if (predecessor instanceof AbstractMergeNode) {
        AbstractMergeNode merge = (AbstractMergeNode) predecessor;
        // Process each predecessor at the merge, unpacking the reasons and speculations as
        // needed.
        ValueNode reason = deopt.getActionAndReason();
        ValuePhiNode reasonPhi = null;
        List<ValueNode> reasons = null;
        int expectedPhis = 0;
        if (reason instanceof ValuePhiNode) {
            reasonPhi = (ValuePhiNode) reason;
            if (reasonPhi.merge() != merge) {
                return;
            }
            reasons = reasonPhi.values().snapshot();
            expectedPhis++;
        } else if (!reason.isConstant()) {
            return;
        }
        ValueNode speculation = deopt.getSpeculation();
        ValuePhiNode speculationPhi = null;
        List<ValueNode> speculations = null;
        if (speculation instanceof ValuePhiNode) {
            speculationPhi = (ValuePhiNode) speculation;
            if (speculationPhi.merge() != merge) {
                return;
            }
            speculations = speculationPhi.values().snapshot();
            expectedPhis++;
        }
        if (merge.phis().count() != expectedPhis) {
            return;
        }
        int index = 0;
        for (AbstractEndNode end : merge.cfgPredecessors().snapshot()) {
            ValueNode thisReason = reasons != null ? reasons.get(index) : reason;
            ValueNode thisSpeculation = speculations != null ? speculations.get(index++) : speculation;
            if (!thisReason.isConstant() || !thisSpeculation.isConstant() || !thisSpeculation.asConstant().equals(JavaConstant.NULL_POINTER)) {
                continue;
            }
            DeoptimizationReason deoptimizationReason = metaAccessProvider.decodeDeoptReason(thisReason.asJavaConstant());
            tryUseTrappingNullCheck(deopt, end.predecessor(), deoptimizationReason, null, implicitNullCheckLimit);
        }
    }
}
Also used : ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) DynamicDeoptimizeNode(org.graalvm.compiler.nodes.DynamicDeoptimizeNode) FixedAccessNode(org.graalvm.compiler.nodes.memory.FixedAccessNode) DeoptimizingFixedWithNextNode(org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) CompressionNode(org.graalvm.compiler.nodes.CompressionNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) AbstractDeoptimizeNode(org.graalvm.compiler.nodes.AbstractDeoptimizeNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) NullCheckNode(org.graalvm.compiler.nodes.extended.NullCheckNode) Node(org.graalvm.compiler.graph.Node) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason)

Example 24 with ValuePhiNode

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

the class ValueMergeUtil method mergeValueProducers.

public static <T> ValueNode mergeValueProducers(AbstractMergeNode merge, List<? extends T> valueProducers, Function<T, FixedWithNextNode> lastInstrFunction, Function<T, ValueNode> valueFunction) {
    ValueNode singleResult = null;
    PhiNode phiResult = null;
    for (T valueProducer : valueProducers) {
        ValueNode result = valueFunction.apply(valueProducer);
        if (result != null) {
            if (phiResult == null && (singleResult == null || singleResult == result)) {
                /* Only one result value, so no need yet for a phi node. */
                singleResult = result;
            } else if (phiResult == null) {
                /* Found a second result value, so create phi node. */
                phiResult = merge.graph().addWithoutUnique(new ValuePhiNode(result.stamp(NodeView.DEFAULT).unrestricted(), merge));
                for (int i = 0; i < merge.forwardEndCount(); i++) {
                    phiResult.addInput(singleResult);
                }
                phiResult.addInput(result);
            } else {
                /* Multiple return values, just add to existing phi node. */
                phiResult.addInput(result);
            }
        }
        // create and wire up a new EndNode
        EndNode endNode = merge.graph().add(new EndNode());
        merge.addForwardEnd(endNode);
        if (lastInstrFunction == null) {
            assert valueProducer instanceof ReturnNode || valueProducer instanceof UnwindNode;
            ((ControlSinkNode) valueProducer).replaceAndDelete(endNode);
        } else {
            FixedWithNextNode lastInstr = lastInstrFunction.apply(valueProducer);
            lastInstr.setNext(endNode);
        }
    }
    if (phiResult != null) {
        assert phiResult.verify();
        phiResult.inferStamp();
        return phiResult;
    } else {
        return singleResult;
    }
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) EndNode(org.graalvm.compiler.nodes.EndNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode)

Aggregations

ValuePhiNode (org.graalvm.compiler.nodes.ValuePhiNode)24 ValueNode (org.graalvm.compiler.nodes.ValueNode)18 PhiNode (org.graalvm.compiler.nodes.PhiNode)12 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)11 Node (org.graalvm.compiler.graph.Node)9 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)8 FixedNode (org.graalvm.compiler.nodes.FixedNode)8 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)7 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)6 LogicNode (org.graalvm.compiler.nodes.LogicNode)6 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)5 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)5 EndNode (org.graalvm.compiler.nodes.EndNode)5 JavaKind (jdk.vm.ci.meta.JavaKind)4 IfNode (org.graalvm.compiler.nodes.IfNode)4 ArrayList (java.util.ArrayList)3 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)3 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)3 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)3 MergeNode (org.graalvm.compiler.nodes.MergeNode)3