Search in sources :

Example 1 with GuardedValueNode

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

the class LoopPredicationPhase method replaceGuardNode.

private static void replaceGuardNode(LoopEx loop, GuardNode guard, ValueNode range, StructuredGraph graph, long scaleCon, ValueNode offset) {
    final InductionVariable counter = loop.counted().getLimitCheckedIV();
    ValueNode rangeLong = IntegerConvertNode.convert(range, StampFactory.forInteger(64), graph, NodeView.DEFAULT);
    ValueNode extremumNode = counter.extremumNode(false, StampFactory.forInteger(64));
    final GuardingNode overFlowGuard = loop.counted().createOverFlowGuard();
    assert overFlowGuard != null || loop.counted().counterNeverOverflows();
    if (overFlowGuard != null) {
        extremumNode = graph.unique(new GuardedValueNode(extremumNode, overFlowGuard));
    }
    final ValueNode upperNode = MathUtil.add(graph, MathUtil.mul(graph, extremumNode, ConstantNode.forLong(scaleCon, graph)), IntegerConvertNode.convert(offset, StampFactory.forInteger(64), graph, NodeView.DEFAULT));
    final LogicNode upperCond = IntegerBelowNode.create(upperNode, rangeLong, NodeView.DEFAULT);
    final ValueNode initNode = IntegerConvertNode.convert(loop.counted().getBodyIVStart(), StampFactory.forInteger(64), graph, NodeView.DEFAULT);
    final ValueNode lowerNode = MathUtil.add(graph, MathUtil.mul(graph, initNode, ConstantNode.forLong(scaleCon, graph)), IntegerConvertNode.convert(offset, StampFactory.forInteger(64), graph, NodeView.DEFAULT));
    final LogicNode lowerCond = IntegerBelowNode.create(lowerNode, rangeLong, NodeView.DEFAULT);
    final FrameState state = loop.loopBegin().stateAfter();
    final BytecodePosition pos = new BytecodePosition(null, state.getMethod(), state.bci);
    SpeculationLog.SpeculationReason reason = LOOP_PREDICATION.createSpeculationReason(pos);
    SpeculationLog.Speculation speculation = graph.getSpeculationLog().speculate(reason);
    final AbstractBeginNode anchor = AbstractBeginNode.prevBegin(loop.entryPoint());
    final GuardNode upperGuard = graph.addOrUniqueWithInputs(new GuardNode(upperCond, anchor, guard.getReason(), guard.getAction(), guard.isNegated(), speculation, null));
    final GuardNode lowerGuard = graph.addOrUniqueWithInputs(new GuardNode(lowerCond, anchor, guard.getReason(), guard.getAction(), guard.isNegated(), speculation, null));
    final GuardingNode combinedGuard = MultiGuardNode.combine(lowerGuard, upperGuard);
    guard.replaceAtUsagesAndDelete(combinedGuard.asNode());
}
Also used : SpeculationLog(jdk.vm.ci.meta.SpeculationLog) BytecodePosition(jdk.vm.ci.code.BytecodePosition) GuardedValueNode(org.graalvm.compiler.nodes.GuardedValueNode) GuardedValueNode(org.graalvm.compiler.nodes.GuardedValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) MultiGuardNode(org.graalvm.compiler.nodes.extended.MultiGuardNode) InductionVariable(org.graalvm.compiler.nodes.loop.InductionVariable) LogicNode(org.graalvm.compiler.nodes.LogicNode) FrameState(org.graalvm.compiler.nodes.FrameState) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Aggregations

BytecodePosition (jdk.vm.ci.code.BytecodePosition)1 SpeculationLog (jdk.vm.ci.meta.SpeculationLog)1 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)1 FrameState (org.graalvm.compiler.nodes.FrameState)1 GuardNode (org.graalvm.compiler.nodes.GuardNode)1 GuardedValueNode (org.graalvm.compiler.nodes.GuardedValueNode)1 LogicNode (org.graalvm.compiler.nodes.LogicNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 GuardingNode (org.graalvm.compiler.nodes.extended.GuardingNode)1 MultiGuardNode (org.graalvm.compiler.nodes.extended.MultiGuardNode)1 InductionVariable (org.graalvm.compiler.nodes.loop.InductionVariable)1