Search in sources :

Example 56 with AbstractMergeNode

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

the class StatelessPostOrderNodeIterator method apply.

public void apply() {
    FixedNode current = start;
    do {
        if (current instanceof LoopBeginNode) {
            loopBegin((LoopBeginNode) current);
            current = ((LoopBeginNode) current).next();
            assert current != null;
        } else if (current instanceof LoopEndNode) {
            loopEnd((LoopEndNode) current);
            assert !visitedEnds.isMarked(current);
            visitedEnds.mark(current);
            current = nodeQueue.pollFirst();
        } else if (current instanceof AbstractMergeNode) {
            merge((AbstractMergeNode) current);
            current = ((AbstractMergeNode) current).next();
            assert current != null;
        } else if (current instanceof FixedWithNextNode) {
            node(current);
            current = ((FixedWithNextNode) current).next();
        } else if (current instanceof EndNode) {
            end((EndNode) current);
            queueMerge((EndNode) current);
            current = nodeQueue.pollFirst();
        } else if (current instanceof ControlSinkNode) {
            node(current);
            current = nodeQueue.pollFirst();
        } else if (current instanceof ControlSplitNode) {
            controlSplit((ControlSplitNode) current);
            for (Node node : current.successors()) {
                nodeQueue.addFirst((AbstractBeginNode) node);
            }
            current = nodeQueue.pollFirst();
        } else {
            assert false : current;
        }
    } while (current != null);
    finished();
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) EndNode(org.graalvm.compiler.nodes.EndNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode)

Example 57 with AbstractMergeNode

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

the class MultiTypeGuardInlineInfo method duplicateInvokeForInlining.

private static Invoke duplicateInvokeForInlining(StructuredGraph graph, Invoke invoke, AbstractMergeNode exceptionMerge, PhiNode exceptionObjectPhi, boolean useForInlining) {
    Invoke result = (Invoke) invoke.asNode().copyWithInputs();
    Node callTarget = result.callTarget().copyWithInputs();
    result.asNode().replaceFirstInput(result.callTarget(), callTarget);
    result.setUseForInlining(useForInlining);
    JavaKind kind = invoke.asNode().getStackKind();
    if (kind != JavaKind.Void) {
        FrameState stateAfter = invoke.stateAfter();
        stateAfter = stateAfter.duplicate(stateAfter.bci);
        stateAfter.replaceFirstInput(invoke.asNode(), result.asNode());
        result.setStateAfter(stateAfter);
    }
    if (invoke instanceof InvokeWithExceptionNode) {
        assert exceptionMerge != null && exceptionObjectPhi != null;
        InvokeWithExceptionNode invokeWithException = (InvokeWithExceptionNode) invoke;
        ExceptionObjectNode exceptionEdge = (ExceptionObjectNode) invokeWithException.exceptionEdge();
        FrameState stateAfterException = exceptionEdge.stateAfter();
        ExceptionObjectNode newExceptionEdge = (ExceptionObjectNode) exceptionEdge.copyWithInputs();
        // set new state (pop old exception object, push new one)
        newExceptionEdge.setStateAfter(stateAfterException.duplicateModified(JavaKind.Object, JavaKind.Object, newExceptionEdge));
        EndNode endNode = graph.add(new EndNode());
        newExceptionEdge.setNext(endNode);
        exceptionMerge.addForwardEnd(endNode);
        exceptionObjectPhi.addInput(newExceptionEdge);
        ((InvokeWithExceptionNode) result).setExceptionEdge(newExceptionEdge);
    }
    return result;
}
Also used : EndNode(org.graalvm.compiler.nodes.EndNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) TypeSwitchNode(org.graalvm.compiler.nodes.java.TypeSwitchNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) FrameState(org.graalvm.compiler.nodes.FrameState) Invoke(org.graalvm.compiler.nodes.Invoke) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 58 with AbstractMergeNode

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

the class FixedNodeProbabilityCache method applyAsDouble.

/**
 * <p>
 * Given a {@link FixedNode} this method finds the most immediate {@link AbstractBeginNode}
 * preceding it that either:
 * <ul>
 * <li>has no predecessor (ie, the begin-node is a merge, in particular a loop-begin, or the
 * start-node)</li>
 * <li>has a control-split predecessor</li>
 * </ul>
 * </p>
 *
 * <p>
 * The thus found {@link AbstractBeginNode} is equi-probable with the {@link FixedNode} it was
 * obtained from. When computed for the first time (afterwards a cache lookup returns it) that
 * probability is computed as follows, again depending on the begin-node's predecessor:
 * <ul>
 * <li>No predecessor. In this case the begin-node is either:</li>
 * <ul>
 * <li>a merge-node, whose probability adds up those of its forward-ends</li>
 * <li>a loop-begin, with probability as above multiplied by the loop-frequency</li>
 * </ul>
 * <li>Control-split predecessor: probability of the branch times that of the control-split</li>
 * </ul>
 * </p>
 *
 * <p>
 * As an exception to all the above, a probability of 1 is assumed for a {@link FixedNode} that
 * appears to be dead-code (ie, lacks a predecessor).
 * </p>
 */
@Override
public double applyAsDouble(FixedNode node) {
    assert node != null;
    computeNodeProbabilityCounter.increment(node.getDebug());
    FixedNode current = findBegin(node);
    if (current == null) {
        // this should only appear for dead code
        return 1D;
    }
    assert current instanceof AbstractBeginNode;
    Double cachedValue = cache.get(current);
    if (cachedValue != null) {
        return cachedValue;
    }
    double probability = 0.0;
    if (current.predecessor() == null) {
        if (current instanceof AbstractMergeNode) {
            probability = handleMerge(current, probability);
        } else {
            assert current instanceof StartNode;
            probability = 1D;
        }
    } else {
        ControlSplitNode split = (ControlSplitNode) current.predecessor();
        probability = multiplyProbabilities(split.probability((AbstractBeginNode) current), applyAsDouble(split));
    }
    assert !Double.isNaN(probability) && !Double.isInfinite(probability) : current + " " + probability;
    cache.put(current, probability);
    return probability;
}
Also used : StartNode(org.graalvm.compiler.nodes.StartNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 59 with AbstractMergeNode

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

the class FixedNodeProbabilityCache method handleMerge.

private double handleMerge(FixedNode current, double probability) {
    double result = probability;
    AbstractMergeNode currentMerge = (AbstractMergeNode) current;
    NodeInputList<EndNode> currentForwardEnds = currentMerge.forwardEnds();
    /*
         * Use simple iteration instead of streams, since the stream infrastructure adds many frames
         * which causes the recursion to overflow the stack earlier than it would otherwise.
         */
    for (AbstractEndNode endNode : currentForwardEnds) {
        result += applyAsDouble(endNode);
    }
    if (current instanceof LoopBeginNode) {
        result = multiplyProbabilities(result, ((LoopBeginNode) current).loopFrequency());
    }
    return result;
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) EndNode(org.graalvm.compiler.nodes.EndNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode)

Aggregations

AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)59 FixedNode (org.graalvm.compiler.nodes.FixedNode)31 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)28 EndNode (org.graalvm.compiler.nodes.EndNode)24 Node (org.graalvm.compiler.graph.Node)22 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)22 ValueNode (org.graalvm.compiler.nodes.ValueNode)22 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)20 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)19 PhiNode (org.graalvm.compiler.nodes.PhiNode)18 MergeNode (org.graalvm.compiler.nodes.MergeNode)16 ValuePhiNode (org.graalvm.compiler.nodes.ValuePhiNode)14 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)13 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)13 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)13 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)12 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)11 ArrayList (java.util.ArrayList)10 FrameState (org.graalvm.compiler.nodes.FrameState)10 IfNode (org.graalvm.compiler.nodes.IfNode)9