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());
}
Aggregations