Search in sources :

Example 61 with AbstractBeginNode

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

the class MultiTypeGuardInlineInfo method inlineSingleMethod.

private EconomicSet<Node> inlineSingleMethod(StructuredGraph graph, StampProvider stampProvider, ConstantReflectionProvider constantReflection) {
    assert concretes.size() == 1 && inlineableElements.length == 1 && ptypes.size() > 1 && !shouldFallbackToInvoke() && notRecordedTypeProbability == 0;
    AbstractBeginNode calleeEntryNode = graph.add(new BeginNode());
    AbstractBeginNode unknownTypeSux = createUnknownTypeSuccessor(graph);
    AbstractBeginNode[] successors = new AbstractBeginNode[] { calleeEntryNode, unknownTypeSux };
    createDispatchOnTypeBeforeInvoke(graph, successors, false, stampProvider, constantReflection);
    calleeEntryNode.setNext(invoke.asNode());
    return inline(invoke, methodAt(0), inlineableElementAt(0), false);
}
Also used : BeginNode(org.graalvm.compiler.nodes.BeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 62 with AbstractBeginNode

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

the class MultiTypeGuardInlineInfo method devirtualizeWithTypeSwitch.

private void devirtualizeWithTypeSwitch(StructuredGraph graph, InvokeKind kind, ResolvedJavaMethod target, StampProvider stampProvider, ConstantReflectionProvider constantReflection) {
    AbstractBeginNode invocationEntry = graph.add(new BeginNode());
    AbstractBeginNode unknownTypeSux = createUnknownTypeSuccessor(graph);
    AbstractBeginNode[] successors = new AbstractBeginNode[] { invocationEntry, unknownTypeSux };
    createDispatchOnTypeBeforeInvoke(graph, successors, true, stampProvider, constantReflection);
    invocationEntry.setNext(invoke.asNode());
    ValueNode receiver = ((MethodCallTargetNode) invoke.callTarget()).receiver();
    PiNode anchoredReceiver = InliningUtil.createAnchoredReceiver(graph, invocationEntry, target.getDeclaringClass(), receiver, false);
    invoke.callTarget().replaceFirstInput(receiver, anchoredReceiver);
    InliningUtil.replaceInvokeCallTarget(invoke, graph, kind, target);
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) PiNode(org.graalvm.compiler.nodes.PiNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 63 with AbstractBeginNode

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

Aggregations

AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)63 FixedNode (org.graalvm.compiler.nodes.FixedNode)32 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)31 Node (org.graalvm.compiler.graph.Node)24 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)23 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)23 EndNode (org.graalvm.compiler.nodes.EndNode)22 BeginNode (org.graalvm.compiler.nodes.BeginNode)21 ValueNode (org.graalvm.compiler.nodes.ValueNode)20 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)16 IfNode (org.graalvm.compiler.nodes.IfNode)16 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)15 MergeNode (org.graalvm.compiler.nodes.MergeNode)15 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)15 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)14 PhiNode (org.graalvm.compiler.nodes.PhiNode)14 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)13 LogicNode (org.graalvm.compiler.nodes.LogicNode)12 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)11 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)11