Search in sources :

Example 6 with IfNode

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

the class BytecodeParser method emitExplicitBoundsCheck.

protected void emitExplicitBoundsCheck(ValueNode index, ValueNode length) {
    AbstractBeginNode trueSucc = graph.add(new BeginNode());
    BytecodeExceptionNode exception = graph.add(new BytecodeExceptionNode(metaAccess, ArrayIndexOutOfBoundsException.class, index));
    append(new IfNode(genUnique(IntegerBelowNode.create(constantReflection, metaAccess, options, null, index, length, NodeView.DEFAULT)), trueSucc, exception, FAST_PATH_PROBABILITY));
    lastInstr = trueSucc;
    exception.setStateAfter(createFrameState(bci(), exception));
    exception.setNext(handleException(exception, bci(), false));
}
Also used : BeginNode(org.graalvm.compiler.nodes.BeginNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) KillingBeginNode(org.graalvm.compiler.nodes.KillingBeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) BytecodeExceptionNode(org.graalvm.compiler.nodes.extended.BytecodeExceptionNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 7 with IfNode

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

the class BytecodeParser method handleUnresolvedInstanceOf.

/**
 * @param type the unresolved type of the type check
 * @param object the object value whose type is being checked against {@code type}
 */
protected void handleUnresolvedInstanceOf(JavaType type, ValueNode object) {
    assert !graphBuilderConfig.unresolvedIsError();
    AbstractBeginNode successor = graph.add(new BeginNode());
    DeoptimizeNode deopt = graph.add(new DeoptimizeNode(InvalidateRecompile, Unresolved));
    deopt.updateNodeSourcePosition(() -> createBytecodePosition());
    append(new IfNode(graph.addOrUniqueWithInputs(IsNullNode.create(object)), successor, deopt, 1));
    lastInstr = successor;
    frameState.push(JavaKind.Int, appendConstant(JavaConstant.INT_0));
}
Also used : BeginNode(org.graalvm.compiler.nodes.BeginNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) KillingBeginNode(org.graalvm.compiler.nodes.KillingBeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 8 with IfNode

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

the class BytecodeParser method emitExplicitNullCheck.

protected ValueNode emitExplicitNullCheck(ValueNode receiver) {
    if (StampTool.isPointerNonNull(receiver.stamp(NodeView.DEFAULT))) {
        return receiver;
    }
    BytecodeExceptionNode exception = graph.add(new BytecodeExceptionNode(metaAccess, NullPointerException.class));
    AbstractBeginNode falseSucc = graph.add(new BeginNode());
    ValueNode nonNullReceiver = graph.addOrUniqueWithInputs(PiNode.create(receiver, objectNonNull(), falseSucc));
    append(new IfNode(graph.addOrUniqueWithInputs(IsNullNode.create(receiver)), exception, falseSucc, SLOW_PATH_PROBABILITY));
    lastInstr = falseSucc;
    exception.setStateAfter(createFrameState(bci(), exception));
    exception.setNext(handleException(exception, bci(), false));
    EXPLICIT_EXCEPTIONS.increment(debug);
    return nonNullReceiver;
}
Also used : BeginNode(org.graalvm.compiler.nodes.BeginNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) KillingBeginNode(org.graalvm.compiler.nodes.KillingBeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) BytecodeExceptionNode(org.graalvm.compiler.nodes.extended.BytecodeExceptionNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 9 with IfNode

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

the class LoopTransformations method updateMainLoopLimit.

private static void updateMainLoopLimit(IfNode preLimit, InductionVariable preIv, LoopFragmentWhole mainLoop) {
    // Update the main loops limit test to be different than the post loop
    StructuredGraph graph = preLimit.graph();
    IfNode mainLimit = mainLoop.getDuplicatedNode(preLimit);
    LogicNode ifTest = mainLimit.condition();
    CompareNode compareNode = (CompareNode) ifTest;
    ValueNode prePhi = preIv.valueNode();
    ValueNode mainPhi = mainLoop.getDuplicatedNode(prePhi);
    ValueNode preStride = preIv.strideNode();
    ValueNode mainStride;
    if (preStride instanceof ConstantNode) {
        mainStride = preStride;
    } else {
        mainStride = mainLoop.getDuplicatedNode(preStride);
    }
    // Fetch the bounds to pose lowering the range by one
    ValueNode ub = null;
    if (compareNode.getX() == mainPhi) {
        ub = compareNode.getY();
    } else if (compareNode.getY() == mainPhi) {
        ub = compareNode.getX();
    } else {
        throw GraalError.shouldNotReachHere();
    }
    // Preloop always performs at least one iteration, so remove that from the main loop.
    ValueNode newLimit = sub(graph, ub, mainStride);
    // Re-wire the condition with the new limit
    compareNode.replaceFirstInput(ub, newLimit);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) IfNode(org.graalvm.compiler.nodes.IfNode)

Example 10 with IfNode

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

the class LoopTransformations method insertPrePostLoops.

// This function splits candidate loops into pre, main and post loops,
// dividing the iteration space to facilitate the majority of iterations
// being executed in a main loop, which will have RCE implemented upon it.
// The initial loop form is constrained to single entry/exit, but can have
// flow. The translation looks like:
// 
// @formatter:off
// 
// (Simple Loop entry)                   (Pre Loop Entry)
// |                                  |
// (LoopBeginNode)                    (LoopBeginNode)
// |                                  |
// (Loop Control Test)<------   ==>  (Loop control Test)<------
// /               \       \         /               \       \
// (Loop Exit)      (Loop Body) |    (Loop Exit)      (Loop Body) |
// |                |       |        |                |       |
// (continue code)     (Loop End)  |  if (M < length)*   (Loop End)  |
// \       /       /      \           \      /
// ----->        /       |            ----->
// /  if ( ... )*
// /     /       \
// /     /         \
// /     /           \
// |     /     (Main Loop Entry)
// |    |             |
// |    |      (LoopBeginNode)
// |    |             |
// |    |     (Loop Control Test)<------
// |    |      /               \        \
// |    |  (Loop Exit)      (Loop Body) |
// \   \      |                |       |
// \   \     |            (Loop End)  |
// \   \    |                \       /
// \   \   |                 ------>
// \   \  |
// (Main Loop Merge)*
// |
// (Post Loop Entry)
// |
// (LoopBeginNode)
// |
// (Loop Control Test)<-----
// /               \       \
// (Loop Exit)     (Loop Body) |
// |               |       |
// (continue code)    (Loop End)  |
// \      /
// ----->
// 
// Key: "*" = optional.
// @formatter:on
// 
// The value "M" is the maximal value of the loop trip for the original
// loop. The value of "length" is applicable to the number of arrays found
// in the loop but is reduced if some or all of the arrays are known to be
// the same length as "M". The maximum number of tests can be equal to the
// number of arrays in the loop, where multiple instances of an array are
// subsumed into a single test for that arrays length.
// 
// If the optional main loop entry tests are absent, the Pre Loop exit
// connects to the Main loops entry and there is no merge hanging off the
// main loops exit to converge flow from said tests. All split use data
// flow is mitigated through phi(s) in the main merge if present and
// passed through the main and post loop phi(s) from the originating pre
// loop with final phi(s) and data flow patched to the "continue code".
// The pre loop is constrained to one iteration for now and will likely
// be updated to produce vector alignment if applicable.
public static LoopBeginNode insertPrePostLoops(LoopEx loop) {
    StructuredGraph graph = loop.loopBegin().graph();
    graph.getDebug().log("LoopTransformations.insertPrePostLoops %s", loop);
    LoopFragmentWhole preLoop = loop.whole();
    CountedLoopInfo preCounted = loop.counted();
    IfNode preLimit = preCounted.getLimitTest();
    assert preLimit != null;
    LoopBeginNode preLoopBegin = loop.loopBegin();
    InductionVariable preIv = preCounted.getCounter();
    LoopExitNode preLoopExitNode = preLoopBegin.getSingleLoopExit();
    FixedNode continuationNode = preLoopExitNode.next();
    // Each duplication is inserted after the original, ergo create the post loop first
    LoopFragmentWhole mainLoop = preLoop.duplicate();
    LoopFragmentWhole postLoop = preLoop.duplicate();
    preLoopBegin.incrementSplits();
    preLoopBegin.incrementSplits();
    preLoopBegin.setPreLoop();
    graph.getDebug().dump(DebugContext.VERBOSE_LEVEL, graph, "After duplication");
    LoopBeginNode mainLoopBegin = mainLoop.getDuplicatedNode(preLoopBegin);
    mainLoopBegin.setMainLoop();
    LoopBeginNode postLoopBegin = postLoop.getDuplicatedNode(preLoopBegin);
    postLoopBegin.setPostLoop();
    EndNode postEndNode = getBlockEndAfterLoopExit(postLoopBegin);
    AbstractMergeNode postMergeNode = postEndNode.merge();
    LoopExitNode postLoopExitNode = postLoopBegin.getSingleLoopExit();
    // Update the main loop phi initialization to carry from the pre loop
    for (PhiNode prePhiNode : preLoopBegin.phis()) {
        PhiNode mainPhiNode = mainLoop.getDuplicatedNode(prePhiNode);
        mainPhiNode.setValueAt(0, prePhiNode);
    }
    EndNode mainEndNode = getBlockEndAfterLoopExit(mainLoopBegin);
    AbstractMergeNode mainMergeNode = mainEndNode.merge();
    AbstractEndNode postEntryNode = postLoopBegin.forwardEnd();
    // In the case of no Bounds tests, we just flow right into the main loop
    AbstractBeginNode mainLandingNode = BeginNode.begin(postEntryNode);
    LoopExitNode mainLoopExitNode = mainLoopBegin.getSingleLoopExit();
    mainLoopExitNode.setNext(mainLandingNode);
    preLoopExitNode.setNext(mainLoopBegin.forwardEnd());
    // Add and update any phi edges as per merge usage as needed and update usages
    processPreLoopPhis(loop, mainLoop, postLoop);
    continuationNode.predecessor().clearSuccessors();
    postLoopExitNode.setNext(continuationNode);
    cleanupMerge(postMergeNode, postLoopExitNode);
    cleanupMerge(mainMergeNode, mainLandingNode);
    // Change the preLoop to execute one iteration for now
    updateMainLoopLimit(preLimit, preIv, mainLoop);
    updatePreLoopLimit(preLimit, preIv, preCounted);
    preLoopBegin.setLoopFrequency(1);
    mainLoopBegin.setLoopFrequency(Math.max(0.0, mainLoopBegin.loopFrequency() - 2));
    postLoopBegin.setLoopFrequency(Math.max(0.0, postLoopBegin.loopFrequency() - 1));
    // The pre and post loops don't require safepoints at all
    for (SafepointNode safepoint : preLoop.nodes().filter(SafepointNode.class)) {
        graph.removeFixed(safepoint);
    }
    for (SafepointNode safepoint : postLoop.nodes().filter(SafepointNode.class)) {
        graph.removeFixed(safepoint);
    }
    graph.getDebug().dump(DebugContext.DETAILED_LEVEL, graph, "InsertPrePostLoops %s", loop);
    return mainLoopBegin;
}
Also used : LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) SafepointNode(org.graalvm.compiler.nodes.SafepointNode) CountedLoopInfo(org.graalvm.compiler.loop.CountedLoopInfo) IfNode(org.graalvm.compiler.nodes.IfNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) LoopFragmentWhole(org.graalvm.compiler.loop.LoopFragmentWhole) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) EndNode(org.graalvm.compiler.nodes.EndNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) InductionVariable(org.graalvm.compiler.loop.InductionVariable)

Aggregations

IfNode (org.graalvm.compiler.nodes.IfNode)27 ValueNode (org.graalvm.compiler.nodes.ValueNode)15 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)14 BeginNode (org.graalvm.compiler.nodes.BeginNode)10 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)10 LogicNode (org.graalvm.compiler.nodes.LogicNode)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)8 FixedNode (org.graalvm.compiler.nodes.FixedNode)8 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)7 CompareNode (org.graalvm.compiler.nodes.calc.CompareNode)7 Node (org.graalvm.compiler.graph.Node)6 EndNode (org.graalvm.compiler.nodes.EndNode)6 KillingBeginNode (org.graalvm.compiler.nodes.KillingBeginNode)6 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)5 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)5 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)5 MergeNode (org.graalvm.compiler.nodes.MergeNode)5 Value (jdk.vm.ci.meta.Value)4 Condition (org.graalvm.compiler.core.common.calc.Condition)4