LLVM 19.0.0git
Public Member Functions | Static Public Member Functions | List of all members
llvm::APSInt Class Reference

An arbitrary precision integer that knows its signedness. More...

#include "llvm/ADT/APSInt.h"

Inheritance diagram for llvm::APSInt:
Inheritance graph
[legend]

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)
 
 APSInt (StringRef Str)
 Construct an APSInt from a string representation.
 
bool isNegative () const
 Determine sign of this APSInt.
 
bool isNonNegative () const
 Determine if this APSInt Value is non-negative (>= 0)
 
bool isStrictlyPositive () const
 Determine if this APSInt Value is positive.
 
APSIntoperator= (APInt RHS)
 
APSIntoperator= (uint64_t RHS)
 
bool isSigned () const
 
bool 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.
 
bool 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
 
APSInt trunc (uint32_t width) const
 
APSInt extend (uint32_t width) const
 
APSInt extOrTrunc (uint32_t width) const
 
const APSIntoperator%= (const APSInt &RHS)
 
const APSIntoperator/= (const APSInt &RHS)
 
APSInt operator% (const APSInt &RHS) const
 
APSInt operator/ (const APSInt &RHS) const
 
APSInt operator>> (unsigned Amt) const
 
APSIntoperator>>= (unsigned Amt)
 
APSInt relativeShr (unsigned Amt) const
 
bool operator< (const APSInt &RHS) const
 
bool operator> (const APSInt &RHS) const
 
bool operator<= (const APSInt &RHS) const
 
bool operator>= (const APSInt &RHS) const
 
bool operator== (const APSInt &RHS) const
 
bool operator!= (const APSInt &RHS) const
 
bool operator== (int64_t RHS) const
 
bool operator!= (int64_t RHS) const
 
bool operator<= (int64_t RHS) const
 
bool operator>= (int64_t RHS) const
 
bool operator< (int64_t RHS) const
 
bool operator> (int64_t RHS) const
 
APSInt operator<< (unsigned Bits) const
 
APSIntoperator<<= (unsigned Amt)
 
APSInt relativeShl (unsigned Amt) const
 
APSIntoperator++ ()
 
APSIntoperator-- ()
 
APSInt operator++ (int)
 
APSInt operator-- (int)
 
APSInt operator- () const
 
APSIntoperator+= (const APSInt &RHS)
 
APSIntoperator-= (const APSInt &RHS)
 
APSIntoperator*= (const APSInt &RHS)
 
APSIntoperator&= (const APSInt &RHS)
 
APSIntoperator|= (const APSInt &RHS)
 
APSIntoperator^= (const APSInt &RHS)
 
APSInt operator& (const APSInt &RHS) const
 
APSInt operator| (const APSInt &RHS) const
 
APSInt operator^ (const APSInt &RHS) const
 
APSInt operator* (const APSInt &RHS) const
 
APSInt operator+ (const APSInt &RHS) const
 
APSInt operator- (const APSInt &RHS) const
 
APSInt operator~ () const
 
void Profile (FoldingSetNodeID &ID) const
 Used to insert APSInt objects, or objects that contain APSInt objects, into FoldingSets.
 
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)
 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.
 
 APInt (const APInt &that)
 Copy Constructor.
 
 APInt (APInt &&that)
 Move Constructor.
 
 ~APInt ()
 Destructor.
 
APInt operator++ (int)
 Postfix increment operator.
 
APIntoperator++ ()
 Prefix increment operator.
 
APInt operator-- (int)
 Postfix decrement operator.
 
APIntoperator-- ()
 Prefix decrement operator.
 
bool operator! () const
 Logical negation operation on this APInt returns true if zero, like normal integers.
 
APIntoperator= (const APInt &RHS)
 Copy assignment operator.
 
APIntoperator= (APInt &&that)
 Move assignment operator.
 
APIntoperator= (uint64_t RHS)
 Assignment operator.
 
APIntoperator&= (const APInt &RHS)
 Bitwise AND assignment operator.
 
APIntoperator&= (uint64_t RHS)
 Bitwise AND assignment operator.
 
APIntoperator|= (const APInt &RHS)
 Bitwise OR assignment operator.
 
APIntoperator|= (uint64_t RHS)
 Bitwise OR assignment operator.
 
APIntoperator^= (const APInt &RHS)
 Bitwise XOR assignment operator.
 
APIntoperator^= (uint64_t RHS)
 Bitwise XOR assignment operator.
 
APIntoperator*= (const APInt &RHS)
 Multiplication assignment operator.
 
APIntoperator*= (uint64_t RHS)
 
APIntoperator+= (const APInt &RHS)
 Addition assignment operator.
 
APIntoperator+= (uint64_t RHS)
 
APIntoperator-= (const APInt &RHS)
 Subtraction assignment operator.
 
APIntoperator-= (uint64_t RHS)
 
APIntoperator<<= (unsigned ShiftAmt)
 Left-shift assignment function.
 
APIntoperator<<= (const APInt &ShiftAmt)
 Left-shift assignment function.
 
bool operator== (const APInt &RHS) const
 Equality operator.
 
bool operator== (uint64_t Val) const
 Equality operator.
 
bool eq (const APInt &RHS) const
 Equality comparison.
 
bool operator!= (const APInt &RHS) const
 Inequality operator.
 
bool operator!= (uint64_t Val) const
 Inequality operator.
 
bool ne (const APInt &RHS) const
 Inequality comparison.
 
bool ult (const APInt &RHS) const
 Unsigned less than comparison.
 
bool ult (uint64_t RHS) const
 Unsigned less than comparison.
 
bool slt (const APInt &RHS) const
 Signed less than comparison.
 
bool slt (int64_t RHS) const
 Signed less than comparison.
 
bool ule (const APInt &RHS) const
 Unsigned less or equal comparison.
 
bool ule (uint64_t RHS) const
 Unsigned less or equal comparison.
 
bool sle (const APInt &RHS) const
 Signed less or equal comparison.
 
bool sle (uint64_t RHS) const
 Signed less or equal comparison.
 
bool ugt (const APInt &RHS) const
 Unsigned greater than comparison.
 
bool ugt (uint64_t RHS) const
 Unsigned greater than comparison.
 
bool sgt (const APInt &RHS) const
 Signed greater than comparison.
 
bool sgt (int64_t RHS) const
 Signed greater than comparison.
 
bool uge (const APInt &RHS) const
 Unsigned greater or equal comparison.
 
bool uge (uint64_t RHS) const
 Unsigned greater or equal comparison.
 
bool sge (const APInt &RHS) const
 Signed greater or equal comparison.
 
bool sge (int64_t RHS) const
 Signed greater or equal comparison.
 
bool 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.
 
bool isSubsetOf (const APInt &RHS) const
 This operation checks that all bits set in this APInt are also set in RHS.
 
APInt trunc (unsigned width) const
 Truncate to new width.
 
APInt truncUSat (unsigned width) const
 Truncate to new width with unsigned saturation.
 
APInt truncSSat (unsigned width) const
 Truncate to new width with signed saturation.
 
APInt sext (unsigned width) const
 Sign extend to a new width.
 
APInt zext (unsigned width) const
 Zero extend to a new width.
 
APInt sextOrTrunc (unsigned width) const
 Sign extend or truncate to width.
 
APInt zextOrTrunc (unsigned width) const
 Zero extend or truncate to width.
 
void setAllBits ()
 Set every bit to 1.
 
void setBit (unsigned BitPosition)
 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 clearLowBits (unsigned loBits)
 Set bottom loBits bits to 0.
 
void clearSignBit ()
 Set the sign bit to 0.
 
void flipAllBits ()
 Toggle every bit to its opposite value.
 
void flipBit (unsigned bitPosition)
 Toggles a given bit to its opposite value.
 
void negate ()
 Negate this APInt in place.
 
void insertBits (const APInt &SubBits, unsigned bitPosition)
 Insert the bits from a smaller APInt starting at bitPosition.
 
void insertBits (uint64_t SubBits, unsigned bitPosition, unsigned numBits)
 
APInt extractBits (unsigned numBits, unsigned bitPosition) const
 Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
 
uint64_t extractBitsAsZExtValue (unsigned numBits, unsigned bitPosition) const
 
unsigned logBase2 () const
 
unsigned ceilLogBase2 () const
 
unsigned nearestLogBase2 () const
 
int32_t exactLogBase2 () const
 
APInt sqrt () const
 Compute the square root.
 
APInt abs () const
 Get the absolute value.
 
APInt multiplicativeInverse (const APInt &modulo) const
 Computes the multiplicative inverse of this APInt for a given modulo.
 
void Profile (FoldingSetNodeID &id) const
 Used to insert APInt objects, or objects that contain APInt objects, into FoldingSets.
 
void dump () const
 debug method
 
bool needsCleanup () const
 Returns whether this instance allocated memory.
 
bool isSingleWord () const
 Determine if this APInt just has one word to store value.
 
bool isNegative () const
 Determine sign of this APInt.
 
bool isNonNegative () const
 Determine if this APInt Value is non-negative (>= 0)
 
bool isSignBitSet () const
 Determine if sign bit of this APInt is set.
 
bool isSignBitClear () const
 Determine if sign bit of this APInt is clear.
 
bool isStrictlyPositive () const
 Determine if this APInt Value is positive.
 
bool isNonPositive () const
 Determine if this APInt Value is non-positive (<= 0).
 
bool isOneBitSet (unsigned BitNo) const
 Determine if this APInt Value only has the specified bit set.
 
bool isAllOnes () const
 Determine if all bits are set. This is true for zero-width values.
 
bool isZero () const
 Determine if this value is zero, i.e. all bits are clear.
 
bool isOne () const
 Determine if this is a value of 1.
 
bool isMaxValue () const
 Determine if this is the largest unsigned value.
 
bool isMaxSignedValue () const
 Determine if this is the largest signed value.
 
bool isMinValue () const
 Determine if this is the smallest unsigned value.
 
bool isMinSignedValue () const
 Determine if this is the smallest signed value.
 
bool isIntN (unsigned N) const
 Check if this APInt has an N-bits unsigned integer value.
 
bool isSignedIntN (unsigned N) const
 Check if this APInt has an N-bits signed integer value.
 
bool isPowerOf2 () const
 Check if this APInt's value is a power of two greater than zero.
 
bool isNegatedPowerOf2 () const
 Check if this APInt's negated value is a power of two greater than zero.
 
bool isAligned (Align A) const
 Checks if this APInt -interpreted as an address- is aligned to the provided value.
 
bool isSignMask () const
 Check if the APInt's value is returned by getSignMask.
 
bool getBoolValue () const
 Convert APInt to a boolean value.
 
uint64_t getLimitedValue (uint64_t Limit=UINT64_MAX) const
 If this value is smaller than the specified limit, return it, otherwise return the limit value.
 
bool isSplat (unsigned SplatSizeInBits) const
 Check if the APInt consists of a repeated bit pattern.
 
bool isMask (unsigned numBits) const
 
bool isMask () const
 
bool isShiftedMask () const
 Return true if this APInt value contains a non-empty sequence of ones with the remainder zero.
 
bool isShiftedMask (unsigned &MaskIdx, unsigned &MaskLen) const
 Return true if this APInt value contains a non-empty sequence of ones with the remainder zero.
 
APInt getHiBits (unsigned numBits) const
 Compute an APInt containing numBits highbits from this APInt.
 
APInt getLoBits (unsigned numBits) const
 Compute an APInt containing numBits lowbits from this APInt.
 
const uint64_tgetRawData () const
 This function returns a pointer to the internal storage of the APInt.
 
APInt operator* (const APInt &RHS) const
 Multiplication operator.
 
APInt operator<< (unsigned Bits) const
 Left logical shift operator.
 
APInt operator<< (const APInt &Bits) const
 Left logical shift operator.
 
APInt ashr (unsigned ShiftAmt) const
 Arithmetic right-shift function.
 
void ashrInPlace (unsigned ShiftAmt)
 Arithmetic right-shift this APInt by ShiftAmt in place.
 
APInt lshr (unsigned shiftAmt) const
 Logical right-shift function.
 
void lshrInPlace (unsigned ShiftAmt)
 Logical right-shift this APInt by ShiftAmt in place.
 
APInt shl (unsigned shiftAmt) const
 Left-shift function.
 
APInt relativeLShr (int RelativeShift) const
 relative logical shift right
 
APInt relativeLShl (int RelativeShift) const
 relative logical shift left
 
APInt relativeAShr (int RelativeShift) const
 relative arithmetic shift right
 
APInt relativeAShl (int RelativeShift) const
 relative arithmetic shift left
 
APInt rotl (unsigned rotateAmt) const
 Rotate left by rotateAmt.
 
APInt rotr (unsigned rotateAmt) const
 Rotate right by rotateAmt.
 
APInt ashr (const APInt &ShiftAmt) const
 Arithmetic right-shift function.
 
void ashrInPlace (const APInt &shiftAmt)
 Arithmetic right-shift this APInt by shiftAmt in place.
 
APInt lshr (const APInt &ShiftAmt) const
 Logical right-shift function.
 
void lshrInPlace (const APInt &ShiftAmt)
 Logical right-shift this APInt by ShiftAmt in place.
 
APInt shl (const APInt &ShiftAmt) const
 Left-shift function.
 
APInt rotl (const APInt &rotateAmt) const
 Rotate left by rotateAmt.
 
APInt rotr (const APInt &rotateAmt) const
 Rotate right by rotateAmt.
 
APInt concat (const APInt &NewLSB) const
 Concatenate the bits from "NewLSB" onto the bottom of *this.
 
APInt udiv (const APInt &RHS) const
 Unsigned division operation.
 
APInt udiv (uint64_t RHS) const
 
APInt sdiv (const APInt &RHS) const
 Signed division function for APInt.
 
APInt sdiv (int64_t RHS) const
 
APInt urem (const APInt &RHS) const
 Unsigned remainder operation.
 
uint64_t urem (uint64_t RHS) const
 
APInt srem (const APInt &RHS) const
 Function for signed remainder operation.
 
int64_t srem (int64_t RHS) const
 
APInt sadd_ov (const APInt &RHS, bool &Overflow) const
 
APInt uadd_ov (const APInt &RHS, bool &Overflow) const
 
APInt ssub_ov (const APInt &RHS, bool &Overflow) const
 
APInt usub_ov (const APInt &RHS, bool &Overflow) const
 
APInt sdiv_ov (const APInt &RHS, bool &Overflow) const
 
APInt smul_ov (const APInt &RHS, bool &Overflow) const
 
APInt umul_ov (const APInt &RHS, bool &Overflow) const
 
APInt sshl_ov (const APInt &Amt, bool &Overflow) const
 
APInt sshl_ov (unsigned Amt, bool &Overflow) const
 
APInt ushl_ov (const APInt &Amt, bool &Overflow) const
 
APInt ushl_ov (unsigned Amt, bool &Overflow) const
 
APInt sfloordiv_ov (const APInt &RHS, bool &Overflow) const
 Signed integer floor division operation.
 
APInt sadd_sat (const APInt &RHS) const
 
APInt uadd_sat (const APInt &RHS) const
 
APInt ssub_sat (const APInt &RHS) const
 
APInt usub_sat (const APInt &RHS) const
 
APInt smul_sat (const APInt &RHS) const
 
APInt umul_sat (const APInt &RHS) const
 
APInt sshl_sat (const APInt &RHS) const
 
APInt sshl_sat (unsigned RHS) const
 
APInt ushl_sat (const APInt &RHS) const
 
APInt ushl_sat (unsigned RHS) const
 
bool operator[] (unsigned bitPosition) const
 Array-indexing support.
 
unsigned getBitWidth () const
 Return the number of bits in the APInt.
 
unsigned getNumWords () const
 Get the number of words.
 
unsigned getActiveBits () const
 Compute the number of active bits in the value.
 
unsigned getActiveWords () const
 Compute the number of active words in the value of this APInt.
 
unsigned getSignificantBits () const
 Get the minimum bit size for this signed APInt.
 
uint64_t getZExtValue () const
 Get zero extended value.
 
std::optional< uint64_ttryZExtValue () const
 Get zero extended value if possible.
 
int64_t getSExtValue () const
 Get sign extended value.
 
std::optional< int64_t > trySExtValue () const
 Get sign extended value if possible.
 
unsigned countl_zero () const
 The APInt version of std::countl_zero.
 
unsigned countLeadingZeros () const
 
unsigned countl_one () const
 Count the number of leading one bits.
 
unsigned countLeadingOnes () const
 
unsigned getNumSignBits () const
 Computes the number of leading bits of this APInt that are equal to its sign bit.
 
unsigned countr_zero () const
 Count the number of trailing zero bits.
 
unsigned countTrailingZeros () const
 
unsigned countr_one () const
 Count the number of trailing one bits.
 
unsigned countTrailingOnes () const
 
unsigned popcount () const
 Count the number of bits set.
 
void print (raw_ostream &OS, bool isSigned) const
 
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.
 
APInt byteSwap () const
 
APInt reverseBits () const
 
double roundToDouble (bool isSigned) const
 Converts this APInt to a double value.
 
double roundToDouble () const
 Converts this unsigned APInt to a double value.
 
double signedRoundToDouble () const
 Converts this signed APInt to a double value.
 
double bitsToDouble () const
 Converts APInt bits to a double.
 
float 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 get (int64_t X)
 
static APSInt getUnsigned (uint64_t X)
 
- Static Public Member Functions inherited from llvm::APInt
static APInt getZero (unsigned numBits)
 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.
 
static APInt getSplat (unsigned NewLen, const APInt &V)
 Return a value containing V broadcasted over NewLen bits.
 
static void tcSet (WordType *, WordType, unsigned)
 Sets the least significant part of a bignum to the input value, and zeroes out higher parts.
 
static void tcAssign (WordType *, const WordType *, unsigned)
 Assign one bignum to another.
 
static bool tcIsZero (const WordType *, unsigned)
 Returns true if a bignum is zero, false otherwise.
 
static int tcExtractBit (const WordType *, unsigned bit)
 Extract the given bit of a bignum; returns 0 or 1. Zero-based.
 
static 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 void tcSetBit (WordType *, unsigned bit)
 Set the given bit of a bignum. Zero-based.
 
static void tcClearBit (WordType *, unsigned bit)
 Clear the given bit of a bignum. Zero-based.
 
static unsigned tcLSB (const WordType *, unsigned n)
 Returns the bit number of the least or most significant set bit of a number.
 
static unsigned tcMSB (const WordType *parts, unsigned n)
 Returns the bit number of the most significant set bit of a number.
 
static void tcNegate (WordType *, unsigned)
 Negate a bignum in-place.
 
static WordType tcAdd (WordType *, const WordType *, WordType carry, unsigned)
 DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
 
static WordType tcAddPart (WordType *, WordType, unsigned)
 DST += RHS. Returns the carry flag.
 
static WordType tcSubtract (WordType *, const WordType *, WordType carry, unsigned)
 DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
 
static WordType tcSubtractPart (WordType *, WordType, unsigned)
 DST -= RHS. Returns the carry flag.
 
static 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 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 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 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 void tcShiftLeft (WordType *, unsigned Words, unsigned Count)
 Shift a bignum left Count bits.
 
static void tcShiftRight (WordType *, unsigned Words, unsigned Count)
 Shift a bignum right Count bits.
 
static 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 void udivrem (const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
 Dual division/remainder interface.
 
static void udivrem (const APInt &LHS, uint64_t RHS, APInt &Quotient, uint64_t &Remainder)
 
static void sdivrem (const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
 
static void sdivrem (const APInt &LHS, int64_t RHS, APInt &Quotient, int64_t &Remainder)
 
static unsigned getNumWords (unsigned BitWidth)
 Get the number of words.
 
static unsigned getBitsNeeded (StringRef str, uint8_t radix)
 Get bits required for string value.
 
static unsigned 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.
 

Additional Inherited Members

- Public Types inherited from llvm::APInt
enum  : unsigned { APINT_WORD_SIZE = sizeof(WordType) , APINT_BITS_PER_WORD = APINT_WORD_SIZE * CHAR_BIT }
 This enum is used to hold the constants we needed for APInt. More...
 
enum class  Rounding { DOWN , TOWARD_ZERO , UP }
 
typedef uint64_t WordType
 
- Static Public Attributes inherited from llvm::APInt
static constexpr WordType WORDTYPE_MAX = ~WordType(0)
 

Detailed Description

An arbitrary precision integer that knows its signedness.

Definition at line 23 of file APSInt.h.

Constructor & Destructor Documentation

◆ APSInt() [1/4]

llvm::APSInt::APSInt ( )
explicitdefault

Default constructor that creates an uninitialized APInt.

Referenced by APSInt().

◆ APSInt() [2/4]

llvm::APSInt::APSInt ( uint32_t  BitWidth,
bool  isUnsigned = true 
)
inlineexplicit

Create an APSInt with the specified width, default to unsigned.

Definition at line 31 of file APSInt.h.

References llvm::BitWidth.

◆ APSInt() [3/4]

llvm::APSInt::APSInt ( APInt  I,
bool  isUnsigned = true 
)
inlineexplicit

Definition at line 34 of file APSInt.h.

References llvm::move().

◆ APSInt() [4/4]

APSInt::APSInt ( StringRef  Str)
explicit

Construct an APSInt from a string representation.

This constructor interprets the string Str using the radix of 10. The interpretation stops at the end of the string. The bit width of the constructed APSInt is determined automatically.

Parameters
Strthe string to be interpreted.

Definition at line 21 of file APSInt.cpp.

References APSInt(), assert(), llvm::APInt::getActiveBits(), llvm::APInt::getSignificantBits(), and llvm::APInt::trunc().

Member Function Documentation

◆ compareValues()

static int llvm::APSInt::compareValues ( const APSInt I1,
const APSInt I2 
)
inlinestatic

Compare underlying values of two numbers.

Definition at line 324 of file APSInt.h.

References assert(), extend(), llvm::APInt::getBitWidth(), isNegative(), and isSigned().

◆ extend()

APSInt llvm::APSInt::extend ( uint32_t  width) const
inline

◆ extOrTrunc()

APSInt llvm::APSInt::extOrTrunc ( uint32_t  width) const
inline

◆ get()

static APSInt llvm::APSInt::get ( int64_t  X)
inlinestatic

Definition at line 349 of file APSInt.h.

References X.

Referenced by llvm::APFixedPoint::toString().

◆ getExtValue()

int64_t llvm::APSInt::getExtValue ( ) const
inline

Get the correctly-extended int64_t value.

Definition at line 98 of file APSInt.h.

References assert(), and isSigned().

◆ getMaxValue()

static APSInt llvm::APSInt::getMaxValue ( uint32_t  numBits,
bool  Unsigned 
)
inlinestatic

Return the APSInt representing the maximum integer value with the given bit width and signedness.

Definition at line 303 of file APSInt.h.

References Unsigned.

Referenced by llvm::APFixedPoint::convertToInt(), llvm::APFixedPoint::getMax(), and llvm::InstCombinerImpl::visitCallInst().

◆ getMinValue()

static APSInt llvm::APSInt::getMinValue ( uint32_t  numBits,
bool  Unsigned 
)
inlinestatic

Return the APSInt representing the minimum integer value with the given bit width and signedness.

Definition at line 311 of file APSInt.h.

References Unsigned.

Referenced by llvm::APFixedPoint::convertToInt(), llvm::APFixedPoint::getMin(), and llvm::InstCombinerImpl::visitCallInst().

◆ getUnsigned()

static APSInt llvm::APSInt::getUnsigned ( uint64_t  X)
inlinestatic

Definition at line 350 of file APSInt.h.

References X.

◆ isNegative()

bool llvm::APSInt::isNegative ( ) const
inline

Determine sign of this APSInt.

Returns
true if this APSInt is negative, false otherwise

Definition at line 49 of file APSInt.h.

References isSigned().

Referenced by compareValues(), llvm::APFixedPoint::convert(), llvm::APFixedPoint::div(), and llvm::APFixedPoint::toString().

◆ isNonNegative()

bool llvm::APSInt::isNonNegative ( ) const
inline

Determine if this APSInt Value is non-negative (>= 0)

Returns
true if this APSInt is non-negative, false otherwise

Definition at line 54 of file APSInt.h.

◆ isRepresentableByInt64()

bool llvm::APSInt::isRepresentableByInt64 ( ) const
inline

If this int is representable using an int64_t.

Definition at line 89 of file APSInt.h.

References llvm::isIntN(), and isSigned().

◆ isSameValue()

static bool llvm::APSInt::isSameValue ( const APSInt I1,
const APSInt I2 
)
inlinestatic

Determine if two APSInts have the same value, zero- or sign-extending as needed.

Definition at line 319 of file APSInt.h.

Referenced by llvm::ConstantFoldExtractElementInstruction().

◆ isSigned()

bool llvm::APSInt::isSigned ( ) const
inline

◆ isStrictlyPositive()

bool llvm::APSInt::isStrictlyPositive ( ) const
inline

Determine if this APSInt Value is positive.

This tests if the value of this APSInt is positive (> 0). Note that 0 is not a positive value.

Returns
true if this APSInt is positive.

Definition at line 62 of file APSInt.h.

References isZero().

◆ isUnsigned()

bool llvm::APSInt::isUnsigned ( ) const
inline

Definition at line 78 of file APSInt.h.

Referenced by llvm::APFixedPoint::getIntPart().

◆ operator!=() [1/2]

bool llvm::APSInt::operator!= ( const APSInt RHS) const
inline

Definition at line 186 of file APSInt.h.

References RHS.

◆ operator!=() [2/2]

bool llvm::APSInt::operator!= ( int64_t  RHS) const
inline

Definition at line 191 of file APSInt.h.

References llvm::get(), and RHS.

◆ operator%()

APSInt llvm::APSInt::operator% ( const APSInt RHS) const
inline

Definition at line 142 of file APSInt.h.

References assert(), and RHS.

◆ operator%=()

const APSInt & llvm::APSInt::operator%= ( const APSInt RHS)
inline

Definition at line 126 of file APSInt.h.

References assert(), and RHS.

◆ operator&()

APSInt llvm::APSInt::operator& ( const APSInt RHS) const
inline

Definition at line 270 of file APSInt.h.

References assert(), and RHS.

◆ operator&=()

APSInt & llvm::APSInt::operator&= ( const APSInt RHS)
inline

Definition at line 254 of file APSInt.h.

References assert(), and RHS.

◆ operator*()

APSInt llvm::APSInt::operator* ( const APSInt RHS) const
inline

Definition at line 285 of file APSInt.h.

References assert(), and RHS.

◆ operator*=()

APSInt & llvm::APSInt::operator*= ( const APSInt RHS)
inline

Definition at line 249 of file APSInt.h.

References assert(), and RHS.

◆ operator+()

APSInt llvm::APSInt::operator+ ( const APSInt RHS) const
inline

Definition at line 289 of file APSInt.h.

References assert(), and RHS.

◆ operator++() [1/2]

APSInt & llvm::APSInt::operator++ ( )
inline

Definition at line 222 of file APSInt.h.

◆ operator++() [2/2]

APSInt llvm::APSInt::operator++ ( int  )
inline

Definition at line 230 of file APSInt.h.

◆ operator+=()

APSInt & llvm::APSInt::operator+= ( const APSInt RHS)
inline

Definition at line 239 of file APSInt.h.

References assert(), and RHS.

◆ operator-() [1/2]

APSInt llvm::APSInt::operator- ( ) const
inline

Definition at line 236 of file APSInt.h.

◆ operator-() [2/2]

APSInt llvm::APSInt::operator- ( const APSInt RHS) const
inline

Definition at line 293 of file APSInt.h.

References assert(), and RHS.

◆ operator--() [1/2]

APSInt & llvm::APSInt::operator-- ( )
inline

Definition at line 226 of file APSInt.h.

◆ operator--() [2/2]

APSInt llvm::APSInt::operator-- ( int  )
inline

Definition at line 233 of file APSInt.h.

◆ operator-=()

APSInt & llvm::APSInt::operator-= ( const APSInt RHS)
inline

Definition at line 244 of file APSInt.h.

References assert(), and RHS.

◆ operator/()

APSInt llvm::APSInt::operator/ ( const APSInt RHS) const
inline

Definition at line 146 of file APSInt.h.

References assert(), and RHS.

◆ operator/=()

const APSInt & llvm::APSInt::operator/= ( const APSInt RHS)
inline

Definition at line 134 of file APSInt.h.

References assert(), and RHS.

◆ operator<() [1/2]

bool llvm::APSInt::operator< ( const APSInt RHS) const
inline

Definition at line 166 of file APSInt.h.

References assert(), and RHS.

◆ operator<() [2/2]

bool llvm::APSInt::operator< ( int64_t  RHS) const
inline

Definition at line 200 of file APSInt.h.

References llvm::get(), and RHS.

◆ operator<<()

APSInt llvm::APSInt::operator<< ( unsigned  Bits) const
inline

Definition at line 210 of file APSInt.h.

◆ operator<<=()

APSInt & llvm::APSInt::operator<<= ( unsigned  Amt)
inline

Definition at line 213 of file APSInt.h.

◆ operator<=() [1/2]

bool llvm::APSInt::operator<= ( const APSInt RHS) const
inline

Definition at line 174 of file APSInt.h.

References assert(), and RHS.

◆ operator<=() [2/2]

bool llvm::APSInt::operator<= ( int64_t  RHS) const
inline

Definition at line 194 of file APSInt.h.

References llvm::get(), and RHS.

◆ operator=() [1/2]

APSInt & llvm::APSInt::operator= ( APInt  RHS)
inline

Definition at line 64 of file APSInt.h.

References RHS.

◆ operator=() [2/2]

APSInt & llvm::APSInt::operator= ( uint64_t  RHS)
inline

Definition at line 70 of file APSInt.h.

References RHS.

◆ operator==() [1/2]

bool llvm::APSInt::operator== ( const APSInt RHS) const
inline

Definition at line 182 of file APSInt.h.

References assert(), and RHS.

◆ operator==() [2/2]

bool llvm::APSInt::operator== ( int64_t  RHS) const
inline

Definition at line 188 of file APSInt.h.

References llvm::get(), and RHS.

◆ operator>() [1/2]

bool llvm::APSInt::operator> ( const APSInt RHS) const
inline

Definition at line 170 of file APSInt.h.

References assert(), and RHS.

◆ operator>() [2/2]

bool llvm::APSInt::operator> ( int64_t  RHS) const
inline

Definition at line 203 of file APSInt.h.

References llvm::get(), and RHS.

◆ operator>=() [1/2]

bool llvm::APSInt::operator>= ( const APSInt RHS) const
inline

Definition at line 178 of file APSInt.h.

References assert(), and RHS.

◆ operator>=() [2/2]

bool llvm::APSInt::operator>= ( int64_t  RHS) const
inline

Definition at line 197 of file APSInt.h.

References llvm::get(), and RHS.

◆ operator>>()

APSInt llvm::APSInt::operator>> ( unsigned  Amt) const
inline

Definition at line 151 of file APSInt.h.

◆ operator>>=()

APSInt & llvm::APSInt::operator>>= ( unsigned  Amt)
inline

Definition at line 154 of file APSInt.h.

◆ operator^()

APSInt llvm::APSInt::operator^ ( const APSInt RHS) const
inline

Definition at line 280 of file APSInt.h.

References assert(), and RHS.

◆ operator^=()

APSInt & llvm::APSInt::operator^= ( const APSInt RHS)
inline

Definition at line 264 of file APSInt.h.

References assert(), and RHS.

◆ operator|()

APSInt llvm::APSInt::operator| ( const APSInt RHS) const
inline

Definition at line 275 of file APSInt.h.

References assert(), and RHS.

◆ operator|=()

APSInt & llvm::APSInt::operator|= ( const APSInt RHS)
inline

Definition at line 259 of file APSInt.h.

References assert(), and RHS.

◆ operator~()

APSInt llvm::APSInt::operator~ ( ) const
inline

Definition at line 297 of file APSInt.h.

◆ Profile()

void APSInt::Profile ( FoldingSetNodeID ID) const

Used to insert APSInt objects, or objects that contain APSInt objects, into FoldingSets.

Definition at line 40 of file APSInt.cpp.

References llvm::APInt::Profile().

◆ relativeShl()

APSInt llvm::APSInt::relativeShl ( unsigned  Amt) const
inline

Definition at line 217 of file APSInt.h.

Referenced by llvm::APFixedPoint::convert(), and llvm::APFixedPoint::getIntPart().

◆ relativeShr()

APSInt llvm::APSInt::relativeShr ( unsigned  Amt) const
inline

Definition at line 161 of file APSInt.h.

◆ setIsSigned()

void llvm::APSInt::setIsSigned ( bool  Val)
inline

Definition at line 80 of file APSInt.h.

Referenced by llvm::APFixedPoint::convert().

◆ setIsUnsigned()

void llvm::APSInt::setIsUnsigned ( bool  Val)
inline

Definition at line 79 of file APSInt.h.

Referenced by llvm::APFixedPoint::toString().

◆ toString() [1/2]

void APInt::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.

Str is commonly a SmallString. If Radix > 10, UpperCase determine the case of letter digits.

Definition at line 1634 of file APInt.cpp.

◆ toString() [2/2]

void llvm::APSInt::toString ( SmallVectorImpl< char > &  Str,
unsigned  Radix = 10 
) const
inline

Append this APSInt to the specified SmallString.

Definition at line 83 of file APSInt.h.

References isSigned().

◆ trunc()

APSInt llvm::APSInt::trunc ( uint32_t  width) const
inline

Definition at line 108 of file APSInt.h.

◆ tryExtValue()

std::optional< int64_t > llvm::APSInt::tryExtValue ( ) const
inline

Definition at line 103 of file APSInt.h.


The documentation for this class was generated from the following files: