12 #include "mlir/Interfaces/InferIntRangeInterface.cpp.inc"
18 return umin().getBitWidth() == other.
umin().getBitWidth() &&
34 return IndexType::kInternalStorageBitWidth;
35 if (
auto integerType = dyn_cast<IntegerType>(type))
36 return integerType.getWidth();
46 return {value, value, value, value};
58 unsigned int width =
smin.getBitWidth();
60 if (
smin.isNonNegative() ==
smax.isNonNegative()) {
64 umin = APInt::getMinValue(width);
65 umax = APInt::getMaxValue(width);
72 unsigned int width =
umin.getBitWidth();
74 if (
umin.isNonNegative() ==
umax.isNonNegative()) {
78 smin = APInt::getSignedMinValue(width);
79 smax = APInt::getSignedMaxValue(width);
90 if (other.
umin().getBitWidth() == 0)
98 return {uminUnion, umaxUnion, sminUnion, smaxUnion};
107 if (other.
umin().getBitWidth() == 0)
110 const APInt &uminIntersect =
umin().ugt(other.
umin()) ?
umin() : other.
umin();
111 const APInt &umaxIntersect =
umax().ult(other.
umax()) ?
umax() : other.
umax();
112 const APInt &sminIntersect =
smin().sgt(other.
smin()) ?
smin() : other.
smin();
113 const APInt &smaxIntersect =
smax().slt(other.
smax()) ?
smax() : other.
smax();
115 return {uminIntersect, umaxIntersect, sminIntersect, smaxIntersect};
128 return os <<
"unsigned : [" << range.
umin() <<
", " << range.
umax()
129 <<
"] signed : [" << range.
smin() <<
", " << range.
smax() <<
"]";
137 APInt umin = APInt::getMinValue(width);
138 APInt umax = APInt::getMaxValue(width);
139 APInt smin = width != 0 ? APInt::getSignedMinValue(width) : umin;
140 APInt smax = width != 0 ? APInt::getSignedMaxValue(width) : umax;
153 unpacked.reserve(argRanges.size());
156 if (range.isUninitialized())
158 unpacked.push_back(range.getValue());
161 interface.inferResultRanges(
171 auto ranges = llvm::to_vector_of<IntegerValueRange>(argRanges);
172 interface.inferResultRangesFromOptional(
175 if (!argRanges.isUninitialized())
176 setResultRanges(value, argRanges.getValue());
static Value getZero(OpBuilder &b, Location loc, Type elementType)
Get zero value for an element type.
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
static unsigned getBitWidth(Type type)
Returns the bit width of integer, float or vector of float or integer values.
A set of arbitrary-precision integers representing bounds on a given integer value.
static ConstantIntRanges maxRange(unsigned bitwidth)
Create a ConstantIntRanges with the maximum bounds for the width bitwidth, that is - [0,...
const APInt & smax() const
The maximum value of an integer when it is interpreted as signed.
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...
const APInt & smin() const
The minimum value of an integer when it is interpreted as signed.
static ConstantIntRanges range(const APInt &min, const APInt &max, bool isSigned)
Create a ConstantIntRanges whose minimum is min and maximum is max with isSigned specifying if the mi...
ConstantIntRanges intersection(const ConstantIntRanges &other) const
Returns the intersection (computed separately for signed and unsigned bounds) of this range and other...
static ConstantIntRanges fromSigned(const APInt &smin, const APInt &smax)
Create an ConstantIntRanges with the signed minimum and maximum equal to smin and smax,...
static unsigned getStorageBitwidth(Type type)
Return the bitwidth that should be used for integer ranges describing type.
std::optional< APInt > getConstantValue() const
If either the signed or unsigned interpretations of the range indicate that the value it bounds is a ...
const APInt & umax() const
The maximum value of an integer when it is interpreted as unsigned.
const APInt & umin() const
The minimum value of an integer when it is interpreted as unsigned.
ConstantIntRanges rangeUnion(const ConstantIntRanges &other) const
Returns the union (computed separately for signed and unsigned bounds) of this range and other.
bool operator==(const ConstantIntRanges &other) const
This lattice value represents the integer range of an SSA value.
void print(raw_ostream &os) const
Print the integer value range.
static IntegerValueRange getMaxRange(Value value)
Create a maximal range ([0, uint_max(t)] / [int_min(t), int_max(t)]) range that is used to mark the v...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
void defaultInferResultRanges(InferIntRangeInterface interface, ArrayRef< IntegerValueRange > argRanges, SetIntLatticeFn setResultRanges)
Default implementation of inferResultRanges which dispatches to the inferResultRangesFromOptional.
void defaultInferResultRangesFromOptional(InferIntRangeInterface interface, ArrayRef< ConstantIntRanges > argRanges, SetIntRangeFn setResultRanges)
Default implementation of inferResultRangesFromOptional which dispatches to the inferResultRanges.
Include the generated interface declarations.
Type getElementTypeOrSelf(Type type)
Return the element type or return the type itself.
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)