13 #include "llvm/Support/Debug.h"
16 #define DEBUG_TYPE "int-range-analysis"
28 const APInt &value = getValue();
34 bool value = getValue();
35 APInt asInt(1, value);
60 argRanges, CmpMode::Both));
66 argRanges, CmpMode::Both));
72 argRanges, CmpMode::Both));
77 setResultRange(getResult(),
83 setResultRange(getResult(),
89 setResultRange(getResult(),
95 setResultRange(getResult(),
101 return setResultRange(
107 setResultRange(getResult(),
113 setResultRange(getResult(),
119 setResultRange(getResult(),
125 setResultRange(getResult(),
131 setResultRange(getResult(),
137 setResultRange(getResult(),
144 argRanges, CmpMode::Both));
149 setResultRange(getResult(),
155 setResultRange(getResult(),
161 setResultRange(getResult(),
167 setResultRange(getResult(),
173 setResultRange(getResult(),
182 unsigned srcWidth,
unsigned destWidth,
184 if (srcWidth < destWidth)
185 return isSigned ?
extSIRange(range, destWidth)
187 if (srcWidth > destWidth)
200 return makeLikeDest(range, srcWidth, destWidth, isSigned);
213 Type sourceType = getOperand().getType();
214 Type destType = getResult().getType();
215 setResultRange(getResult(),
inferIndexCast(argRanges[0], sourceType, destType,
221 Type sourceType = getOperand().getType();
222 Type destType = getResult().getType();
223 setResultRange(getResult(),
inferIndexCast(argRanges[0], sourceType, destType,
233 index::IndexCmpPredicate indexPred = getPred();
238 APInt
max = APInt::getAllOnes(1);
244 std::optional<bool> truthValue32 =
247 if (truthValue64 == truthValue32) {
248 if (truthValue64.has_value() && *truthValue64)
250 else if (truthValue64.has_value() && !(*truthValue64))
262 unsigned storageWidth =
static Value getZero(OpBuilder &b, Location loc, Type elementType)
Get zero value for an element type.
static std::function< ConstantIntRanges(ArrayRef< ConstantIntRanges >)> inferWithoutOverflowFlags(InferRangeWithOvfFlagsFn inferWithOvfFn)
static ConstantIntRanges makeLikeDest(const ConstantIntRanges &range, unsigned srcWidth, unsigned destWidth, bool isSigned)
static ConstantIntRanges inferIndexCast(const ConstantIntRanges &range, Type sourceType, Type destType, bool isSigned)
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
A set of arbitrary-precision integers representing bounds on a given integer value.
static ConstantIntRanges constant(const APInt &value)
Create a ConstantIntRanges with a constant value - that is, with the bounds [value,...
static ConstantIntRanges fromUnsigned(const APInt &umin, const APInt &umax)
Create an ConstantIntRanges with the unsigned minimum and maximum equal to umin and umax and the sign...
static unsigned getStorageBitwidth(Type type)
Return the bitwidth that should be used for integer ranges describing type.
ConstantIntRanges rangeUnion(const ConstantIntRanges &other) const
Returns the union (computed separately for signed and unsigned bounds) of this range and other.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
ConstantIntRanges inferAnd(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferShl(ArrayRef< ConstantIntRanges > argRanges, OverflowFlags ovfFlags=OverflowFlags::None)
ConstantIntRanges inferIndexOp(const InferRangeFn &inferFn, ArrayRef< ConstantIntRanges > argRanges, CmpMode mode)
Compute inferFn on ranges, whose size should be the index storage bitwidth.
ConstantIntRanges inferShrS(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges extSIRange(const ConstantIntRanges &range, unsigned destWidth)
Use the signed values in range to sign-extend it to destWidth.
std::optional< bool > evaluatePred(CmpPredicate pred, const ConstantIntRanges &lhs, const ConstantIntRanges &rhs)
Returns a boolean value if pred is statically true or false for anypossible inputs falling within lhs...
ConstantIntRanges inferMinS(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferMaxU(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferRemS(ArrayRef< ConstantIntRanges > argRanges)
CmpPredicate
Copy of the enum from arith and index to allow the common integer range infrastructure to not depend ...
ConstantIntRanges inferOr(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges extRange(const ConstantIntRanges &range, unsigned destWidth)
Independently zero-extend the unsigned values and sign-extend the signed values in range to destWidth...
ConstantIntRanges inferSub(ArrayRef< ConstantIntRanges > argRanges, OverflowFlags ovfFlags=OverflowFlags::None)
ConstantIntRanges inferAdd(ArrayRef< ConstantIntRanges > argRanges, OverflowFlags ovfFlags=OverflowFlags::None)
ConstantIntRanges truncRange(const ConstantIntRanges &range, unsigned destWidth)
Truncate range to destWidth bits, taking care to handle cases such as the truncation of [255,...
ConstantIntRanges inferDivU(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferCeilDivS(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferMinU(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferMul(ArrayRef< ConstantIntRanges > argRanges, OverflowFlags ovfFlags=OverflowFlags::None)
ConstantIntRanges inferXor(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferDivS(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferShrU(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges inferRemU(ArrayRef< ConstantIntRanges > argRanges)
static constexpr unsigned indexMinWidth
ConstantIntRanges inferFloorDivS(ArrayRef< ConstantIntRanges > argRanges)
static constexpr unsigned indexMaxWidth
ConstantIntRanges inferCeilDivU(ArrayRef< ConstantIntRanges > argRanges)
ConstantIntRanges extUIRange(const ConstantIntRanges &range, unsigned destWidth)
Use the unsigned values in range to zero-extend it to destWidth.
ConstantIntRanges inferMaxS(ArrayRef< ConstantIntRanges > argRanges)
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.