15#ifndef LLVM_ADT_APSINT_H
16#define LLVM_ADT_APSINT_H
25 bool IsUnsigned =
false;
67 APInt::operator=(std::move(
RHS));
73 APInt::operator=(
RHS);
85 APInt::toString(Str, Radix,
isSigned());
87 using APInt::toString;
100 assert(isRepresentableByInt64() &&
"Too many bits for int64_t");
101 return isSigned() ? getSExtValue() : getZExtValue();
105 return isRepresentableByInt64() ? std::optional<int64_t>(getExtValue())
110 return APSInt(APInt::trunc(width), IsUnsigned);
115 return APSInt(zext(width), IsUnsigned);
117 return APSInt(sext(width), IsUnsigned);
122 return APSInt(zextOrTrunc(width), IsUnsigned);
124 return APSInt(sextOrTrunc(width), IsUnsigned);
128 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
136 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
144 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
148 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
153 return IsUnsigned ?
APSInt(lshr(Amt),
true) :
APSInt(ashr(Amt),
false);
163 return IsUnsigned ?
APSInt(relativeLShr(Amt),
true)
164 :
APSInt(relativeAShr(Amt),
false);
168 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
169 return IsUnsigned ? ult(
RHS) : slt(
RHS);
172 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
173 return IsUnsigned ? ugt(
RHS) : sgt(
RHS);
176 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
177 return IsUnsigned ? ule(
RHS) : sle(
RHS);
180 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
181 return IsUnsigned ? uge(
RHS) : sge(
RHS);
184 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
190 return compareValues(*
this,
get(
RHS)) == 0;
193 return compareValues(*
this,
get(
RHS)) != 0;
196 return compareValues(*
this,
get(
RHS)) <= 0;
199 return compareValues(*
this,
get(
RHS)) >= 0;
202 return compareValues(*
this,
get(
RHS)) < 0;
205 return compareValues(*
this,
get(
RHS)) > 0;
212 return APSInt(
static_cast<const APInt &
>(*
this) << Bits, IsUnsigned);
215 static_cast<APInt &
>(*this) <<= Amt;
219 return IsUnsigned ?
APSInt(relativeLShl(Amt),
true)
220 :
APSInt(relativeAShl(Amt),
false);
224 ++(
static_cast<APInt &
>(*this));
228 --(
static_cast<APInt &
>(*this));
232 return APSInt(++
static_cast<APInt &
>(*
this), IsUnsigned);
235 return APSInt(--
static_cast<APInt &
>(*
this), IsUnsigned);
238 return APSInt(-
static_cast<const APInt &
>(*
this), IsUnsigned);
241 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
246 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
251 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
256 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
261 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
266 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
272 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
273 return APSInt(
static_cast<const APInt &
>(*
this) &
RHS, IsUnsigned);
277 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
278 return APSInt(
static_cast<const APInt &
>(*
this) |
RHS, IsUnsigned);
282 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
283 return APSInt(
static_cast<const APInt &
>(*
this) ^
RHS, IsUnsigned);
287 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
288 return APSInt(
static_cast<const APInt &
>(*
this) *
RHS, IsUnsigned);
291 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
292 return APSInt(
static_cast<const APInt &
>(*
this) +
RHS, IsUnsigned);
295 assert(IsUnsigned ==
RHS.IsUnsigned &&
"Signedness mismatch!");
296 return APSInt(
static_cast<const APInt &
>(*
this) -
RHS, IsUnsigned);
299 return APSInt(~
static_cast<const APInt &
>(*
this), IsUnsigned);
306 : APInt::getSignedMaxValue(numBits),
314 : APInt::getSignedMinValue(numBits),
321 return !compareValues(I1, I2);
327 return I1.IsUnsigned ? I1.compare(I2) : I1.compareSigned(I2);
331 return compareValues(I1, I2.
extend(I1.getBitWidth()));
333 return compareValues(I1.extend(I2.
getBitWidth()), I2);
347 return I1.compare(I2);
366 I.print(
OS,
I.isSigned());
385 return LHS.getBitWidth() ==
RHS.getBitWidth() &&
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static bool isSigned(unsigned int Opcode)
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Class for arbitrary precision integers.
unsigned getBitWidth() const
Return the number of bits in the APInt.
An arbitrary precision integer that knows its signedness.
APSInt extOrTrunc(uint32_t width) const
APSInt & operator+=(const APSInt &RHS)
APSInt operator-(const APSInt &RHS) const
APSInt & operator=(APInt RHS)
static APSInt getMinValue(uint32_t numBits, bool Unsigned)
Return the APSInt representing the minimum integer value with the given bit width and signedness.
bool operator==(int64_t RHS) const
static APSInt get(int64_t X)
bool operator==(const APSInt &RHS) const
bool isNegative() const
Determine sign of this APSInt.
APSInt operator>>(unsigned Amt) const
APSInt operator^(const APSInt &RHS) const
bool operator!=(int64_t RHS) const
APSInt operator*(const APSInt &RHS) const
APSInt & operator*=(const APSInt &RHS)
bool operator>(const APSInt &RHS) const
bool operator>(int64_t RHS) const
APSInt(uint32_t BitWidth, bool isUnsigned=true)
Create an APSInt with the specified width, default to unsigned.
APSInt relativeShr(unsigned Amt) const
bool operator<(const APSInt &RHS) const
static int compareValues(const APSInt &I1, const APSInt &I2)
Compare underlying values of two numbers.
int64_t getExtValue() const
Get the correctly-extended int64_t value.
APSInt operator+(const APSInt &RHS) const
const APSInt & operator/=(const APSInt &RHS)
bool isRepresentableByInt64() const
If this int is representable using an int64_t.
static APSInt getMaxValue(uint32_t numBits, bool Unsigned)
Return the APSInt representing the maximum integer value with the given bit width and signedness.
bool isNonNegative() const
Determine if this APSInt Value is non-negative (>= 0)
static APSInt getUnsigned(uint64_t X)
bool operator<=(int64_t RHS) const
APSInt operator<<(unsigned Bits) const
APSInt operator&(const APSInt &RHS) const
bool isStrictlyPositive() const
Determine if this APSInt Value is positive.
APSInt & operator&=(const APSInt &RHS)
void setIsSigned(bool Val)
bool operator>=(const APSInt &RHS) const
APSInt(APInt I, bool isUnsigned=true)
APSInt operator%(const APSInt &RHS) const
const APSInt & operator%=(const APSInt &RHS)
APSInt & operator|=(const APSInt &RHS)
APSInt relativeShl(unsigned Amt) const
void toString(SmallVectorImpl< char > &Str, unsigned Radix=10) const
Append this APSInt to the specified SmallString.
bool operator!=(const APSInt &RHS) const
std::optional< int64_t > tryExtValue() const
bool operator<(int64_t RHS) const
APSInt()=default
Default constructor that creates an uninitialized APInt.
APSInt & operator>>=(unsigned Amt)
void setIsUnsigned(bool Val)
static bool isSameValue(const APSInt &I1, const APSInt &I2)
Determine if two APSInts have the same value, zero- or sign-extending as needed.
APSInt extend(uint32_t width) const
APSInt & operator-=(const APSInt &RHS)
APSInt operator|(const APSInt &RHS) const
bool operator<=(const APSInt &RHS) const
APSInt operator/(const APSInt &RHS) const
APSInt & operator=(uint64_t RHS)
bool operator>=(int64_t RHS) const
APSInt trunc(uint32_t width) const
APSInt & operator^=(const APSInt &RHS)
APSInt & operator<<=(unsigned Amt)
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
bool operator!=(uint64_t V1, const APInt &V2)
bool operator>=(int64_t V1, const APSInt &V2)
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
bool operator>(int64_t V1, const APSInt &V2)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
bool operator<=(int64_t V1, const APSInt &V2)
Implement std::hash so that hash_code can be used in STL containers.
static APSInt getEmptyKey()
static bool isEqual(const APSInt &LHS, const APSInt &RHS)
static APSInt getTombstoneKey()
static unsigned getHashValue(const APSInt &Key)
An information struct used to provide DenseMap with the various necessary components for a given valu...