package org.graalvm.compiler.replacements.nodes.arithmetic;
import org.graalvm.compiler.core.common.type.IntegerStamp;
import org.graalvm.compiler.core.common.type.Stamp;
import org.graalvm.compiler.graph.NodeClass;
import org.graalvm.compiler.graph.spi.SimplifierTool;
import org.graalvm.compiler.nodeinfo.NodeInfo;
import org.graalvm.compiler.nodes.AbstractBeginNode;
import org.graalvm.compiler.nodes.NodeView;
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.calc.AddNode;
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
import jdk.vm.ci.meta.Value;
@NodeInfo
public final class IntegerAddExactSplitNode extends IntegerExactArithmeticSplitNode {
public static final NodeClass<IntegerAddExactSplitNode> TYPE = NodeClass.create(IntegerAddExactSplitNode.class);
public IntegerAddExactSplitNode(Stamp stamp, ValueNode x, ValueNode y, AbstractBeginNode next, AbstractBeginNode overflowSuccessor) {
super(TYPE, stamp, x, y, next, overflowSuccessor);
}
@Override
protected Value generateArithmetic(NodeLIRBuilderTool gen) {
return gen.getLIRGeneratorTool().getArithmetic().emitAdd(gen.operand(getX()), gen.operand(getY()), true);
}
@Override
public void simplify(SimplifierTool tool) {
NodeView view = NodeView.from(tool);
if (!IntegerStamp.addCanOverflow((IntegerStamp) x.stamp(view), (IntegerStamp) y.stamp(view))) {
tool.deleteBranch(overflowSuccessor);
tool.addToWorkList(next);
AddNode replacement = graph().unique(new AddNode(x, y));
graph().replaceSplitWithFloating(this, replacement, next);
tool.addToWorkList(replacement);
}
}
}