LLVM 22.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:
[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)
 
LLVM_ABI 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
 
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.
 
LLVM_ABI APInt (unsigned numBits, ArrayRef< uint64_t > bigVal)
 Construct an APInt of numBits width, initialized as bigVal[].
 
LLVM_ABI 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.
 
LLVM_ABI 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.
 
LLVM_ABI APIntoperator++ ()
 Prefix increment operator.
 
APInt operator-- (int)
 Postfix decrement operator.
 
LLVM_ABI 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.
 
LLVM_ABI APIntoperator*= (const APInt &RHS)
 Multiplication assignment operator.
 
LLVM_ABI APIntoperator*= (uint64_t RHS)
 
LLVM_ABI APIntoperator+= (const APInt &RHS)
 Addition assignment operator.
 
LLVM_ABI APIntoperator+= (uint64_t RHS)
 
LLVM_ABI APIntoperator-= (const APInt &RHS)
 Subtraction assignment operator.
 
LLVM_ABI APIntoperator-= (uint64_t RHS)
 
APIntoperator<<= (unsigned ShiftAmt)
 Left-shift assignment function.
 
LLVM_ABI 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.
 
LLVM_ABI APInt trunc (unsigned width) const
 Truncate to new width.
 
LLVM_ABI APInt truncUSat (unsigned width) const
 Truncate to new width with unsigned saturation.
 
LLVM_ABI APInt truncSSat (unsigned width) const
 Truncate to new width with signed saturation.
 
LLVM_ABI APInt sext (unsigned width) const
 Sign extend to a new width.
 
LLVM_ABI APInt zext (unsigned width) const
 Zero extend to a new width.
 
LLVM_ABI APInt sextOrTrunc (unsigned width) const
 Sign extend or truncate to width.
 
LLVM_ABI 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 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)
 
LLVM_ABI APInt extractBits (unsigned numBits, unsigned bitPosition) const
 Return an APInt with the extracted bits [bitPosition,bitPosition+numBits).
 
LLVM_ABI uint64_t extractBitsAsZExtValue (unsigned numBits, unsigned bitPosition) const
 
unsigned logBase2 () const
 
unsigned ceilLogBase2 () const
 
LLVM_ABI unsigned nearestLogBase2 () const
 
int32_t exactLogBase2 () const
 
LLVM_ABI APInt sqrt () const
 Compute the square root.
 
APInt abs () const
 Get the absolute value.
 
LLVM_ABI APInt 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 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.
 
LLVM_ABI 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.
 
LLVM_ABI 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.
 
LLVM_ABI APInt getHiBits (unsigned numBits) const
 Compute an APInt containing numBits highbits from this APInt.
 
LLVM_ABI 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.
 
LLVM_ABI 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
 
LLVM_ABI APInt rotl (unsigned rotateAmt) const
 Rotate left by rotateAmt.
 
LLVM_ABI APInt rotr (unsigned rotateAmt) const
 Rotate right by rotateAmt.
 
APInt 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.
 
APInt 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.
 
APInt shl (const APInt &ShiftAmt) const
 Left-shift function.
 
LLVM_ABI APInt rotl (const APInt &rotateAmt) const
 Rotate left by rotateAmt.
 
LLVM_ABI 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.
 
LLVM_ABI APInt udiv (const APInt &RHS) const
 Unsigned division operation.
 
LLVM_ABI APInt udiv (uint64_t RHS) const
 
LLVM_ABI APInt sdiv (const APInt &RHS) const
 Signed division function for APInt.
 
LLVM_ABI APInt sdiv (int64_t RHS) const
 
LLVM_ABI APInt urem (const APInt &RHS) const
 Unsigned remainder operation.
 
LLVM_ABI uint64_t urem (uint64_t RHS) const
 
LLVM_ABI APInt srem (const APInt &RHS) const
 Function for signed remainder operation.
 
LLVM_ABI int64_t srem (int64_t RHS) const
 
LLVM_ABI APInt sadd_ov (const APInt &RHS, bool &Overflow) const
 
LLVM_ABI APInt uadd_ov (const APInt &RHS, bool &Overflow) const
 
LLVM_ABI APInt ssub_ov (const APInt &RHS, bool &Overflow) const
 
LLVM_ABI APInt usub_ov (const APInt &RHS, bool &Overflow) const
 
LLVM_ABI APInt sdiv_ov (const APInt &RHS, bool &Overflow) const
 
LLVM_ABI APInt smul_ov (const APInt &RHS, bool &Overflow) const
 
LLVM_ABI APInt umul_ov (const APInt &RHS, bool &Overflow) const
 
LLVM_ABI APInt sshl_ov (const APInt &Amt, bool &Overflow) const
 
LLVM_ABI APInt sshl_ov (unsigned Amt, bool &Overflow) const
 
LLVM_ABI APInt ushl_ov (const APInt &Amt, bool &Overflow) const
 
LLVM_ABI APInt ushl_ov (unsigned Amt, bool &Overflow) const
 
LLVM_ABI APInt sfloordiv_ov (const APInt &RHS, bool &Overflow) const
 Signed integer floor division operation.
 
LLVM_ABI APInt sadd_sat (const APInt &RHS) const
 
LLVM_ABI APInt uadd_sat (const APInt &RHS) const
 
LLVM_ABI APInt ssub_sat (const APInt &RHS) const
 
LLVM_ABI APInt usub_sat (const APInt &RHS) const
 
LLVM_ABI APInt smul_sat (const APInt &RHS) const
 
LLVM_ABI APInt umul_sat (const APInt &RHS) const
 
LLVM_ABI APInt sshl_sat (const APInt &RHS) const
 
LLVM_ABI APInt sshl_sat (unsigned RHS) const
 
LLVM_ABI APInt ushl_sat (const APInt &RHS) const
 
LLVM_ABI 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.
 
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.
 
LLVM_ABI APInt byteSwap () const
 
LLVM_ABI APInt reverseBits () const
 
LLVM_ABI 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 LLVM_ABI APInt 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.
 
static LLVM_ABI bool 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.
 
static LLVM_ABI unsigned tcLSB (const WordType *, unsigned n)
 Returns the bit number of the least or most significant set bit of a number.
 
static LLVM_ABI unsigned 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.
 
static LLVM_ABI WordType tcAdd (WordType *, const WordType *, WordType carry, unsigned)
 DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.
 
static LLVM_ABI WordType tcAddPart (WordType *, WordType, unsigned)
 DST += RHS. Returns the carry flag.
 
static LLVM_ABI WordType tcSubtract (WordType *, const WordType *, WordType carry, unsigned)
 DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.
 
static LLVM_ABI WordType 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.
 
static LLVM_ABI unsigned getBitsNeeded (StringRef str, uint8_t radix)
 Get bits required for string value.
 
static LLVM_ABI 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 class  Rounding { DOWN , TOWARD_ZERO , UP }
 
typedef uint64_t WordType
 
- Static Public Attributes inherited from llvm::APInt
static constexpr unsigned APINT_WORD_SIZE = sizeof(WordType)
 Byte size of a word.
 
static constexpr unsigned APINT_BITS_PER_WORD = APINT_WORD_SIZE * CHAR_BIT
 Bits in a word.
 
static constexpr WordType WORDTYPE_MAX = ~WordType(0)
 

Detailed Description

An arbitrary precision integer that knows its signedness.

Definition at line 24 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 32 of file APSInt.h.

◆ APSInt() [3/4]

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

Definition at line 35 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 325 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 350 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 99 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 304 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 312 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 351 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 50 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 55 of file APSInt.h.

◆ isRepresentableByInt64()

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

If this int is representable using an int64_t.

Definition at line 90 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 320 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 63 of file APSInt.h.

References isZero().

◆ isUnsigned()

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

Definition at line 79 of file APSInt.h.

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

◆ operator!=() [1/2]

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

Definition at line 187 of file APSInt.h.

References RHS.

◆ operator!=() [2/2]

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

Definition at line 192 of file APSInt.h.

References llvm::get(), and RHS.

◆ operator%()

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

Definition at line 143 of file APSInt.h.

References assert(), and RHS.

◆ operator%=()

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

Definition at line 127 of file APSInt.h.

References assert(), and RHS.

◆ operator&()

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

Definition at line 271 of file APSInt.h.

References assert(), and RHS.

◆ operator&=()

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

Definition at line 255 of file APSInt.h.

References assert(), and RHS.

◆ operator*()

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

Definition at line 286 of file APSInt.h.

References assert(), and RHS.

◆ operator*=()

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

Definition at line 250 of file APSInt.h.

References assert(), and RHS.

◆ operator+()

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

Definition at line 290 of file APSInt.h.

References assert(), and RHS.

◆ operator++() [1/2]

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

Definition at line 223 of file APSInt.h.

◆ operator++() [2/2]

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

Definition at line 231 of file APSInt.h.

◆ operator+=()

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

Definition at line 240 of file APSInt.h.

References assert(), and RHS.

◆ operator-() [1/2]

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

Definition at line 237 of file APSInt.h.

◆ operator-() [2/2]

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

Definition at line 294 of file APSInt.h.

References assert(), and RHS.

◆ operator--() [1/2]

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

Definition at line 227 of file APSInt.h.

◆ operator--() [2/2]

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

Definition at line 234 of file APSInt.h.

◆ operator-=()

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

Definition at line 245 of file APSInt.h.

References assert(), and RHS.

◆ operator/()

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

Definition at line 147 of file APSInt.h.

References assert(), and RHS.

◆ operator/=()

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

Definition at line 135 of file APSInt.h.

References assert(), and RHS.

◆ operator<() [1/2]

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

Definition at line 167 of file APSInt.h.

References assert(), and RHS.

◆ operator<() [2/2]

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

Definition at line 201 of file APSInt.h.

References llvm::get(), and RHS.

◆ operator<<()

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

Definition at line 211 of file APSInt.h.

◆ operator<<=()

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

Definition at line 214 of file APSInt.h.

◆ operator<=() [1/2]

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

Definition at line 175 of file APSInt.h.

References assert(), and RHS.

◆ operator<=() [2/2]

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

Definition at line 195 of file APSInt.h.

References llvm::get(), and RHS.

◆ operator=() [1/2]

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

Definition at line 65 of file APSInt.h.

References RHS.

◆ operator=() [2/2]

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

Definition at line 71 of file APSInt.h.

References RHS.

◆ operator==() [1/2]

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

Definition at line 183 of file APSInt.h.

References assert(), and RHS.

◆ operator==() [2/2]

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

Definition at line 189 of file APSInt.h.

References llvm::get(), and RHS.

◆ operator>() [1/2]

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

Definition at line 171 of file APSInt.h.

References assert(), and RHS.

◆ operator>() [2/2]

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

Definition at line 204 of file APSInt.h.

References llvm::get(), and RHS.

◆ operator>=() [1/2]

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

Definition at line 179 of file APSInt.h.

References assert(), and RHS.

◆ operator>=() [2/2]

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

Definition at line 198 of file APSInt.h.

References llvm::get(), and RHS.

◆ operator>>()

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

Definition at line 152 of file APSInt.h.

◆ operator>>=()

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

Definition at line 155 of file APSInt.h.

◆ operator^()

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

Definition at line 281 of file APSInt.h.

References assert(), and RHS.

◆ operator^=()

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

Definition at line 265 of file APSInt.h.

References assert(), and RHS.

◆ operator|()

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

Definition at line 276 of file APSInt.h.

References assert(), and RHS.

◆ operator|=()

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

Definition at line 260 of file APSInt.h.

References assert(), and RHS.

◆ operator~()

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

Definition at line 298 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 218 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 162 of file APSInt.h.

◆ setIsSigned()

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

Definition at line 81 of file APSInt.h.

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

◆ setIsUnsigned()

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

Definition at line 80 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 1684 of file APInt.cpp.

References RHS.

◆ 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 84 of file APSInt.h.

References isSigned().

◆ trunc()

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

Definition at line 109 of file APSInt.h.

◆ tryExtValue()

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

Definition at line 104 of file APSInt.h.


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