llvm::APInt

Arbitrary-precision integer.

Synopsis

Declared in <llvm/ADT/APInt.h>

class [[nodiscard]] APInt;

Type Aliases

NameDescription
WordType Native limb type used to store APInt words.

Enums

NameDescription
Rounding Rounding mode for converting floating-point values to APInt.

Member Functions

NameDescription
APInt [constructor]Constructors
~APInt [destructor]Destructor.
operator= Assignment operators
Profile Profile this APInt into a FoldingSet node ID.
abs Return the absolute value of this APInt.
ashr Arithmetic right-shift function.
ashrInPlace ashrInPlace overloads
bitsToDouble Converts APInt bits to a double
bitsToFloat Converts APInt bits to a float
bitsToQuad
byteSwap Return a byte-swapped representation of this APInt.
ceilLogBase2 Return the ceil of the log base 2 of this APInt.
clearAllBits Set every bit to 0.
clearBit Clear the bit at BitPosition.
clearBits Clear bits from LoBit (inclusive) to HiBit (exclusive).
clearHighBits Clear the top hiBits bits.
clearLowBits Clear the bottom loBits bits.
clearSignBit Set the sign bit to 0.
concat Concatenate the bits from NewLSB onto the bottom of *this.
countLeadingOnes Alias for countl_one().
countLeadingZeros Alias for countl_zero().
countTrailingOnes Alias for countr_one().
countTrailingZeros Alias for countr_zero().
countl_one Count the number of leading one bits.
countl_zero The APInt version of std::countl_zero.
countr_one Count the number of trailing one bits.
countr_zero Count the number of trailing zero bits.
dump debug method
eq Equality comparison.
exactLogBase2 Return log base 2 if this APInt is an exact power of two, otherwise -1.
extractBits Return an APInt with bits [bitPosition, bitPosition+numBits).]
extractBitsAsZExtValue Extract bits as a zero-extended 64-bit value.
flipAllBits Toggle every bit to its opposite value.
flipBit Toggle the bit at bitPosition to its opposite value.
getActiveBits Compute the number of active bits in the value
getActiveWords Compute the number of active words in the value of this APInt.
getBitWidth Return the number of bits in the APInt.
getBoolValue Convert APInt to a boolean value.
getHiBits Compute an APInt containing numBits high bits from this APInt.
getLimitedValue Return this value, or Limit if this value is larger.
getLoBits Compute an APInt containing numBits low bits from this APInt.
getNumSignBits Computes the number of leading bits of this APInt that are equal to its sign bit.
getNumWords Get the number of words.
getRawData This function returns a pointer to the internal storage of the APInt. This is useful for writing out the APInt in binary form without any conversions.
getSExtValue Get sign extended value
getSignificantBits Get the minimum bit size for this signed APInt
getZExtValue Get zero extended value
insertBits insertBits overloads
intersects Return true if any corresponding bits are set in both this and RHS.
isAligned Return true if this APInt, interpreted as an address, is aligned to A.
isAllOnes Determine if all bits are set. This is true for zero-width values.
isIntN Check if this APInt has an N-bit unsigned integer value.
isInverseOf Return true if every bit is set in exactly one of this or RHS.
isMask isMask overloads
isMaxSignedValue Determine if this is the largest signed value.
isMaxValue Determine if this is the largest unsigned value.
isMinSignedValue Determine if this is the smallest signed value.
isMinValue Determine if this is the smallest unsigned value.
isNegatedPowerOf2 Check if this APInt's negated value is a power of two greater than zero.
isNegative Determine sign of this APInt.
isNonNegative Determine if this APInt Value is non-negative (>= 0)
isNonPositive Determine if this APInt Value is non-positive (<= 0).
isOne Determine if this is a value of 1.
isOneBitSet Determine if this APInt Value only has the specified bit set.
isPowerOf2 Check if this APInt's value is a power of two greater than zero.
isShiftedMask isShiftedMask overloads
isSignBitClear Determine if sign bit of this APInt is clear.
isSignBitSet Determine if sign bit of this APInt is set.
isSignMask Check if the APInt's value is returned by getSignMask.
isSignedIntN Check if this APInt has an N-bit signed integer value.
isSingleWord Determine if this APInt just has one word to store value.
isSplat Check if the APInt consists of a repeated bit pattern.
isStrictlyPositive Determine if this APInt Value is positive.
isSubsetOf Return true if every bit set in this APInt is also set in RHS.
isZero Determine if this value is zero, i.e. all bits are clear.
logBase2 Return the floor of the log base 2 of this APInt.
lshr Logical right-shift function.
lshrInPlace Logical right-shift this APInt by ShiftAmt in place.
multiplicativeInverse Return the multiplicative inverse of an odd APInt modulo 2^BitWidth.
ne Inequality comparison.
nearestLogBase2 NOTE: When we have a BitWidth of 1, we define:
needsCleanup Returns whether this instance allocated memory.
negate Negate this APInt in place.
operator&= Bitwise AND assignment operator.
operator* Multiplication operator.
operator*= Multiplication assignment operators
operator++ Increment operators
operator+= Addition assignment operators
operator-- Decrement operators
operator-= Subtraction assignment operators
operator<<= Left-shift assignment function.
operator[] Array-indexing support for individual bits.
operator^= Bitwise XOR assignment operator.
operator|= Bitwise OR assignment operator.
popcount Count the number of bits set.
print Print this APInt to a stream.
relativeAShl Relative arithmetic shift left (negative amounts shift right).
relativeAShr Relative arithmetic shift right (negative amounts shift left).
relativeLShl Relative logical shift left (negative amounts shift right).
relativeLShr Relative logical shift right (negative amounts shift left).
reverseBits Return this APInt with its bit representation reversed.
rotl Rotate left by rotateAmt.
rotr Rotate right by rotateAmt.
roundToDouble roundToDouble overloads
sadd_ov Operations that return overflow indicators. Signed add that records whether the result overflowed.
sadd_sat Operations that saturate on overflow. Signed add saturating to the signed min/max of the bit width.
sdiv sdiv overloads
sdiv_ov Signed divide that records whether the result overflowed.
setAllBits Set every bit to 1.
setBit Set the bit at BitPosition to 1.
setBitVal Set the bit at BitPosition to BitValue.
setBits Set bits from loBit (inclusive) to hiBit (exclusive).
setBitsFrom Set all bits from loBit through the top of the value.
setBitsWithWrap Set bits from loBit to hiBit, wrapping if loBit >= hiBit.
setHighBits Set the top hiBits bits.
setLowBits Set the bottom loBits bits.
setSignBit Set the sign bit to 1.
sext Sign-extend to a new width.
sextOrTrunc Sign-extend or truncate to width.
sfloordiv_ov Signed integer floor division that records overflow.
sge Signed greater or equal comparison
sgt Signed greater than comparison
shl Left-shift function.
signedRoundToDouble Converts this signed APInt to a double value.
sle Signed less or equal comparison
slt Signed less than comparison
smul_ov Signed multiply that records whether the result overflowed.
smul_sat Signed multiply saturating to the signed min/max of the bit width.
sqrtFloor Compute the floor of the square root of the unsigned value.
srem srem overloads
sshl_ov sshl_ov overloads
sshl_sat sshl_sat overloads
ssub_ov Signed subtract that records whether the result overflowed.
ssub_sat Signed subtract saturating to the signed min/max of the bit width.
toString Convert this APInt to a string and append it to Str.
toStringSigned Convert this APInt as signed into a string in the given radix.
toStringUnsigned Convert this APInt as unsigned into a string in the given radix.
trunc Truncate to a new width.
truncSSat Truncate to a new width with signed saturation to a signed result.
truncSSatU Truncate to a new width with signed saturation to an unsigned result.
truncUSat Truncate to a new width with unsigned saturation.
trySExtValue Get sign extended value if possible
tryZExtValue Get zero extended value if possible
uadd_ov Unsigned add that records whether the result overflowed.
uadd_sat Unsigned add saturating to the unsigned max of the bit width.
udiv udiv overloads
uge Unsigned greater or equal comparison
ugt Unsigned greater than comparison
ule Unsigned less or equal comparison
ult Unsigned less than comparison
umul_ov Unsigned multiply that records whether the result overflowed.
umul_sat Unsigned multiply saturating to the unsigned max of the bit width.
urem urem overloads
ushl_ov ushl_ov overloads
ushl_sat ushl_sat overloads
usub_ov Unsigned subtract that records whether the result overflowed.
usub_sat Unsigned subtract saturating at zero.
zext Zero-extend to a new width.
zextOrTrunc Zero-extend or truncate to width.
operator<< Left logical shift operator.
operator! Logical negation operation on this APInt returns true if zero, like normal integers.
operator== Equality operator.
operator!= Inequality operator.

Static Member Functions

NameDescription
doubleToBits Reinterpret the bits of a double as an APInt.
floatToBits Reinterpret the bits of a float as an APInt.
getAllOnes Return an APInt of a specified width with all bits set.
getBitsNeeded Determine how many bits are required to hold the value of a string.
getBitsSet Get a value with a block of bits set.
getBitsSetFrom Construct an APInt with bits set from loBit to the top of the value.
getBitsSetWithWrap Construct an APInt with a possibly wrapping contiguous range of bits set.
getHighBitsSet Constructs an APInt value that has the top hiBitsSet bits set.
getLowBitsSet Constructs an APInt value that has the bottom loBitsSet bits set.
getMaxValue Gets maximum unsigned value of APInt for specific bit width.
getMinValue Gets minimum unsigned value of APInt for a specific bit width.
getNumWords Get the number of words needed for a given bit width.
getOneBitSet Return an APInt with exactly one bit set in the result.
getSignMask Get the SignMask for a specific bit width.
getSignedMaxValue Gets maximum signed value of APInt for a specific bit width.
getSignedMinValue Gets minimum signed value of APInt for a specific bit width.
getSplat Return a value containing V broadcasted over NewLen bits.
getSufficientBitsNeeded Estimate bits needed for a string without fully parsing it.
getZero Get the '0' value for the specified bit-width.
getZeroWidth Return an APInt zero bits wide.
isSameValue Return true if two APInts have the same numeric value after matching widths.
sdivrem sdivrem overloads
tcAdd Add two bignums with an incoming carry and return the outgoing carry.
tcAddPart Add a single limb to a bignum and return the carry flag.
tcAssign Assign one bignum to another.
tcClearBit Clear the given zero-based bit of a bignum.
tcCompare Compare two bignums as unsigned values.
tcDecrement Decrement a bignum in-place and return the borrow flag.
tcDivide Divide bignums: set lhs to quotient and remainder to the remainder.
tcExtract Extract a contiguous bit-field from one bignum into another.
tcExtractBit Extract the given zero-based bit of a bignum; returns 0 or 1.
tcFullMultiply Multiply two bignums into a full-width (sum of widths) destination.
tcIncrement Increment a bignum in-place and return the carry flag.
tcIsZero Return true if a bignum is zero.
tcLSB Return the bit index of the least significant set bit in a bignum.
tcMSB Return the bit index of the most significant set bit in parts.
tcMultiply Multiply two equal-width bignums into a same-width destination.
tcMultiplyPart Multiply a bignum by a single limb, optionally adding into the destination.
tcNegate Negate a bignum in place (two's complement).
tcSet Set the least significant limb of a bignum and zero higher limbs.
tcSetBit Set the given zero-based bit of a bignum.
tcShiftLeft Shift a bignum left by Count bits; shifted-in bits are zero.
tcShiftRight Shift a bignum right by Count bits; shifted-in bits are zero.
tcSubtract Subtract a bignum plus carry from another and return the borrow flag.
tcSubtractPart Subtract a single limb from a bignum and return the borrow flag.
udivrem udivrem overloads

Static Data Members

NameDescription
APINT_BITS_PER_WORD Bits in a word.
APINT_WORD_SIZE Byte size of a word.
WORDTYPE_MAX Maximum value representable in a single WordType limb.

Friends

NameDescription
llvm::DynamicAPIntDynamically sized arbitrary-precision integer.
llvm::APSIntAn arbitrary precision integer that knows its signedness.
llvm::DenseMapInfo<APInt, void>Provide DenseMapInfo for APInt.
llvm::hash_valueOverload to compute a hash_code for an APInt value.

Non-Member Functions

NameDescription
ConstantFoldBinOpConstant-fold a generic integer binary opcode on two register operands.
ConstantFoldCastOpConstant-fold a generic cast opcode producing an integer result.
ConstantFoldExtOpConstant-fold a generic extend opcode with an immediate second operand.
ConstantFoldUnaryIntOpConstant-fold a unary integer operation on Src.
ConstantFoldVectorBinopTries to constant fold a vector binop with sources Op1 and Op2. Returns an empty vector on failure.
LoadIntFromMemoryLoad LoadBytes bytes from Src into IntVal.
StoreIntToMemoryFill StoreBytes bytes of memory starting at Dst with IntVal.
getAllocSizeReturn the size of the requested allocation.
getIConstantFromRegVReg is defined by a G_CONSTANT, return the corresponding value.
getIConstantSplatValReturn the scalar integral splat value defined by MI if possible.
getIConstantSplatValReturn the scalar integral splat value of Reg if possible.
getIConstantVRegValIf VReg is defined by a G_CONSTANT, return the corresponding value.
getMinMaxLimitReturn the minimum or maximum constant value for the specified integer min/max flavor and type.
isConstantOrConstantSplatVectorDetermines if Def defines a constant integer or a splat vector of constant integers.
operator&Bitwise AND of two APInts.
operator&Bitwise AND of a 64-bit value and an APInt.
operator&Bitwise AND that prefers moving from b.
operator&Bitwise AND of an APInt and a 64-bit value.
operator*Multiply an APInt by a 64-bit value.
operator*Multiply a 64-bit value by an APInt.
operator+Add two APInts.
operator+Add an APInt and a 64-bit value.
operator+Add that prefers moving from b.
operator+Add a 64-bit value and an APInt.
operator-Subtract an APInt from a 64-bit value.
operator-Negate an APInt.
operator-Subtract that prefers moving from b.
operator-Subtract a 64-bit value from an APInt.
operator-Subtract two APInts.
operator^Bitwise XOR of two APInts.
operator^Bitwise XOR of an APInt and a 64-bit value.
operator^Bitwise XOR that prefers moving from b.
operator^Bitwise XOR of a 64-bit value and an APInt.
operator|Bitwise OR of an APInt and a 64-bit value.
operator|Bitwise OR of a 64-bit value and an APInt.
operator|Bitwise OR of two APInts.
operator|Bitwise OR that prefers moving from b.
operator~Unary bitwise complement operator.
possiblyDemandedEltsInMaskReturn an APInt of active lanes for a <Y x i1> mask.
readWideAPIntDecode a wide APInt from a sequence of 64-bit words.
toStringConvert an APInt to a std::string in the given radix.
AArch64::getCpuSupportsMaskCompute the CPU-supports bitmask for the given FMV feature names.
AArch64::getFMVPriorityCompute the FMV priority bitmask for the given feature names.
APIntOps::GetMostSignificantDifferentBitReturn the index of the most significant bit that differs between two values.
APIntOps::GreatestCommonDivisorCompute the GCD of two APInt values using Stein's algorithm.
APIntOps::RoundAPIntToDoubleConvert APIVal to a double, treating it as unsigned.
APIntOps::RoundAPIntToFloatConvert APIVal to a float, treating it as unsigned.
APIntOps::RoundDoubleToAPIntConvert a double value to an APInt of the given width.
APIntOps::RoundFloatToAPIntConvert a float value to an APInt of the given width.
APIntOps::RoundSignedAPIntToDoubleConvert APIVal to a double, treating it as signed.
APIntOps::RoundSignedAPIntToFloatConvert APIVal to a float, treating it as signed.
APIntOps::RoundingSDivReturn A signed-divided by B, rounded by RM.
APIntOps::RoundingUDivReturn A unsigned-divided by B, rounded by RM.
APIntOps::ScaleBitMaskSplat/merge neighboring bits to widen or narrow the bitmask in A.
APIntOps::SolveQuadraticEquationWrapFind the smallest n where quadratic q(n) = An^2 + Bn + C wraps the value range.
APIntOps::abdsDetermine the absolute difference of two APInts considered to be signed.
APIntOps::abduDetermine the absolute difference of two APInts considered to be unsigned.
APIntOps::avgCeilSCompute the ceil of the signed average of C1 and C2.
APIntOps::avgCeilUCompute the ceil of the unsigned average of C1 and C2.
APIntOps::avgFloorSCompute the floor of the signed average of C1 and C2.
APIntOps::avgFloorUCompute the floor of the unsigned average of C1 and C2.
APIntOps::clmulPerform a carry-less multiply, also known as XOR multiplication, and return low-bits. All arguments and result have the same bitwidth.
APIntOps::clmulhPerform a carry-less multiply, and return high-bits. All arguments and result have the same bitwidth.
APIntOps::clmulrPerform a reversed carry-less multiply.
APIntOps::fshlPerform a funnel shift left.
APIntOps::fshrPerform a funnel shift right.
APIntOps::mulhsMultiply sign-extended operands and return the high N bits of the product.
APIntOps::mulhuMultiply zero-extended operands and return the high N bits of the product.
APIntOps::mulsExtendedMultiply sign-extended operands and return the full 2N-bit product.
APIntOps::muluExtendedMultiply zero-extended operands and return the full 2N-bit product.
APIntOps::pdepPerform an "expand" operation, also known as pdep or bdep.
APIntOps::pextPerform a "compress" operation, also known as pext or bext.
APIntOps::powCompute X raised to the power N for N >= 0.
APIntOps::smaxDetermine the larger of two APInts considered to be signed.
APIntOps::sminDetermine the smaller of two APInts considered to be signed.
APIntOps::umaxDetermine the larger of two APInts considered to be unsigned.
APIntOps::uminDetermine the smaller of two APInts considered to be unsigned.
MIPatternMatch::m_GConstantOrFConstantBitsMatches a literal G_CONSTANT or G_FCONSTANT, binding raw bits to Bits.
MIPatternMatch::m_ICstMatches an integer constant, binding an APInt to Cst.
MIPatternMatch::m_ICstOrSplatMatches an integer constant or splat, binding an APInt to Cst.
MIPatternMatch::m_SpecificICstMatches a constant equal to RequestedValue.
MIPatternMatch::m_SpecificICstOrSplatMatches RequestedValue or a constant splat of that value.
MIPatternMatch::m_SpecificICstSplatMatches a constant splat of RequestedValue.
MIPatternMatch::matchConstantMatch Reg as an APInt integer constant.
MIPatternMatch::matchConstantSplatMatch Reg as an APInt constant splat.
PatternMatch::m_APIntMatch a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
PatternMatch::m_APIntAllowPoisonMatch APInt while allowing poison in splat vector constants.
PatternMatch::m_APIntForbidPoisonMatch APInt while forbidding poison in splat vector constants.
PatternMatch::m_LowBitMaskMatch a low-bit-mask constant and bind the APInt.
PatternMatch::m_LowBitMaskOrZeroMatch a zero or low-bit-mask constant and bind the APInt.
PatternMatch::m_MaxSignedValueMatch a max-signed-value constant and bind the APInt.
PatternMatch::m_NegatedPower2Match a negated power-of-two constant and bind the APInt.
PatternMatch::m_NegatedPower2OrZeroMatch a zero or negated power-of-two constant and bind the APInt.
PatternMatch::m_NegativeMatch a negative constant and bind the APInt.
PatternMatch::m_NonNegativeMatch a non-negative constant and bind the APInt.
PatternMatch::m_NonPositiveMatch a non-positive constant and bind the APInt.
PatternMatch::m_Power2Match a power-of-two constant and bind the APInt.
PatternMatch::m_Power2OrZeroMatch a zero or power-of-two constant and bind the APInt.
PatternMatch::m_SpecificIntMatch a specific integer value or vector with all elements equal to the value.
PatternMatch::m_SpecificIntAllowPoisonMatch a specific integer allowing poison in splat vectors.
PatternMatch::m_StrictlyPositiveMatch a strictly positive constant and bind the APInt.
SCEVPatternMatch::m_scev_APIntMatch an SCEV constant and bind it to an APInt.
SDPatternMatch::m_ConstIntMatch any integer constants or splat of an integer constant; return the specific constant or constant splat value.
SDPatternMatch::m_SpecificIntMatch a specific integer constant or constant splat value.

Derived Classes

NameDescription
APSInt An arbitrary precision integer that knows its signedness.

Return Value

NOTE

The return value should not be discarded.