Search in sources :

Example 41 with PhiNode

use of org.graalvm.compiler.nodes.PhiNode 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

PhiNode (org.graalvm.compiler.nodes.PhiNode)41 ValueNode (org.graalvm.compiler.nodes.ValueNode)31 Node (org.graalvm.compiler.graph.Node)22 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)21 FixedNode (org.graalvm.compiler.nodes.FixedNode)21 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)19 ValuePhiNode (org.graalvm.compiler.nodes.ValuePhiNode)18 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)17 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)17 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)15 EndNode (org.graalvm.compiler.nodes.EndNode)15 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)15 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)14 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)13 FrameState (org.graalvm.compiler.nodes.FrameState)10 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)10 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)10 MergeNode (org.graalvm.compiler.nodes.MergeNode)9 PiNode (org.graalvm.compiler.nodes.PiNode)9 BeginNode (org.graalvm.compiler.nodes.BeginNode)7