< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/arithmetic/IntegerAddExactNode.java

Print this page
rev 56282 : [mq]: graal


  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.replacements.nodes.arithmetic;
  26 
  27 import static org.graalvm.compiler.core.common.type.IntegerStamp.addOverflowsNegatively;
  28 import static org.graalvm.compiler.core.common.type.IntegerStamp.addOverflowsPositively;
  29 import static org.graalvm.compiler.core.common.type.IntegerStamp.carryBits;
  30 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_2;
  31 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_2;
  32 
  33 import org.graalvm.compiler.core.common.type.IntegerStamp;
  34 import org.graalvm.compiler.core.common.type.Stamp;
  35 import org.graalvm.compiler.core.common.type.StampFactory;

  36 import org.graalvm.compiler.graph.NodeClass;
  37 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
  38 import org.graalvm.compiler.nodeinfo.InputType;
  39 import org.graalvm.compiler.nodeinfo.NodeInfo;
  40 import org.graalvm.compiler.nodes.ConstantNode;
  41 import org.graalvm.compiler.nodes.NodeView;
  42 import org.graalvm.compiler.nodes.ValueNode;
  43 import org.graalvm.compiler.nodes.calc.AddNode;
  44 
  45 import jdk.vm.ci.code.CodeUtil;
  46 import jdk.vm.ci.meta.JavaConstant;
  47 import jdk.vm.ci.meta.JavaKind;
  48 import org.graalvm.compiler.nodes.extended.GuardedNode;
  49 import org.graalvm.compiler.nodes.extended.GuardingNode;
  50 
  51 /**
  52  * Node representing an exact integer addition that will throw an {@link ArithmeticException} in
  53  * case the addition would overflow the 32 bit range.
  54  */
  55 @NodeInfo(cycles = CYCLES_2, size = SIZE_2)
  56 public final class IntegerAddExactNode extends AddNode implements GuardedNode, IntegerExactArithmeticNode {
  57     public static final NodeClass<IntegerAddExactNode> TYPE = NodeClass.create(IntegerAddExactNode.class);
  58 
  59     @Input(InputType.Guard) protected GuardingNode guard;
  60 
  61     public IntegerAddExactNode(ValueNode x, ValueNode y, GuardingNode guard) {
  62         super(TYPE, x, y);
  63         setStamp(x.stamp(NodeView.DEFAULT).unrestricted());
  64         assert x.stamp(NodeView.DEFAULT).isCompatible(y.stamp(NodeView.DEFAULT)) && x.stamp(NodeView.DEFAULT) instanceof IntegerStamp;
  65         this.guard = guard;
  66     }
  67 
  68     @Override
  69     public boolean inferStamp() {
  70         /*
  71          * Note: it is not allowed to use the foldStamp method of the regular add node as we do not
  72          * know the result stamp of this node if we do not know whether we may deopt. If we know we
  73          * can never overflow we will replace this node with its non overflow checking counterpart
  74          * anyway.
  75          */
  76         return false;




  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.replacements.nodes.arithmetic;
  26 
  27 import static org.graalvm.compiler.core.common.type.IntegerStamp.addOverflowsNegatively;
  28 import static org.graalvm.compiler.core.common.type.IntegerStamp.addOverflowsPositively;
  29 import static org.graalvm.compiler.core.common.type.IntegerStamp.carryBits;
  30 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_2;
  31 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_2;
  32 
  33 import org.graalvm.compiler.core.common.type.IntegerStamp;
  34 import org.graalvm.compiler.core.common.type.Stamp;
  35 import org.graalvm.compiler.core.common.type.StampFactory;
  36 import org.graalvm.compiler.graph.IterableNodeType;
  37 import org.graalvm.compiler.graph.NodeClass;
  38 import org.graalvm.compiler.graph.spi.CanonicalizerTool;
  39 import org.graalvm.compiler.nodeinfo.InputType;
  40 import org.graalvm.compiler.nodeinfo.NodeInfo;
  41 import org.graalvm.compiler.nodes.ConstantNode;
  42 import org.graalvm.compiler.nodes.NodeView;
  43 import org.graalvm.compiler.nodes.ValueNode;
  44 import org.graalvm.compiler.nodes.calc.AddNode;
  45 
  46 import jdk.vm.ci.code.CodeUtil;
  47 import jdk.vm.ci.meta.JavaConstant;
  48 import jdk.vm.ci.meta.JavaKind;
  49 import org.graalvm.compiler.nodes.extended.GuardedNode;
  50 import org.graalvm.compiler.nodes.extended.GuardingNode;
  51 
  52 /**
  53  * Node representing an exact integer addition that will throw an {@link ArithmeticException} in
  54  * case the addition would overflow the 32 bit range.
  55  */
  56 @NodeInfo(cycles = CYCLES_2, size = SIZE_2)
  57 public final class IntegerAddExactNode extends AddNode implements GuardedNode, IntegerExactArithmeticNode, IterableNodeType {
  58     public static final NodeClass<IntegerAddExactNode> TYPE = NodeClass.create(IntegerAddExactNode.class);
  59 
  60     @Input(InputType.Guard) protected GuardingNode guard;
  61 
  62     public IntegerAddExactNode(ValueNode x, ValueNode y, GuardingNode guard) {
  63         super(TYPE, x, y);
  64         setStamp(x.stamp(NodeView.DEFAULT).unrestricted());
  65         assert x.stamp(NodeView.DEFAULT).isCompatible(y.stamp(NodeView.DEFAULT)) && x.stamp(NodeView.DEFAULT) instanceof IntegerStamp;
  66         this.guard = guard;
  67     }
  68 
  69     @Override
  70     public boolean inferStamp() {
  71         /*
  72          * Note: it is not allowed to use the foldStamp method of the regular add node as we do not
  73          * know the result stamp of this node if we do not know whether we may deopt. If we know we
  74          * can never overflow we will replace this node with its non overflow checking counterpart
  75          * anyway.
  76          */
  77         return false;


< prev index next >