IntegerBelowNode.java revision 12968:4d8a004e5c6d
1/* 2 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 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 */ 23package org.graalvm.compiler.nodes.calc; 24 25import org.graalvm.compiler.core.common.NumUtil; 26import org.graalvm.compiler.core.common.calc.Condition; 27import org.graalvm.compiler.core.common.type.IntegerStamp; 28import org.graalvm.compiler.core.common.type.StampFactory; 29import org.graalvm.compiler.graph.NodeClass; 30import org.graalvm.compiler.nodeinfo.NodeInfo; 31import org.graalvm.compiler.nodes.LogicNode; 32import org.graalvm.compiler.nodes.ValueNode; 33 34import jdk.vm.ci.code.CodeUtil; 35import jdk.vm.ci.meta.ConstantReflectionProvider; 36 37@NodeInfo(shortName = "|<|") 38public final class IntegerBelowNode extends IntegerLowerThanNode { 39 public static final NodeClass<IntegerBelowNode> TYPE = NodeClass.create(IntegerBelowNode.class); 40 private static final BelowOp OP = new BelowOp(); 41 42 public IntegerBelowNode(ValueNode x, ValueNode y) { 43 super(TYPE, x, y, OP); 44 assert x.stamp() instanceof IntegerStamp; 45 assert y.stamp() instanceof IntegerStamp; 46 } 47 48 public static LogicNode create(ValueNode x, ValueNode y, ConstantReflectionProvider constantReflection) { 49 return OP.create(x, y, constantReflection); 50 } 51 52 @Override 53 protected CompareNode duplicateModified(ValueNode newX, ValueNode newY) { 54 assert newX.stamp() instanceof IntegerStamp && newY.stamp() instanceof IntegerStamp; 55 return new IntegerBelowNode(newX, newY); 56 } 57 58 public static class BelowOp extends LowerOp { 59 60 @Override 61 protected long upperBound(IntegerStamp stamp) { 62 return stamp.unsignedUpperBound(); 63 } 64 65 @Override 66 protected long lowerBound(IntegerStamp stamp) { 67 return stamp.unsignedLowerBound(); 68 } 69 70 @Override 71 protected int compare(long a, long b) { 72 return Long.compareUnsigned(a, b); 73 } 74 75 @Override 76 protected long min(long a, long b) { 77 return NumUtil.minUnsigned(a, b); 78 } 79 80 @Override 81 protected long max(long a, long b) { 82 return NumUtil.maxUnsigned(a, b); 83 } 84 85 @Override 86 protected long cast(long a, int bits) { 87 return CodeUtil.zeroExtend(a, bits); 88 } 89 90 @Override 91 protected long minValue(int bits) { 92 return 0; 93 } 94 95 @Override 96 protected long maxValue(int bits) { 97 return NumUtil.maxValueUnsigned(bits); 98 } 99 100 @Override 101 protected IntegerStamp forInteger(int bits, long min, long max) { 102 return StampFactory.forUnsignedInteger(bits, min, max); 103 } 104 105 @Override 106 protected Condition getCondition() { 107 return Condition.BT; 108 } 109 110 @Override 111 protected IntegerLowerThanNode create(ValueNode x, ValueNode y) { 112 return new IntegerBelowNode(x, y); 113 } 114 } 115} 116