LLVM: llvm::APSInt Class Reference (original) (raw)
Public Member Functions
APSInt ()=default
Default constructor that creates an uninitialized APInt.
APSInt (uint32_t BitWidth, bool isUnsigned=true)
Create an APSInt with the specified width, default to unsigned.
APSInt (APInt I, bool isUnsigned=true)
Construct an APSInt from a string representation.
isNegative () const
Determine sign of this APSInt.
Determine if this APSInt Value is non-negative (>= 0)
Determine if this APSInt Value is positive.
APSInt &
APSInt &
isUnsigned () const
void
setIsUnsigned (bool Val)
void
setIsSigned (bool Val)
void
toString (SmallVectorImpl< char > &Str, unsigned Radix=10) const
Append this APSInt to the specified SmallString.
isRepresentableByInt64 () const
If this int is representable using an int64_t.
int64_t
getExtValue () const
Get the correctly-extended int64_t value.
std::optional< int64_t >
tryExtValue () const
extOrTrunc (uint32_t width) const
operator%= (const APSInt &RHS)
operator/= (const APSInt &RHS)
operator% (const APSInt &RHS) const
operator/ (const APSInt &RHS) const
operator>> (unsigned Amt) const
APSInt &
operator>>= (unsigned Amt)
relativeShr (unsigned Amt) const
operator< (const APSInt &RHS) const
operator> (const APSInt &RHS) const
operator<= (const APSInt &RHS) const
operator>= (const APSInt &RHS) const
operator== (const APSInt &RHS) const
operator!= (const APSInt &RHS) const
operator== (int64_t RHS) const
operator!= (int64_t RHS) const
operator<= (int64_t RHS) const
operator>= (int64_t RHS) const
operator<< (unsigned Bits) const
APSInt &
operator<<= (unsigned Amt)
relativeShl (unsigned Amt) const
APSInt &
operator++ ()
APSInt &
operator-- ()
operator++ (int)
operator-- (int)
APSInt &
operator+= (const APSInt &RHS)
APSInt &
operator-= (const APSInt &RHS)
APSInt &
operator*= (const APSInt &RHS)
APSInt &
operator&= (const APSInt &RHS)
APSInt &
operator|= (const APSInt &RHS)
APSInt &
operator^= (const APSInt &RHS)
operator& (const APSInt &RHS) const
operator| (const APSInt &RHS) const
operator^ (const APSInt &RHS) const
operator* (const APSInt &RHS) const
operator+ (const APSInt &RHS) const
operator- (const APSInt &RHS) const
LLVM_ABI void
Profile (FoldingSetNodeID &ID) const
Used to insert APSInt objects, or objects that contain APSInt objects, into FoldingSets.
LLVM_ABI void
toString (SmallVectorImpl< char > &Str, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false) const
Converts an APInt to a string and append it to Str.
Public Member Functions inherited from llvm::APInt
APInt (unsigned numBits, uint64_t val, bool isSigned=false, bool implicitTrunc=false)
Create a new APInt of numBits width, initialized as val.
APInt (unsigned numBits, ArrayRef< uint64_t > bigVal)
Construct an APInt of numBits width, initialized as bigVal[].
APInt (unsigned numBits, unsigned numWords, const uint64_t bigVal[])
Equivalent to APInt(numBits, ArrayRef<uint64_t>(bigVal, numWords)), but deprecated because this constructor is prone to ambiguity with the APInt(unsigned, uint64_t, bool) constructor.
APInt (unsigned numBits, StringRef str, uint8_t radix)
Construct an APInt from a string representation.
APInt ()
Default constructor that creates an APInt with a 1-bit zero value.
Copy Constructor.
Move Constructor.
~APInt ()
Destructor.
operator++ (int)
Postfix increment operator.
operator++ ()
Prefix increment operator.
operator-- (int)
Postfix decrement operator.
operator-- ()
Prefix decrement operator.
Logical negation operation on this APInt returns true if zero, like normal integers.
APInt &
Copy assignment operator.
APInt &
Move assignment operator.
APInt &
Assignment operator.
APInt &
operator&= (const APInt &RHS)
Bitwise AND assignment operator.
APInt &
Bitwise AND assignment operator.
APInt &
operator|= (const APInt &RHS)
Bitwise OR assignment operator.
APInt &
Bitwise OR assignment operator.
APInt &
operator^= (const APInt &RHS)
Bitwise XOR assignment operator.
APInt &
Bitwise XOR assignment operator.
operator*= (const APInt &RHS)
Multiplication assignment operator.
operator+= (const APInt &RHS)
Addition assignment operator.
operator-= (const APInt &RHS)
Subtraction assignment operator.
APInt &
operator<<= (unsigned ShiftAmt)
Left-shift assignment function.
operator<<= (const APInt &ShiftAmt)
Left-shift assignment function.
operator== (const APInt &RHS) const
Equality operator.
operator== (uint64_t Val) const
Equality operator.
Equality comparison.
operator!= (const APInt &RHS) const
Inequality operator.
operator!= (uint64_t Val) const
Inequality operator.
Inequality comparison.
Unsigned less than comparison.
Unsigned less than comparison.
Signed less than comparison.
Signed less than comparison.
Unsigned less or equal comparison.
Unsigned less or equal comparison.
Signed less or equal comparison.
Signed less or equal comparison.
Unsigned greater than comparison.
Unsigned greater than comparison.
Signed greater than comparison.
Signed greater than comparison.
Unsigned greater or equal comparison.
Unsigned greater or equal comparison.
Signed greater or equal comparison.
Signed greater or equal comparison.
intersects (const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are both set.
isSubsetOf (const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
Truncate to new width.
truncUSat (unsigned width) const
Truncate to new width with unsigned saturation.
truncSSat (unsigned width) const
Truncate to new width with signed saturation.
Sign extend to a new width.
Zero extend to a new width.
sextOrTrunc (unsigned width) const
Sign extend or truncate to width.
zextOrTrunc (unsigned width) const
Zero extend or truncate to width.
void
setAllBits ()
Set every bit to 1.
void
Set the given bit to 1 whose position is given as "bitPosition".
void
setSignBit ()
Set the sign bit to 1.
void
setBitVal (unsigned BitPosition, bool BitValue)
Set a given bit to a given value.
void
setBitsWithWrap (unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
void
setBits (unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
void
setBitsFrom (unsigned loBit)
Set the top bits starting from loBit.
void
setLowBits (unsigned loBits)
Set the bottom loBits bits.
void
setHighBits (unsigned hiBits)
Set the top hiBits bits.
void
clearAllBits ()
Set every bit to 0.
void
clearBit (unsigned BitPosition)
Set a given bit to 0.
void
clearBits (unsigned LoBit, unsigned HiBit)
Clear the bits from LoBit (inclusive) to HiBit (exclusive) to 0.
void
clearLowBits (unsigned loBits)
Set bottom loBits bits to 0.
void
clearHighBits (unsigned hiBits)
Set top hiBits bits to 0.
void
clearSignBit ()
Set the sign bit to 0.
void
flipAllBits ()
Toggle every bit to its opposite value.
LLVM_ABI void
flipBit (unsigned bitPosition)
Toggles a given bit to its opposite value.
void
negate ()
Negate this APInt in place.
LLVM_ABI void
insertBits (const APInt &SubBits, unsigned bitPosition)
Insert the bits from a smaller APInt starting at bitPosition.
LLVM_ABI void
insertBits (uint64_t SubBits, unsigned bitPosition, unsigned numBits)
extractBits (unsigned numBits, unsigned bitPosition) const
Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
extractBitsAsZExtValue (unsigned numBits, unsigned bitPosition) const
int32_t
Compute the square root.
Get the absolute value.
multiplicativeInverse () const
LLVM_ABI void
Profile (FoldingSetNodeID &id) const
Used to insert APInt objects, or objects that contain APInt objects, into FoldingSets.
LLVM_DUMP_METHOD void
debug method
Returns whether this instance allocated memory.
Determine if this APInt just has one word to store value.
isNegative () const
Determine sign of this APInt.
Determine if this APInt Value is non-negative (>= 0)
Determine if sign bit of this APInt is set.
Determine if sign bit of this APInt is clear.
Determine if this APInt Value is positive.
Determine if this APInt Value is non-positive (<= 0).
isOneBitSet (unsigned BitNo) const
Determine if this APInt Value only has the specified bit set.
Determine if all bits are set. This is true for zero-width values.
Determine if this value is zero, i.e. all bits are clear.
Determine if this is a value of 1.
isMaxValue () const
Determine if this is the largest unsigned value.
Determine if this is the largest signed value.
isMinValue () const
Determine if this is the smallest unsigned value.
Determine if this is the smallest signed value.
Check if this APInt has an N-bits unsigned integer value.
isSignedIntN (unsigned N) const
Check if this APInt has an N-bits signed integer value.
isPowerOf2 () const
Check if this APInt's value is a power of two greater than zero.
Check if this APInt's negated value is a power of two greater than zero.
Checks if this APInt -interpreted as an address- is aligned to the provided value.
isSignMask () const
Check if the APInt's value is returned by getSignMask.
Convert APInt to a boolean value.
getLimitedValue (uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
isSplat (unsigned SplatSizeInBits) const
Check if the APInt consists of a repeated bit pattern.
isMask (unsigned numBits) const
Return true if this APInt value contains a non-empty sequence of ones with the remainder zero.
isShiftedMask (unsigned &MaskIdx, unsigned &MaskLen) const
Return true if this APInt value contains a non-empty sequence of ones with the remainder zero.
getHiBits (unsigned numBits) const
Compute an APInt containing numBits highbits from this APInt.
getLoBits (unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
getRawData () const
This function returns a pointer to the internal storage of the APInt.
operator* (const APInt &RHS) const
Multiplication operator.
operator<< (unsigned Bits) const
Left logical shift operator.
operator<< (const APInt &Bits) const
Left logical shift operator.
ashr (unsigned ShiftAmt) const
Arithmetic right-shift function.
void
ashrInPlace (unsigned ShiftAmt)
Arithmetic right-shift this APInt by ShiftAmt in place.
lshr (unsigned shiftAmt) const
Logical right-shift function.
void
lshrInPlace (unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
Left-shift function.
relativeLShr (int RelativeShift) const
relative logical shift right
relativeLShl (int RelativeShift) const
relative logical shift left
relativeAShr (int RelativeShift) const
relative arithmetic shift right
relativeAShl (int RelativeShift) const
relative arithmetic shift left
rotl (unsigned rotateAmt) const
Rotate left by rotateAmt.
rotr (unsigned rotateAmt) const
Rotate right by rotateAmt.
ashr (const APInt &ShiftAmt) const
Arithmetic right-shift function.
LLVM_ABI void
ashrInPlace (const APInt &shiftAmt)
Arithmetic right-shift this APInt by shiftAmt in place.
lshr (const APInt &ShiftAmt) const
Logical right-shift function.
LLVM_ABI void
lshrInPlace (const APInt &ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
shl (const APInt &ShiftAmt) const
Left-shift function.
rotl (const APInt &rotateAmt) const
Rotate left by rotateAmt.
rotr (const APInt &rotateAmt) const
Rotate right by rotateAmt.
concat (const APInt &NewLSB) const
Concatenate the bits from "NewLSB" onto the bottom of *this.
Unsigned division operation.
Signed division function for APInt.
Unsigned remainder operation.
Function for signed remainder operation.
LLVM_ABI int64_t
sadd_ov (const APInt &RHS, bool &Overflow) const
uadd_ov (const APInt &RHS, bool &Overflow) const
ssub_ov (const APInt &RHS, bool &Overflow) const
usub_ov (const APInt &RHS, bool &Overflow) const
sdiv_ov (const APInt &RHS, bool &Overflow) const
smul_ov (const APInt &RHS, bool &Overflow) const
umul_ov (const APInt &RHS, bool &Overflow) const
sshl_ov (const APInt &Amt, bool &Overflow) const
sshl_ov (unsigned Amt, bool &Overflow) const
ushl_ov (const APInt &Amt, bool &Overflow) const
ushl_ov (unsigned Amt, bool &Overflow) const
sfloordiv_ov (const APInt &RHS, bool &Overflow) const
Signed integer floor division operation.
sadd_sat (const APInt &RHS) const
uadd_sat (const APInt &RHS) const
ssub_sat (const APInt &RHS) const
usub_sat (const APInt &RHS) const
smul_sat (const APInt &RHS) const
umul_sat (const APInt &RHS) const
sshl_sat (const APInt &RHS) const
ushl_sat (const APInt &RHS) const
operator[] (unsigned bitPosition) const
Array-indexing support.
getBitWidth () const
Return the number of bits in the APInt.
getNumWords () const
Get the number of words.
Compute the number of active bits in the value.
Compute the number of active words in the value of this APInt.
Get the minimum bit size for this signed APInt.
Get zero extended value.
std::optional< uint64_t >
Get zero extended value if possible.
int64_t
Get sign extended value.
std::optional< int64_t >
Get sign extended value if possible.
countl_zero () const
The APInt version of std::countl_zero.
countl_one () const
Count the number of leading one bits.
Computes the number of leading bits of this APInt that are equal to its sign bit.
countr_zero () const
Count the number of trailing zero bits.
countr_one () const
Count the number of trailing one bits.
Count the number of bits set.
LLVM_ABI void
print (raw_ostream &OS, bool isSigned) const
LLVM_ABI void
toString (SmallVectorImpl< char > &Str, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false) const
Converts an APInt to a string and append it to Str.
void
toStringUnsigned (SmallVectorImpl< char > &Str, unsigned Radix=10) const
Considers the APInt to be unsigned and converts it into a string in the radix given.
void
toStringSigned (SmallVectorImpl< char > &Str, unsigned Radix=10) const
Considers the APInt to be signed and converts it into a string in the radix given.
reverseBits () const
LLVM_ABI double
roundToDouble (bool isSigned) const
Converts this APInt to a double value.
double
Converts this unsigned APInt to a double value.
double
Converts this signed APInt to a double value.
double
Converts APInt bits to a double.
bitsToFloat () const
Converts APInt bits to a float.
Static Public Member Functions
static APSInt
getMaxValue (uint32_t numBits, bool Unsigned)
Return the APSInt representing the maximum integer value with the given bit width and signedness.
static APSInt
getMinValue (uint32_t numBits, bool Unsigned)
Return the APSInt representing the minimum integer value with the given bit width and signedness.
static bool
isSameValue (const APSInt &I1, const APSInt &I2)
Determine if two APSInts have the same value, zero- or sign-extending as needed.
static int
compareValues (const APSInt &I1, const APSInt &I2)
Compare underlying values of two numbers.
static APSInt
static APSInt
Static Public Member Functions inherited from llvm::APInt
static APInt
Get the '0' value for the specified bit-width.
static APInt
getZeroWidth ()
Return an APInt zero bits wide.
static APInt
getMaxValue (unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
static APInt
getSignedMaxValue (unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static APInt
getMinValue (unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
static APInt
getSignedMinValue (unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
static APInt
getSignMask (unsigned BitWidth)
Get the SignMask for a specific bit width.
static APInt
getAllOnes (unsigned numBits)
Return an APInt of a specified width with all bits set.
static APInt
getOneBitSet (unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
static APInt
getBitsSet (unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
static APInt
getBitsSetWithWrap (unsigned numBits, unsigned loBit, unsigned hiBit)
Wrap version of getBitsSet.
static APInt
getBitsSetFrom (unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
static APInt
getHighBitsSet (unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
static APInt
getLowBitsSet (unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
getSplat (unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
static LLVM_ABI void
tcSet (WordType *, WordType, unsigned)
Sets the least significant part of a bignum to the input value, and zeroes out higher parts.
static LLVM_ABI void
tcAssign (WordType *, const WordType *, unsigned)
Assign one bignum to another.
tcIsZero (const WordType *, unsigned)
Returns true if a bignum is zero, false otherwise.
static LLVM_ABI int
tcExtractBit (const WordType *, unsigned bit)
Extract the given bit of a bignum; returns 0 or 1. Zero-based.
static LLVM_ABI void
tcExtract (WordType *, unsigned dstCount, const WordType *, unsigned srcBits, unsigned srcLSB)
Copy the bit vector of width srcBITS from SRC, starting at bit srcLSB, to DST, of dstCOUNT parts, such that the bit srcLSB becomes the least significant bit of DST.
static LLVM_ABI void
tcSetBit (WordType *, unsigned bit)
Set the given bit of a bignum. Zero-based.
static LLVM_ABI void
tcClearBit (WordType *, unsigned bit)
Clear the given bit of a bignum. Zero-based.
tcLSB (const WordType *, unsigned n)
Returns the bit number of the least or most significant set bit of a number.
tcMSB (const WordType *parts, unsigned n)
Returns the bit number of the most significant set bit of a number.
static LLVM_ABI void
tcNegate (WordType *, unsigned)
Negate a bignum in-place.
tcAdd (WordType *, const WordType *, WordType carry, unsigned)
DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
tcAddPart (WordType *, WordType, unsigned)
DST += RHS. Returns the carry flag.
tcSubtract (WordType *, const WordType *, WordType carry, unsigned)
DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
tcSubtractPart (WordType *, WordType, unsigned)
DST -= RHS. Returns the carry flag.
static LLVM_ABI int
tcMultiplyPart (WordType *dst, const WordType *src, WordType multiplier, WordType carry, unsigned srcParts, unsigned dstParts, bool add)
DST += SRC * MULTIPLIER + PART if add is true DST = SRC * MULTIPLIER + PART if add is false.
static LLVM_ABI int
tcMultiply (WordType *, const WordType *, const WordType *, unsigned)
DST = LHS * RHS, where DST has the same width as the operands and is filled with the least significant parts of the result.
static LLVM_ABI void
tcFullMultiply (WordType *, const WordType *, const WordType *, unsigned, unsigned)
DST = LHS * RHS, where DST has width the sum of the widths of the operands.
static LLVM_ABI int
tcDivide (WordType *lhs, const WordType *rhs, WordType *remainder, WordType *scratch, unsigned parts)
If RHS is zero LHS and REMAINDER are left unchanged, return one.
static LLVM_ABI void
tcShiftLeft (WordType *, unsigned Words, unsigned Count)
Shift a bignum left Count bits.
static LLVM_ABI void
tcShiftRight (WordType *, unsigned Words, unsigned Count)
Shift a bignum right Count bits.
static LLVM_ABI int
tcCompare (const WordType *, const WordType *, unsigned)
Comparison (unsigned) of two bignums.
static WordType
tcIncrement (WordType *dst, unsigned parts)
Increment a bignum in-place. Return the carry flag.
static WordType
tcDecrement (WordType *dst, unsigned parts)
Decrement a bignum in-place. Return the borrow flag.
static bool
isSameValue (const APInt &I1, const APInt &I2)
Determine if two APInts have the same value, after zero-extending one of them (if needed!) to ensure that the bit-widths match.
static LLVM_ABI void
udivrem (const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
static LLVM_ABI void
udivrem (const APInt &LHS, uint64_t RHS, APInt &Quotient, uint64_t &Remainder)
static LLVM_ABI void
sdivrem (const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
static LLVM_ABI void
sdivrem (const APInt &LHS, int64_t RHS, APInt &Quotient, int64_t &Remainder)
static unsigned
getNumWords (unsigned BitWidth)
Get the number of words.
getBitsNeeded (StringRef str, uint8_t radix)
Get bits required for string value.
getSufficientBitsNeeded (StringRef Str, uint8_t Radix)
Get the bits that are sufficient to represent the string value.
static APInt
doubleToBits (double V)
Converts a double to APInt bits.
static APInt
floatToBits (float V)
Converts a float to APInt bits.
An arbitrary precision integer that knows its signedness.