LLVM  13.0.0git
Classes | Public Types | Static Public Attributes | Friends | List of all members
llvm::APInt Class Reference

Class for arbitrary precision integers. More...

#include "llvm/ADT/APInt.h"

Inheritance diagram for llvm::APInt:
Inheritance graph
[legend]
Collaboration diagram for llvm::APInt:
Collaboration graph
[legend]

Classes

struct  ms
 Magic data for optimising signed division by a constant. More...
 
struct  mu
 Magic data for optimising unsigned division by a constant. More...
 

Public Types

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  Rounding { Rounding::DOWN, Rounding::TOWARD_ZERO, Rounding::UP }
 
typedef uint64_t WordType
 

Public Member Functions

Constructors
 APInt (unsigned numBits, uint64_t val, bool isSigned=false)
 Create a new APInt of numBits width, initialized as val. More...
 
 APInt (unsigned numBits, ArrayRef< uint64_t > bigVal)
 Construct an APInt of numBits width, initialized as bigVal[]. More...
 
 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. More...
 
 APInt (unsigned numBits, StringRef str, uint8_t radix)
 Construct an APInt from a string representation. More...
 
 APInt (const APInt &that)
 Simply makes *this a copy of that. More...
 
 APInt (APInt &&that)
 Move Constructor. More...
 
 ~APInt ()
 Destructor. More...
 
 APInt ()
 Default constructor that creates an uninteresting APInt representing a 1-bit zero value. More...
 
bool needsCleanup () const
 Returns whether this instance allocated memory. More...
 
void Profile (FoldingSetNodeID &id) const
 Used to insert APInt objects, or objects that contain APInt objects, into FoldingSets. More...
 
Value Tests
bool isNegative () const
 Determine sign of this APInt. More...
 
bool isNonNegative () const
 Determine if this APInt Value is non-negative (>= 0) More...
 
bool isSignBitSet () const
 Determine if sign bit of this APInt is set. More...
 
bool isSignBitClear () const
 Determine if sign bit of this APInt is clear. More...
 
bool isStrictlyPositive () const
 Determine if this APInt Value is positive. More...
 
bool isNonPositive () const
 Determine if this APInt Value is non-positive (<= 0). More...
 
bool isAllOnesValue () const
 Determine if all bits are set. More...
 
bool isNullValue () const
 Determine if all bits are clear. More...
 
bool isOneValue () const
 Determine if this is a value of 1. More...
 
bool isMaxValue () const
 Determine if this is the largest unsigned value. More...
 
bool isMaxSignedValue () const
 Determine if this is the largest signed value. More...
 
bool isMinValue () const
 Determine if this is the smallest unsigned value. More...
 
bool isMinSignedValue () const
 Determine if this is the smallest signed value. More...
 
bool isIntN (unsigned N) const
 Check if this APInt has an N-bits unsigned integer value. More...
 
bool isSignedIntN (unsigned N) const
 Check if this APInt has an N-bits signed integer value. More...
 
bool isPowerOf2 () const
 Check if this APInt's value is a power of two greater than zero. More...
 
bool isSignMask () const
 Check if the APInt's value is returned by getSignMask. More...
 
bool getBoolValue () const
 Convert APInt to a boolean value. More...
 
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. More...
 
bool isSplat (unsigned SplatSizeInBits) const
 Check if the APInt consists of a repeated bit pattern. More...
 
bool isMask (unsigned numBits) const
 
bool isMask () const
 
bool isShiftedMask () const
 Return true if this APInt value contains a sequence of ones with the remainder zero. More...
 
Unary Operators
const APInt operator++ (int)
 Postfix increment operator. More...
 
APIntoperator++ ()
 Prefix increment operator. More...
 
const APInt operator-- (int)
 Postfix decrement operator. More...
 
APIntoperator-- ()
 Prefix decrement operator. More...
 
bool operator! () const
 Logical negation operator. More...
 
Assignment Operators
APIntoperator= (const APInt &RHS)
 Copy assignment operator. More...
 
APIntoperator= (APInt &&that)
 Move assignment operator. More...
 
APIntoperator= (uint64_t RHS)
 Assignment operator. More...
 
APIntoperator&= (const APInt &RHS)
 Bitwise AND assignment operator. More...
 
APIntoperator&= (uint64_t RHS)
 Bitwise AND assignment operator. More...
 
APIntoperator|= (const APInt &RHS)
 Bitwise OR assignment operator. More...
 
APIntoperator|= (uint64_t RHS)
 Bitwise OR assignment operator. More...
 
APIntoperator^= (const APInt &RHS)
 Bitwise XOR assignment operator. More...
 
APIntoperator^= (uint64_t RHS)
 Bitwise XOR assignment operator. More...
 
APIntoperator*= (const APInt &RHS)
 Multiplication assignment operator. More...
 
APIntoperator*= (uint64_t RHS)
 
APIntoperator+= (const APInt &RHS)
 Addition assignment operator. More...
 
APIntoperator+= (uint64_t RHS)
 
APIntoperator-= (const APInt &RHS)
 Subtraction assignment operator. More...
 
APIntoperator-= (uint64_t RHS)
 
APIntoperator<<= (unsigned ShiftAmt)
 Left-shift assignment function. More...
 
APIntoperator<<= (const APInt &ShiftAmt)
 Left-shift assignment function. More...
 
Comparison Operators
bool operator== (const APInt &RHS) const
 Equality operator. More...
 
bool operator== (uint64_t Val) const
 Equality operator. More...
 
bool eq (const APInt &RHS) const
 Equality comparison. More...
 
bool operator!= (const APInt &RHS) const
 Inequality operator. More...
 
bool operator!= (uint64_t Val) const
 Inequality operator. More...
 
bool ne (const APInt &RHS) const
 Inequality comparison. More...
 
bool ult (const APInt &RHS) const
 Unsigned less than comparison. More...
 
bool ult (uint64_t RHS) const
 Unsigned less than comparison. More...
 
bool slt (const APInt &RHS) const
 Signed less than comparison. More...
 
bool slt (int64_t RHS) const
 Signed less than comparison. More...
 
bool ule (const APInt &RHS) const
 Unsigned less or equal comparison. More...
 
bool ule (uint64_t RHS) const
 Unsigned less or equal comparison. More...
 
bool sle (const APInt &RHS) const
 Signed less or equal comparison. More...
 
bool sle (uint64_t RHS) const
 Signed less or equal comparison. More...
 
bool ugt (const APInt &RHS) const
 Unsigned greater than comparison. More...
 
bool ugt (uint64_t RHS) const
 Unsigned greater than comparison. More...
 
bool sgt (const APInt &RHS) const
 Signed greater than comparison. More...
 
bool sgt (int64_t RHS) const
 Signed greater than comparison. More...
 
bool uge (const APInt &RHS) const
 Unsigned greater or equal comparison. More...
 
bool uge (uint64_t RHS) const
 Unsigned greater or equal comparison. More...
 
bool sge (const APInt &RHS) const
 Signed greater or equal comparison. More...
 
bool sge (int64_t RHS) const
 Signed greater or equal comparison. More...
 
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. More...
 
bool isSubsetOf (const APInt &RHS) const
 This operation checks that all bits set in this APInt are also set in RHS. More...
 
Resizing Operators
APInt trunc (unsigned width) const
 Truncate to new width. More...
 
APInt truncUSat (unsigned width) const
 Truncate to new width with unsigned saturation. More...
 
APInt truncSSat (unsigned width) const
 Truncate to new width with signed saturation. More...
 
APInt sext (unsigned width) const
 Sign extend to a new width. More...
 
APInt zext (unsigned width) const
 Zero extend to a new width. More...
 
APInt sextOrTrunc (unsigned width) const
 Sign extend or truncate to width. More...
 
APInt zextOrTrunc (unsigned width) const
 Zero extend or truncate to width. More...
 
APInt truncOrSelf (unsigned width) const
 Truncate to width. More...
 
APInt sextOrSelf (unsigned width) const
 Sign extend or truncate to width. More...
 
APInt zextOrSelf (unsigned width) const
 Zero extend or truncate to width. More...
 
Bit Manipulation Operators
void setAllBits ()
 Set every bit to 1. More...
 
void setBit (unsigned BitPosition)
 Set a given bit to 1. More...
 
void setSignBit ()
 Set the sign bit to 1. More...
 
void setBitVal (unsigned BitPosition, bool BitValue)
 Set a given bit to a given value. More...
 
void setBitsWithWrap (unsigned loBit, unsigned hiBit)
 Set the bits from loBit (inclusive) to hiBit (exclusive) to 1. More...
 
void setBits (unsigned loBit, unsigned hiBit)
 Set the bits from loBit (inclusive) to hiBit (exclusive) to 1. More...
 
void setBitsFrom (unsigned loBit)
 Set the top bits starting from loBit. More...
 
void setLowBits (unsigned loBits)
 Set the bottom loBits bits. More...
 
void setHighBits (unsigned hiBits)
 Set the top hiBits bits. More...
 
void clearAllBits ()
 Set every bit to 0. More...
 
void clearBit (unsigned BitPosition)
 Set a given bit to 0. More...
 
void clearLowBits (unsigned loBits)
 Set bottom loBits bits to 0. More...
 
void clearSignBit ()
 Set the sign bit to 0. More...
 
void flipAllBits ()
 Toggle every bit to its opposite value. More...
 
void flipBit (unsigned bitPosition)
 Toggles a given bit to its opposite value. More...
 
void negate ()
 Negate this APInt in place. More...
 
void insertBits (const APInt &SubBits, unsigned bitPosition)
 Insert the bits from a smaller APInt starting at bitPosition. More...
 
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). More...
 
uint64_t extractBitsAsZExtValue (unsigned numBits, unsigned bitPosition) const
 
Mathematics Operations
unsigned logBase2 () const
 
unsigned ceilLogBase2 () const
 
unsigned nearestLogBase2 () const
 
int32_t exactLogBase2 () const
 
APInt sqrt () const
 Compute the square root. More...
 
APInt abs () const
 Get the absolute value;. More...
 
APInt multiplicativeInverse (const APInt &modulo) const
 Computes the multiplicative inverse of this APInt for a given modulo. More...
 
Support for division by constant
ms magic () const
 Calculate the magic numbers required to implement a signed integer division by a constant as a sequence of multiplies, adds and shifts. More...
 
mu magicu (unsigned LeadingZeros=0) const
 Calculate the magic numbers required to implement an unsigned integer division by a constant as a sequence of multiplies, adds and shifts. More...
 

Static Public Attributes

static constexpr WordType WORDTYPE_MAX = ~WordType(0)
 

Friends

struct DenseMapInfo< APInt >
 
class APSInt
 

Value Generators

hash_code hash_value (const APInt &Arg)
 Overload to compute a hash_code for an APInt value. More...
 
APInt getHiBits (unsigned numBits) const
 Compute an APInt containing numBits highbits from this APInt. More...
 
APInt getLoBits (unsigned numBits) const
 Compute an APInt containing numBits lowbits from this APInt. More...
 
const uint64_t * getRawData () const
 This function returns a pointer to the internal storage of the APInt. More...
 
static APInt getMaxValue (unsigned numBits)
 Gets maximum unsigned value of APInt for specific bit width. More...
 
static APInt getSignedMaxValue (unsigned numBits)
 Gets maximum signed value of APInt for a specific bit width. More...
 
static APInt getMinValue (unsigned numBits)
 Gets minimum unsigned value of APInt for a specific bit width. More...
 
static APInt getSignedMinValue (unsigned numBits)
 Gets minimum signed value of APInt for a specific bit width. More...
 
static APInt getSignMask (unsigned BitWidth)
 Get the SignMask for a specific bit width. More...
 
static APInt getAllOnesValue (unsigned numBits)
 Get the all-ones value. More...
 
static APInt getNullValue (unsigned numBits)
 Get the '0' value. More...
 
static APInt getOneBitSet (unsigned numBits, unsigned BitNo)
 Return an APInt with exactly one bit set in the result. More...
 
static APInt getBitsSet (unsigned numBits, unsigned loBit, unsigned hiBit)
 Get a value with a block of bits set. More...
 
static APInt getBitsSetWithWrap (unsigned numBits, unsigned loBit, unsigned hiBit)
 Wrap version of getBitsSet. More...
 
static APInt getBitsSetFrom (unsigned numBits, unsigned loBit)
 Get a value with upper bits starting at loBit set. More...
 
static APInt getHighBitsSet (unsigned numBits, unsigned hiBitsSet)
 Get a value with high bits set. More...
 
static APInt getLowBitsSet (unsigned numBits, unsigned loBitsSet)
 Get a value with low bits set. More...
 
static APInt getSplat (unsigned NewLen, const APInt &V)
 Return a value containing V broadcasted over NewLen bits. More...
 
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. More...
 

Binary Operators

APInt operator* (const APInt &RHS) const
 Multiplication operator. More...
 
APInt operator<< (unsigned Bits) const
 Left logical shift operator. More...
 
APInt operator<< (const APInt &Bits) const
 Left logical shift operator. More...
 
APInt ashr (unsigned ShiftAmt) const
 Arithmetic right-shift function. More...
 
void ashrInPlace (unsigned ShiftAmt)
 Arithmetic right-shift this APInt by ShiftAmt in place. More...
 
APInt lshr (unsigned shiftAmt) const
 Logical right-shift function. More...
 
void lshrInPlace (unsigned ShiftAmt)
 Logical right-shift this APInt by ShiftAmt in place. More...
 
APInt shl (unsigned shiftAmt) const
 Left-shift function. More...
 
APInt rotl (unsigned rotateAmt) const
 Rotate left by rotateAmt. More...
 
APInt rotr (unsigned rotateAmt) const
 Rotate right by rotateAmt. More...
 
APInt ashr (const APInt &ShiftAmt) const
 Arithmetic right-shift function. More...
 
void ashrInPlace (const APInt &shiftAmt)
 Arithmetic right-shift this APInt by shiftAmt in place. More...
 
APInt lshr (const APInt &ShiftAmt) const
 Logical right-shift function. More...
 
void lshrInPlace (const APInt &ShiftAmt)
 Logical right-shift this APInt by ShiftAmt in place. More...
 
APInt shl (const APInt &ShiftAmt) const
 Left-shift function. More...
 
APInt rotl (const APInt &rotateAmt) const
 Rotate left by rotateAmt. More...
 
APInt rotr (const APInt &rotateAmt) const
 Rotate right by rotateAmt. More...
 
APInt udiv (const APInt &RHS) const
 Unsigned division operation. More...
 
APInt udiv (uint64_t RHS) const
 
APInt sdiv (const APInt &RHS) const
 Signed division function for APInt. More...
 
APInt sdiv (int64_t RHS) const
 
APInt urem (const APInt &RHS) const
 Unsigned remainder operation. More...
 
uint64_t urem (uint64_t RHS) const
 
APInt srem (const APInt &RHS) const
 Function for signed remainder operation. More...
 
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 ushl_ov (const APInt &Amt, bool &Overflow) const
 
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 ushl_sat (const APInt &RHS) const
 
bool operator[] (unsigned bitPosition) const
 Array-indexing support. More...
 
static void udivrem (const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
 Dual division/remainder interface. More...
 
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)
 

Value Characterization Functions

unsigned getBitWidth () const
 Return the number of bits in the APInt. More...
 
unsigned getNumWords () const
 Get the number of words. More...
 
unsigned getActiveBits () const
 Compute the number of active bits in the value. More...
 
unsigned getActiveWords () const
 Compute the number of active words in the value of this APInt. More...
 
unsigned getMinSignedBits () const
 Get the minimum bit size for this signed APInt. More...
 
uint64_t getZExtValue () const
 Get zero extended value. More...
 
int64_t getSExtValue () const
 Get sign extended value. More...
 
unsigned countLeadingZeros () const
 The APInt version of the countLeadingZeros functions in MathExtras.h. More...
 
unsigned countLeadingOnes () const
 Count the number of leading one bits. More...
 
unsigned getNumSignBits () const
 Computes the number of leading bits of this APInt that are equal to its sign bit. More...
 
unsigned countTrailingZeros () const
 Count the number of trailing zero bits. More...
 
unsigned countTrailingOnes () const
 Count the number of trailing one bits. More...
 
unsigned countPopulation () const
 Count the number of bits set. More...
 
static unsigned getNumWords (unsigned BitWidth)
 Get the number of words. More...
 
static unsigned getBitsNeeded (StringRef str, uint8_t radix)
 Get bits required for string value. More...
 

Conversion Functions

void print (raw_ostream &OS, bool isSigned) const
 
void toString (SmallVectorImpl< char > &Str, unsigned Radix, bool Signed, bool formatAsCLiteral=false) const
 Converts an APInt to a string and append it to Str. More...
 
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. More...
 
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. More...
 
std::string toString (unsigned Radix, bool Signed) const
 Return the APInt as a std::string. More...
 
APInt byteSwap () const
 
APInt reverseBits () const
 
double roundToDouble (bool isSigned) const
 Converts this APInt to a double value. More...
 
double roundToDouble () const
 Converts this unsigned APInt to a double value. More...
 
double signedRoundToDouble () const
 Converts this signed APInt to a double value. More...
 
double bitsToDouble () const
 Converts APInt bits to a double. More...
 
float bitsToFloat () const
 Converts APInt bits to a float. More...
 
static APInt doubleToBits (double V)
 Converts a double to APInt bits. More...
 
static APInt floatToBits (float V)
 Converts a float to APInt bits. More...
 

Building-block Operations for APInt and APFloat

void dump () const
 debug method More...
 
static void tcSet (WordType *, WordType, unsigned)
 Sets the least significant part of a bignum to the input value, and zeroes out higher parts. More...
 
static void tcAssign (WordType *, const WordType *, unsigned)
 Assign one bignum to another. More...
 
static bool tcIsZero (const WordType *, unsigned)
 Returns true if a bignum is zero, false otherwise. More...
 
static int tcExtractBit (const WordType *, unsigned bit)
 Extract the given bit of a bignum; returns 0 or 1. Zero-based. More...
 
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. More...
 
static void tcSetBit (WordType *, unsigned bit)
 Set the given bit of a bignum. Zero-based. More...
 
static void tcClearBit (WordType *, unsigned bit)
 Clear the given bit of a bignum. Zero-based. More...
 
static unsigned tcLSB (const WordType *, unsigned n)
 Returns the bit number of the least or most significant set bit of a number. More...
 
static unsigned tcMSB (const WordType *parts, unsigned n)
 
static void tcNegate (WordType *, unsigned)
 Negate a bignum in-place. More...
 
static WordType tcAdd (WordType *, const WordType *, WordType carry, unsigned)
 DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag. More...
 
static WordType tcAddPart (WordType *, WordType, unsigned)
 DST += RHS. Returns the carry flag. More...
 
static WordType tcSubtract (WordType *, const WordType *, WordType carry, unsigned)
 DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag. More...
 
static WordType tcSubtractPart (WordType *, WordType, unsigned)
 DST -= RHS. Returns the carry flag. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static void tcShiftLeft (WordType *, unsigned Words, unsigned Count)
 Shift a bignum left Count bits. More...
 
static void tcShiftRight (WordType *, unsigned Words, unsigned Count)
 Shift a bignum right Count bits. More...
 
static void tcAnd (WordType *, const WordType *, unsigned)
 The obvious AND, OR and XOR and complement operations. More...
 
static void tcOr (WordType *, const WordType *, unsigned)
 
static void tcXor (WordType *, const WordType *, unsigned)
 
static void tcComplement (WordType *, unsigned)
 
static int tcCompare (const WordType *, const WordType *, unsigned)
 Comparison (unsigned) of two bignums. More...
 
static WordType tcIncrement (WordType *dst, unsigned parts)
 Increment a bignum in-place. Return the carry flag. More...
 
static WordType tcDecrement (WordType *dst, unsigned parts)
 Decrement a bignum in-place. Return the borrow flag. More...
 
static void tcSetLeastSignificantBits (WordType *, unsigned, unsigned bits)
 Set the least significant BITS and clear the rest. More...
 

Detailed Description

Class for arbitrary precision integers.

APInt is a functional replacement for common case unsigned integer type like "unsigned", "unsigned long" or "uint64_t", but also allows non-byte-width integer sizes and large integer value types such as 3-bits, 15-bits, or more than 64-bits of precision. APInt provides a variety of arithmetic operators and methods to manipulate integer values of any bit-width. It supports both the typical integer arithmetic and comparison operations as well as bitwise manipulation.

The class has several invariants worth noting:

Definition at line 70 of file APInt.h.

Member Typedef Documentation

◆ WordType

typedef uint64_t llvm::APInt::WordType

Definition at line 72 of file APInt.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum : unsigned

This enum is used to hold the constants we needed for APInt.

Enumerator
APINT_WORD_SIZE 

Byte size of a word.

APINT_BITS_PER_WORD 

Bits in a word.

Definition at line 75 of file APInt.h.

◆ Rounding

enum llvm::APInt::Rounding
strong
Enumerator
DOWN 
TOWARD_ZERO 
UP 

Definition at line 82 of file APInt.h.

Constructor & Destructor Documentation

◆ APInt() [1/7]

llvm::APInt::APInt ( unsigned  numBits,
uint64_t  val,
bool  isSigned = false 
)
inline

Create a new APInt of numBits width, initialized as val.

If isSigned is true then val is treated as if it were a signed value (i.e. as an int64_t) and the appropriate sign extension to the bit width will be done. Otherwise, no sign extension occurs (high order bits beyond the range of val are zero filled).

Parameters
numBitsthe bit width of the constructed APInt
valthe initial value of the APInt
isSignedhow to treat signedness of val

Definition at line 278 of file APInt.h.

References assert(), llvm::BitWidth, clearUnusedBits(), and val.

◆ APInt() [2/7]

APInt::APInt ( unsigned  numBits,
ArrayRef< uint64_t >  bigVal 
)

Construct an APInt of numBits width, initialized as bigVal[].

Note that bigVal.size() can be smaller or larger than the corresponding bit width but any extraneous bits will be dropped.

Parameters
numBitsthe bit width of the constructed APInt
bigVala sequence of words to form the initial value of the APInt

Definition at line 108 of file APInt.cpp.

◆ APInt() [3/7]

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

If this overload is ever deleted, care should be taken to prevent calls from being incorrectly captured by the APInt(unsigned, uint64_t, bool) constructor.

Definition at line 113 of file APInt.cpp.

References llvm::makeArrayRef().

◆ APInt() [4/7]

APInt::APInt ( unsigned  numBits,
StringRef  str,
uint8_t  radix 
)

Construct an APInt from a string representation.

This constructor interprets the string str in the given radix. The interpretation stops when the first character that is not suitable for the radix is encountered, or the end of the string. Acceptable radix values are 2, 8, 10, 16, and 36. It is an error for the value implied by the string to require more bits than numBits.

Parameters
numBitsthe bit width of the constructed APInt
strthe string to be interpreted
radixthe radix to use for the conversion

Definition at line 118 of file APInt.cpp.

References assert().

◆ APInt() [5/7]

llvm::APInt::APInt ( const APInt that)
inline

Simply makes *this a copy of that.

Copy Constructor.

Definition at line 322 of file APInt.h.

References that.

◆ APInt() [6/7]

llvm::APInt::APInt ( APInt &&  that)
inline

Move Constructor.

Definition at line 330 of file APInt.h.

References memcpy(), and that.

◆ ~APInt()

llvm::APInt::~APInt ( )
inline

Destructor.

Definition at line 336 of file APInt.h.

◆ APInt() [7/7]

llvm::APInt::APInt ( )
inlineexplicit

Default constructor that creates an uninteresting APInt representing a 1-bit zero value.

This is useful for object deserialization (pair this with the static method Read).

Definition at line 346 of file APInt.h.

Referenced by byteSwap(), extractBits(), multiplicativeInverse(), operator*(), reverseBits(), sext(), sqrt(), sshl_ov(), trunc(), udiv(), udivrem(), urem(), ushl_ov(), usub_sat(), and zext().

Member Function Documentation

◆ abs()

APInt llvm::APInt::abs ( ) const
inline

◆ ashr() [1/2]

APInt llvm::APInt::ashr ( const APInt ShiftAmt) const
inline

Arithmetic right-shift function.

Arithmetic right-shift this APInt by shiftAmt.

Definition at line 1024 of file APInt.h.

References llvm::RISCVFenceField::R.

◆ ashr() [2/2]

APInt llvm::APInt::ashr ( unsigned  ShiftAmt) const
inline

◆ ashrInPlace() [1/2]

void APInt::ashrInPlace ( const APInt shiftAmt)

Arithmetic right-shift this APInt by shiftAmt in place.

Arithmetic right-shift this APInt by shiftAmt.

Arithmetic right-shift function.

Definition at line 984 of file APInt.cpp.

References ashrInPlace(), and getLimitedValue().

◆ ashrInPlace() [2/2]

void llvm::APInt::ashrInPlace ( unsigned  ShiftAmt)
inline

◆ bitsToDouble()

double llvm::APInt::bitsToDouble ( ) const
inline

Converts APInt bits to a double.

The conversion does not do a translation from integer to double, it just re-interprets the bits as a double. Note that it is valid to do this on any bit width. Exactly 64 bits will be translated.

Definition at line 1782 of file APInt.h.

References llvm::BitsToDouble().

Referenced by llvm::detail::IEEEFloat::convertToDouble(), llvm::convertToNonDenormSingle(), and llvm::ExecutionEngine::getConstantValue().

◆ bitsToFloat()

float llvm::APInt::bitsToFloat ( ) const
inline

Converts APInt bits to a float.

The conversion does not do a translation from integer to float, it just re-interprets the bits as a float. Note that it is valid to do this on any bit width. Exactly 32 bits will be translated.

Definition at line 1791 of file APInt.h.

References llvm::BitsToFloat().

Referenced by llvm::detail::IEEEFloat::convertToFloat(), llvm::ExecutionEngine::getConstantValue(), and llvm::AMDGPUTargetLowering::LowerUDIVREM64().

◆ byteSwap()

APInt APInt::byteSwap ( ) const

◆ ceilLogBase2()

unsigned llvm::APInt::ceilLogBase2 ( ) const
inline
Returns
the ceil log base 2 of this APInt.

Definition at line 1819 of file APInt.h.

References getActiveBits().

Referenced by ComputeNumSignBitsImpl(), llvm::InstCombinerImpl::foldICmpUsingKnownBits(), and genConstMult().

◆ clearAllBits()

void llvm::APInt::clearAllBits ( )
inline

◆ clearBit()

void llvm::APInt::clearBit ( unsigned  BitPosition)
inline

◆ clearLowBits()

void llvm::APInt::clearLowBits ( unsigned  loBits)
inline

◆ clearSignBit()

void llvm::APInt::clearSignBit ( )
inline

Set the sign bit to 0.

Definition at line 1542 of file APInt.h.

References llvm::BitWidth.

Referenced by llvm::ConstantRange::fromKnownBits().

◆ countLeadingOnes()

unsigned llvm::APInt::countLeadingOnes ( ) const
inline

Count the number of leading one bits.

This function is an APInt version of the countLeadingOnes functions in MathExtras.h. It counts the number of ones from the most significant bit to the first zero bit.

Returns
0 if the high order bit is not set, otherwise returns the number of 1 bits from the most significant to the least

Definition at line 1680 of file APInt.h.

References llvm::BitWidth, and llvm::countLeadingOnes().

Referenced by llvm::KnownBits::countMinLeadingOnes(), llvm::KnownBits::countMinLeadingZeros(), llvm::InstCombinerImpl::foldICmpShrConstConst(), lower1BitShuffle(), lowerShuffleAsByteShiftMask(), lowerShuffleAsVTRUNCAndUnpack(), llvm::CombinerHelper::matchCombineShlOfExtend(), and sshl_ov().

◆ countLeadingZeros()

unsigned llvm::APInt::countLeadingZeros ( ) const
inline

The APInt version of the countLeadingZeros functions in MathExtras.h.

It counts the number of zeros from the most significant bit to the first one bit.

Returns
BitWidth if the value is zero, otherwise returns the number of zeros from the most significant bit to the first one bits.

Definition at line 1664 of file APInt.h.

References llvm::BitWidth, and llvm::countLeadingZeros().

Referenced by areUsedBitsDense(), bitTrackingDCE(), llvm::KnownBits::countMaxLeadingOnes(), llvm::KnownBits::countMaxLeadingZeros(), llvm::InstCombinerImpl::foldICmpShrConstConst(), llvm::SelectionDAG::getNode(), processUMulZExtIdiom(), llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), sshl_ov(), tryBitfieldInsertOpFromOr(), umul_ov(), ushl_ov(), and llvm::InstCombinerImpl::visitAnd().

◆ countPopulation()

unsigned llvm::APInt::countPopulation ( ) const
inline

◆ countTrailingOnes()

unsigned llvm::APInt::countTrailingOnes ( ) const
inline

Count the number of trailing one bits.

This function is an APInt version of the countTrailingOnes functions in MathExtras.h. It counts the number of ones from the least significant bit to the first zero bit.

Returns
BitWidth if the value is all ones, otherwise returns the number of ones from the least significant bit to the first zero bit.

Definition at line 1714 of file APInt.h.

References llvm::countTrailingOnes().

Referenced by combineAndMaskToShift(), combineShiftRightLogical(), llvm::KnownBits::countMinTrailingOnes(), llvm::KnownBits::countMinTrailingZeros(), getDemandedBitsLHSMask(), lowerShuffleAsByteShiftMask(), and llvm::ConstantRange::truncate().

◆ countTrailingZeros()

unsigned llvm::APInt::countTrailingZeros ( ) const
inline

◆ doubleToBits()

static APInt llvm::APInt::doubleToBits ( double  V)
inlinestatic

Converts a double to APInt bits.

The conversion does not do a translation from double to integer, it just re-interprets the bits of the double.

Definition at line 1799 of file APInt.h.

References llvm::DoubleToBits().

Referenced by llvm::ExecutionEngine::getConstantValue(), and llvm::detail::IEEEFloat::IEEEFloat().

◆ dump()

LLVM_DUMP_METHOD void APInt::dump ( ) const

debug method

Definition at line 2289 of file APInt.cpp.

References llvm::BitWidth, llvm::dbgs(), S, toStringSigned(), and toStringUnsigned().

◆ eq()

bool llvm::APInt::eq ( const APInt RHS) const
inline

Equality comparison.

Compares this APInt with RHS for the validity of the equality relationship.

Returns
true if *this == Val

Definition at line 1173 of file APInt.h.

Referenced by llvm::omp::getBestVariantMatchForContext(), and processUMulZExtIdiom().

◆ exactLogBase2()

int32_t llvm::APInt::exactLogBase2 ( ) const
inline
Returns
the log base 2 of this APInt if its an exact power of two, -1 otherwise

Definition at line 1856 of file APInt.h.

Referenced by llvm::InstCombinerImpl::Descale(), and llvm::InstCombinerImpl::foldICmpAndConstant().

◆ extractBits()

APInt APInt::extractBits ( unsigned  numBits,
unsigned  bitPosition 
) const

◆ extractBitsAsZExtValue()

uint64_t APInt::extractBitsAsZExtValue ( unsigned  numBits,
unsigned  bitPosition 
) const

Definition at line 463 of file APInt.cpp.

References assert().

◆ flipAllBits()

void llvm::APInt::flipAllBits ( )
inline

Toggle every bit to its opposite value.

Definition at line 1547 of file APInt.h.

References clearUnusedBits().

Referenced by getUsefulBits(), getUsefulBitsFromBFM(), insert1BitVector(), and llvm::operator~().

◆ flipBit()

void APInt::flipBit ( unsigned  bitPosition)

Toggles a given bit to its opposite value.

Toggle a given bit to its opposite value whose position is given as "bitPosition".

Toggles a given bit to its opposite value.

Definition at line 339 of file APInt.cpp.

References assert(), and setBitVal().

◆ floatToBits()

static APInt llvm::APInt::floatToBits ( float  V)
inlinestatic

Converts a float to APInt bits.

The conversion does not do a translation from float to integer, it just re-interprets the bits of the float.

Definition at line 1807 of file APInt.h.

References llvm::FloatToBits().

Referenced by llvm::ExecutionEngine::getConstantValue(), and llvm::detail::IEEEFloat::IEEEFloat().

◆ getActiveBits()

unsigned llvm::APInt::getActiveBits ( ) const
inline

◆ getActiveWords()

unsigned llvm::APInt::getActiveWords ( ) const
inline

Compute the number of active words in the value of this APInt.

This is used in conjunction with getActiveData to extract the raw value of the APInt.

Definition at line 1611 of file APInt.h.

◆ getAllOnesValue()

static APInt llvm::APInt::getAllOnesValue ( unsigned  numBits)
inlinestatic

Get the all-ones value.

Returns
the all-ones value for an APInt of the specified bit-width.

Definition at line 567 of file APInt.h.

Referenced by llvm::ConstantRange::binaryNot(), canTryToConstantAddTwoShiftAmounts(), combineBEXTR(), combineExtractVectorElt(), combineKSHIFT(), combineMinMaxReduction(), combineMOVMSK(), combinePDEP(), combinePMULDQ(), combineShuffle(), combineVectorInsert(), combineVectorPack(), combineVectorShiftImm(), combineVectorShiftVar(), combineVectorSignBitsTruncation(), combineVTRUNC(), combineX86INT_TO_FP(), combineX86ShuffleChain(), combineX86ShufflesRecursively(), computeKnownBits(), llvm::SelectionDAG::computeKnownBits(), llvm::X86TargetLowering::computeKnownBitsForTargetNode(), computeKnownBitsFromOperator(), llvm::GISelKnownBits::computeKnownBitsImpl(), llvm::GISelKnownBits::computeNumSignBits(), ComputeNumSignBits(), llvm::SelectionDAG::ComputeNumSignBits(), detectSSatPattern(), findDemandedEltsByAllUsers(), findDemandedEltsBySingleUser(), llvm::InstCombinerImpl::foldICmpUsingKnownBits(), foldShiftIntoShiftInAnotherHandOfAndInICmp(), llvm::SelectionDAG::getAllOnesConstant(), llvm::Constant::getAllOnesValue(), llvm::APFloat::getAllOnesValue(), getBitcastWiderVectorElementOffset(), llvm::DemandedBits::getDemandedBits(), llvm::SelectionDAG::GetDemandedBits(), getDemandedBitsLHSMask(), getHopForBuildVector(), llvm::GISelKnownBits::getKnownBits(), llvm::IntegerType::getMask(), llvm::X86TTIImpl::getMaskedMemoryOpCost(), llvm::X86TTIImpl::getMemoryOpCost(), llvm::SelectionDAG::getNOT(), getOnesVector(), llvm::BuildVectorSDNode::getRepeatedSequence(), llvm::BasicTTIImplBase< AMDGPUTTIImpl >::getScalarizationOverhead(), llvm::SelectionDAG::getSplatSourceVector(), llvm::BuildVectorSDNode::getSplatValue(), getTargetConstantBitsFromNode(), getTargetShuffleInputs(), isConditionalZeroOrAllOnes(), isKnownNonZero(), llvm::SelectionDAG::isSplatValue(), magicu(), MatchVectorAllZeroTest(), narrowSDivOrSRem(), llvm::PPCTargetLowering::PerformDAGCombine(), performVectorTruncateCombine(), llvm::possiblyDemandedEltsInMask(), llvm::recognizeBSwapOrBitReverseIdiom(), setLimitsForBinOp(), llvm::TargetLowering::ShrinkDemandedConstant(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::ARMTargetLowering::SimplifyDemandedBitsForTargetNode(), llvm::InstCombinerImpl::SimplifyDemandedInstructionBits(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), llvm::InstCombinerImpl::SimplifyDemandedVectorElts(), llvm::TargetLowering::SimplifyDemandedVectorElts(), llvm::TargetLowering::SimplifyMultipleUseDemandedBits(), llvm::X86TargetLowering::SimplifyMultipleUseDemandedBitsForTargetNode(), llvm::TargetLowering::SimplifyMultipleUseDemandedVectorElts(), llvm::InstCombinerImpl::simplifyShrShlDemandedBits(), llvm::APFixedPoint::toString(), llvm::LegalizationArtifactCombiner::tryCombineZExt(), llvm::InstCombinerImpl::visitCallInst(), llvm::InstCombinerImpl::visitGetElementPtrInst(), llvm::InstCombinerImpl::visitInsertElementInst(), llvm::InstCombinerImpl::visitShuffleVectorInst(), and llvm::InstCombinerImpl::visitXor().

◆ getBitsNeeded()

unsigned APInt::getBitsNeeded ( StringRef  str,
uint8_t  radix 
)
static

Get bits required for string value.

This method determines how many bits are required to hold the APInt equivalent of the string given by str.

Definition at line 488 of file APInt.cpp.

References assert(), llvm::StringRef::begin(), llvm::StringRef::empty(), isNegative(), p, and llvm::StringRef::size().

◆ getBitsSet()

static APInt llvm::APInt::getBitsSet ( unsigned  numBits,
unsigned  loBit,
unsigned  hiBit 
)
inlinestatic

Get a value with a block of bits set.

Constructs an APInt value that has a contiguous range of bits set. The bits from loBit (inclusive) to hiBit (exclusive) will be set. All other bits will be zero. For example, with parameters(32, 0, 16) you would get 0x0000FFFF. Please call getBitsSetWithWrap if loBit may be greater than hiBit.

Parameters
numBitsthe intended bit width of the result
loBitthe index of the lowest bit set.
hiBitthe index of the highest bit set.
Returns
An APInt value with the requested bits set.

Definition at line 612 of file APInt.h.

References assert(), and setBits().

Referenced by combineToExtendBoolVectorInReg(), llvm::X86TTIImpl::getScalarizationOverhead(), insert1BitVector(), llvm::AMDGPUTargetLowering::PerformDAGCombine(), llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode(), simplifyX86immShift(), tryBitfieldInsertOpFromOr(), tryToMergePartialOverlappingStores(), and llvm::RegisterBankInfo::ValueMapping::verify().

◆ getBitsSetFrom()

static APInt llvm::APInt::getBitsSetFrom ( unsigned  numBits,
unsigned  loBit 
)
inlinestatic

Get a value with upper bits starting at loBit set.

Constructs an APInt value that has a contiguous range of bits set. The bits from loBit (inclusive) to numBits (exclusive) will be set. All other bits will be zero. For example, with parameters(32, 12) you would get 0xFFFFF000.

Parameters
numBitsthe intended bit width of the result
loBitthe index of the lowest bit to set.
Returns
An APInt value with the requested bits set.

Definition at line 643 of file APInt.h.

References setBitsFrom().

Referenced by canEvaluateTruncated(), combineSetCC(), llvm::APFixedPoint::convert(), getDemandedBitsLHSMask(), getTruncatedUSUBSAT(), LowerPARITY(), llvm::RISCVTargetLowering::PerformDAGCombine(), and llvm::ConstantRange::truncate().

◆ getBitsSetWithWrap()

static APInt llvm::APInt::getBitsSetWithWrap ( unsigned  numBits,
unsigned  loBit,
unsigned  hiBit 
)
inlinestatic

Wrap version of getBitsSet.

If hiBit is bigger than loBit, this is same with getBitsSet. If hiBit is not bigger than loBit, the set bits "wrap". For example, with parameters (32, 28, 4), you would get 0xF000000F. If hiBit is equal to loBit, you would get a result with all bits set.

Definition at line 625 of file APInt.h.

References setBitsWithWrap().

Referenced by llvm::PPCInstrInfo::combineRLWINM(), and llvm::LegalizerHelper::lowerInsert().

◆ getBitWidth()

unsigned llvm::APInt::getBitWidth ( ) const
inline

Return the number of bits in the APInt.

Definition at line 1581 of file APInt.h.

References llvm::BitWidth.

Referenced by llvm::DwarfExpression::addConstantFP(), llvm::DwarfUnit::addConstantValue(), llvm::APFixedPoint::APFixedPoint(), APIntToHexString(), llvm::SwitchCG::SwitchLowering::buildBitTests(), BuildExactSDIV(), llvm::TargetLowering::BuildUDIV(), calculateOffsetDiff(), llvm::FunctionComparator::cmpAPInts(), combineCMov(), combineSetCCMOVMSK(), combineShiftOfShiftedLogic(), CombineVMOVDRRCandidateWithVecOp(), combinevXi1ConstantToInteger(), llvm::APFixedPoint::compare(), CompareSCEVComplexity(), llvm::APSInt::compareValues(), llvm::SelectionDAG::computeKnownBits(), computeKnownBits(), llvm::SystemZTargetLowering::computeKnownBitsForTargetNode(), llvm::X86TargetLowering::computeKnownBitsForTargetNode(), computeKnownBitsFromOperator(), llvm::computeMinimumValueSizes(), llvm::ComputeMultiple(), llvm::SelectionDAG::ComputeNumSignBits(), ComputeNumSignBitsImpl(), llvm::FunctionLoweringInfo::ComputePHILiveOutRegInfo(), llvm::ConstantFoldBinaryInstruction(), llvm::ConstantRange::ConstantRange(), llvm::APFixedPoint::convert(), llvm::InstCombinerImpl::Descale(), emitGlobalConstantFP(), extractConstantWithoutWrapping(), extractShiftForRotate(), llvm::InstCombinerImpl::foldICmpShlConstConst(), llvm::InstCombinerImpl::foldICmpShrConstant(), foldNoWrapAdd(), foldSelectICmpAnd(), llvm::ConstantInt::get(), llvm::KnownBits::getBitWidth(), llvm::ConstantInt::getBitWidth(), llvm::ExecutionEngine::getConstantValue(), llvm::getConstantVRegSExtVal(), llvm::getConstantVRegValWithLookThrough(), getConstVector(), getFauxShuffleMask(), getFpImmVal(), getHorizDemandedElts(), llvm::BPFTTIImpl::getIntImmCost(), llvm::SystemZTTIImpl::getIntImmCost(), llvm::PPCTTIImpl::getIntImmCost(), llvm::SystemZTTIImpl::getIntImmCostInst(), llvm::PPCTTIImpl::getIntImmCostInst(), llvm::X86TTIImpl::getIntImmCostInst(), llvm::SystemZTTIImpl::getIntImmCostIntrin(), llvm::PPCTTIImpl::getIntImmCostIntrin(), llvm::AArch64TTIImpl::getIntImmCostIntrin(), llvm::X86TTIImpl::getIntImmCostIntrin(), llvm::SwitchCG::getJumpTableRange(), getKnownUndefForVectorBinop(), llvm::SelectionDAG::getNode(), getPackDemandedElts(), llvm::getPtrStride(), GetQuadraticEquation(), llvm::BuildVectorSDNode::getRepeatedSequence(), llvm::BasicTTIImplBase< AMDGPUTTIImpl >::getScalarizationOverhead(), getShiftAmount(), getSplat(), llvm::BuildVectorSDNode::getSplatValue(), llvm::getStrideFromPointer(), getTargetConstantBitsFromNode(), getUsefulBits(), getUsefulBitsForUse(), getUsefulBitsFromAndWithImmediate(), getUsefulBitsFromBFM(), getUsefulBitsFromBitfieldMoveOpd(), IncorporateWeight(), insertBits(), llvm::ConstantRange::intrinsic(), llvm::TargetTransformInfoImplBase::isConstantStridedAccessLessThan(), llvm::TargetLowering::isConstTrueVal(), llvm::DenseMapInfo< APInt >::isEqual(), llvm::DenseMapInfo< APSInt >::isEqual(), llvm::ARMTTIImpl::isHardwareLoopProfitable(), llvm::SIInstrInfo::isInlineConstant(), isMultiple(), isSameValue(), isSplat(), llvm::SelectionDAG::isSplatValue(), makeExactMulNSWRegion(), makeExactMulNUWRegion(), matchAndOrChain(), MatchDiv(), MatchMul(), operator*(), ParseBFI(), parseHexOcta(), performORCombine(), PerformORCombine(), PerformSHLSimplify(), printConstant(), processUMulZExtIdiom(), resolveTargetShuffleFromZeroables(), rotateModulo(), llvm::RISCVDAGToDAGISel::selectShiftMask(), llvm::APFixedPoint::shl(), simplifyAndOrOfICmpsWithLimitConst(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), llvm::TargetLowering::SimplifyDemandedVectorElts(), llvm::X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode(), llvm::X86TargetLowering::SimplifyDemandedVectorEltsForTargetShuffle(), simplifyICmpWithBinOpOnLHS(), simplifyIntrinsic(), llvm::InstCombinerImpl::SimplifyMultipleUseDemandedBits(), llvm::TargetLowering::SimplifyMultipleUseDemandedBits(), llvm::X86TargetLowering::SimplifyMultipleUseDemandedBitsForTargetNode(), sshl_ov(), llvm::ConstantRange::subtract(), llvm::SystemZVectorConstantInfo::SystemZVectorConstantInfo(), llvm::X86TargetLowering::targetShrinkDemandedConstant(), llvm::APFixedPoint::toString(), toString(), llvm::detail::IEEEFloat::toString(), tryToMergePartialOverlappingStores(), ushl_ov(), llvm::InstCombinerImpl::visitAdd(), llvm::SCEVDivision::visitConstant(), llvm::InstCombinerImpl::visitMul(), and zeroExtendToMatch().

◆ getBoolValue()

bool llvm::APInt::getBoolValue ( ) const
inline

◆ getHiBits()

APInt APInt::getHiBits ( unsigned  numBits) const

Compute an APInt containing numBits highbits from this APInt.

This function returns the high "numBits" bits of this APInt.

Get an APInt with the same BitWidth as this APInt, just zero mask the low bits and right shift to the least significant bit.

Returns
the high "numBits" bits of this APInt.

Definition at line 562 of file APInt.cpp.

References lshr().

Referenced by llvm::SelectionDAG::computeKnownBits(), llvm::SIInstrInfo::expandPostRAPseudo(), parseHexOcta(), and WriteConstantInternal().

◆ getHighBitsSet()

static APInt llvm::APInt::getHighBitsSet ( unsigned  numBits,
unsigned  hiBitsSet 
)
inlinestatic

Get a value with high bits set.

Constructs an APInt value that has the top hiBitsSet bits set.

Parameters
numBitsthe bitwidth of the result
hiBitsSetthe number of high-order bits set in the result.

Definition at line 655 of file APInt.h.

References setHighBits().

Referenced by canEvaluateZExtd(), combineAnd(), combineCMP(), combineMulToPMADDWD(), combineMulToPMULDQ(), combineOr(), combineTargetShuffle(), combineVectorPack(), combineZext(), llvm::AMDGPUTargetLowering::computeKnownBitsForTargetNode(), llvm::ARMTargetLowering::computeKnownBitsForTargetNode(), llvm::AArch64TargetLowering::computeKnownBitsForTargetNode(), llvm::X86TargetLowering::computeKnownBitsForTargetNode(), llvm::computeKnownBitsFromRangeMetadata(), EmitCmp(), llvm::TargetLowering::expandMUL_LOHI(), llvm::InstCombinerImpl::foldAddWithConstant(), llvm::InstCombinerImpl::foldICmpEqIntrinsicWithConstant(), llvm::InstCombinerImpl::foldICmpShrConstant(), llvm::InstCombinerImpl::foldICmpTruncConstant(), foldMaskAndShiftToScale(), llvm::InstCombinerImpl::FoldShiftByConstant(), foldShiftedShift(), getFauxShuffleMask(), isTruncWithZeroHighBitsInput(), LowerMUL(), LowerScalarImmediateShift(), llvm::AMDGPUTargetLowering::LowerUDIVREM64(), matchShuffleWithPACK(), AMDGPUPostLegalizerCombinerHelper::matchUCharToFloat(), llvm::ARMTargetLowering::PerformDAGCombine(), PerformShiftCombine(), PerformSHLSimplify(), performSRLCombine(), PerformVMOVNCombine(), PerformVQMOVNCombine(), llvm::RISCVTargetLowering::ReplaceNodeResults(), SaturateWidenedDIVFIX(), llvm::ConstantRange::signExtend(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), llvm::X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode(), llvm::TargetLowering::SimplifySetCC(), simplifyUnaryIntrinsic(), simplifyX86varShift(), tryLowerToSLI(), llvm::InstCombinerImpl::visitShl(), llvm::InstCombinerImpl::visitSub(), and llvm::InstCombinerImpl::visitZExt().

◆ getLimitedValue()

uint64_t llvm::APInt::getLimitedValue ( uint64_t  Limit = UINT64_MAX) const
inline

◆ getLoBits()

APInt APInt::getLoBits ( unsigned  numBits) const

Compute an APInt containing numBits lowbits from this APInt.

This function returns the low "numBits" bits of this APInt.

Get an APInt with the same BitWidth as this APInt, just zero mask the high bits.

Returns
the low "numBits" bits of this APInt.

Definition at line 567 of file APInt.cpp.

References getLowBitsSet().

Referenced by llvm::SIInstrInfo::expandMovDPP64(), llvm::SIInstrInfo::expandPostRAPseudo(), llvm::KnownBits::mul(), parseHexOcta(), llvm::X86TTIImpl::simplifyDemandedVectorEltsIntrinsic(), and WriteConstantInternal().

◆ getLowBitsSet()

static APInt llvm::APInt::getLowBitsSet ( unsigned  numBits,
unsigned  loBitsSet 
)
inlinestatic

Get a value with low bits set.

Constructs an APInt value that has the bottom loBitsSet bits set.

Parameters
numBitsthe bitwidth of the result
loBitsSetthe number of low-order bits set in the result.

Definition at line 667 of file APInt.h.

References setLowBits().

Referenced by buildBitFieldInsert(), llvm::MachineIRBuilder::buildZExtInReg(), canEvaluateShiftedShift(), clampDynamicVectorIndex(), combineBT(), combineCMP(), combineCVTPH2PS(), combineMOVMSK(), combinePredicateReduction(), combineVectorTruncationWithPACKUS(), combineVEXTRACT_STORE(), llvm::SelectionDAG::computeKnownBits(), llvm::ConstantFoldBinaryInstruction(), llvm::ConstantFoldCastOperand(), llvm::InstCombinerImpl::foldICmpBinOp(), llvm::InstCombinerImpl::foldICmpEqIntrinsicWithConstant(), llvm::InstCombinerImpl::foldICmpEquality(), llvm::InstCombinerImpl::foldICmpIntrinsicWithConstant(), llvm::InstCombinerImpl::foldICmpShlConstant(), llvm::InstCombinerImpl::FoldShiftByConstant(), foldShiftedShift(), getLoBits(), getTruncatedUSUBSAT(), llvm::SelectionDAG::getZeroExtendInReg(), llvm::ARMTTIImpl::instCombineIntrinsic(), llvm::X86TTIImpl::instCombineIntrinsic(), llvm::LegalizerHelper::lowerFCopySign(), LowerMUL(), LowerScalarImmediateShift(), MatchVectorAllZeroTest(), ParseBFI(), llvm::RISCVTargetLowering::PerformDAGCombine(), llvm::ARMTargetLowering::PerformDAGCombine(), llvm::ARMTargetLowering::PerformIntrinsicCombine(), PerformPREDICATE_CASTCombine(), performTBISimplification(), PerformVMOVhrCombine(), PerformVMOVNCombine(), PerformVQMOVNCombine(), processUGT_ADDCST_ADD(), SaturateWidenedDIVFIX(), llvm::TargetLowering::scalarizeVectorLoad(), llvm::ConstantRange::signExtend(), SimplifyAndInst(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), llvm::X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode(), simplifyMul24(), llvm::InstCombinerImpl::SimplifyMultipleUseDemandedBits(), llvm::TargetLowering::SimplifySetCC(), simplifyX86pack(), llvm::X86TargetLowering::targetShrinkDemandedConstant(), tryLowerToSLI(), llvm::InstCombinerImpl::visitAnd(), llvm::InstCombinerImpl::visitAShr(), llvm::InstCombinerImpl::visitCallInst(), llvm::InstCombinerImpl::visitLShr(), and llvm::InstCombinerImpl::visitZExt().

◆ getMaxValue()

static APInt llvm::APInt::getMaxValue ( unsigned  numBits)
inlinestatic

◆ getMinSignedBits()

unsigned llvm::APInt::getMinSignedBits ( ) const
inline

Get the minimum bit size for this signed APInt.

Computes the minimum bit width for this APInt while considering it to be a signed (and probably negative) value. If the value is not negative, this function returns the same value as getActiveBits()+1. Otherwise, it returns the smallest bit width that will retain the negative value. For example, -1 can be written as 0b1 or 0xFFFFFFFFFF. 0b1 is shorter and so for -1, this function will always return 1.

Definition at line 1624 of file APInt.h.

References llvm::BitWidth.

Referenced by llvm::APSInt::APSInt(), canFoldIVIncExpr(), combineShiftRightLogical(), eliminateDeadSwitchCases(), llvm::RISCVTTIImpl::getIntImmCostInst(), llvm::SelectionDAG::getVScale(), llvm::RISCVTargetLowering::isDesirableToCommuteWithShift(), isIndexInRangeOfArrayType(), llvm::TargetLowering::SimplifySetCC(), llvm::RISCVTargetLowering::targetShrinkDemandedConstant(), and llvm::InstCombinerImpl::visitSDiv().

◆ getMinValue()

static APInt llvm::APInt::getMinValue ( unsigned  numBits)
inlinestatic

◆ getNullValue()

static APInt llvm::APInt::getNullValue ( unsigned  numBits)
inlinestatic

Get the '0' value.

Returns
the '0' value for an APInt of the specified bit-width.

Definition at line 574 of file APInt.h.

Referenced by llvm::ConstantRange::abs(), llvm::ConstantRange::binaryAnd(), llvm::ConstantRange::binaryOr(), llvm::SwitchCG::SwitchLowering::buildBitTests(), llvm::TargetLowering::BuildUDIV(), cmpExcludesZero(), combineSetCCMOVMSK(), combineVectorPack(), combineX86ShuffleChain(), combineX86ShufflesConstants(), combineX86ShufflesRecursively(), llvm::ObjectSizeOffsetVisitor::compute(), llvm::SelectionDAG::computeKnownBits(), llvm::SelectionDAG::ComputeNumSignBits(), computeZeroableShuffleElements(), llvm::ConstantFoldCastInstruction(), EltsFromConsecutiveLoads(), getHorizDemandedElts(), getKnownUndefForVectorBinop(), llvm::SelectionDAG::getNode(), llvm::Constant::getNullValue(), getPackDemandedElts(), getShuffleDemandedElts(), getTargetConstantBitsFromNode(), getTargetShuffleAndZeroables(), llvm::SelectionDAG::isSplatValue(), llvm::LegalizerHelper::lowerFPTOUI(), llvm::ConstantRange::makeAllowedICmpRegion(), llvm::ConstantRange::makeGuaranteedNoWrapRegion(), matchBinaryShuffle(), matchScalarReduction(), resolveZeroablesFromTargetShuffle(), scalarConstantToHexString(), llvm::ConstantRange::sdiv(), setLimitsForSelectPattern(), simplifyAndOrOfICmpsWithLimitConst(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::TargetLowering::SimplifyDemandedVectorElts(), llvm::X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode(), llvm::TargetLowering::SimplifyMultipleUseDemandedBits(), simplifyX86pack(), llvm::ConstantRange::srem(), stripAndComputeConstantOffsets(), llvm::ConstantRange::urem(), and llvm::reassociate::XorOpnd::XorOpnd().

◆ getNumSignBits()

unsigned llvm::APInt::getNumSignBits ( ) const
inline

◆ getNumWords() [1/2]

unsigned llvm::APInt::getNumWords ( ) const
inline

Get the number of words.

Here one word's bitwidth equals to that of uint64_t.

Returns
the number of words to hold the integer value of this APInt.

Definition at line 1588 of file APInt.h.

References llvm::BitWidth, and getNumWords().

Referenced by byteSwap(), llvm::detail::IEEEFloat::convertFromAPInt(), emitGlobalConstantFP(), extractBits(), getNumWords(), llvm::detail::IEEEFloat::makeNaN(), operator*(), operator*=(), operator++(), operator+=(), operator--(), operator-=(), printConstant(), Profile(), sext(), trunc(), udiv(), udivrem(), urem(), and zext().

◆ getNumWords() [2/2]

static unsigned llvm::APInt::getNumWords ( unsigned  BitWidth)
inlinestatic

Get the number of words.

NOTE Here one word's bitwidth equals to that of uint64_t.

Returns
the number of words to hold the integer value with a given bit width.

Definition at line 1596 of file APInt.h.

References llvm::BitWidth.

◆ getOneBitSet()

static APInt llvm::APInt::getOneBitSet ( unsigned  numBits,
unsigned  BitNo 
)
inlinestatic

Return an APInt with exactly one bit set in the result.

Definition at line 593 of file APInt.h.

References setBit().

Referenced by BinomialCoefficient(), llvm::TargetLowering::BuildUDIV(), combineExtractVectorElt(), combineShiftAnd1ToBitTest(), llvm::InstCombinerImpl::commonIDivTransforms(), llvm::SelectionDAG::computeKnownBits(), llvm::ARMTargetLowering::computeKnownBitsForTargetNode(), llvm::X86TargetLowering::computeKnownBitsForTargetNode(), computeKnownBitsFromOperator(), llvm::SelectionDAG::ComputeNumSignBits(), extractShiftForRotate(), findDemandedEltsBySingleUser(), llvm::InstCombinerImpl::foldICmpEqIntrinsicWithConstant(), llvm::InstCombinerImpl::foldICmpEquality(), llvm::InstCombinerImpl::foldICmpIntrinsicWithConstant(), llvm::InstCombinerImpl::foldICmpShlConstant(), foldSelectICmpAndOr(), IncorporateWeight(), llvm::ARMTTIImpl::instCombineIntrinsic(), isKnownNonZero(), llvm::fuzzerop::makeConstantsWithType(), MatchBinaryOp(), processUMulZExtIdiom(), scalarizeMaskedCompressStore(), scalarizeMaskedExpandLoad(), scalarizeMaskedGather(), scalarizeMaskedLoad(), scalarizeMaskedScatter(), scalarizeMaskedStore(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode(), llvm::X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode(), simplifyIntrinsic(), llvm::X86TargetLowering::SimplifyMultipleUseDemandedBitsForTargetNode(), simplifyX86immShift(), SolveLinEquationWithOverflow(), llvm::APIntOps::SolveQuadraticEquationWrap(), llvm::LegalizerHelper::widenScalar(), and llvm::ConstantRange::zeroExtend().

◆ getRawData()

const uint64_t* llvm::APInt::getRawData ( ) const
inline

◆ getSExtValue()

int64_t llvm::APInt::getSExtValue ( ) const
inline

Get sign extended value.

This method attempts to return the value of this APInt as a sign extended int64_t. The bit width must be <= 64 or the value must fit within an int64_t. Otherwise an assertion will result.

Definition at line 1643 of file APInt.h.

References assert(), llvm::BitWidth, and llvm::SignExtend64().

Referenced by llvm::DwarfUnit::addConstantValue(), llvm::InterleavedAccessInfo::analyzeInterleaving(), llvm::TargetLowering::BuildSDIV(), llvm::SIInstrInfo::FoldImmediate(), llvm::getConstantVRegSExtVal(), llvm::AArch64_AM::getFP16Imm(), llvm::ARM_AM::getFP16Imm(), llvm::AArch64_AM::getFP32Imm(), llvm::ARM_AM::getFP32Imm(), llvm::AArch64_AM::getFP64Imm(), llvm::ARM_AM::getFP64Imm(), llvm::TargetTransformInfoImplCRTPBase< AMDGPUTTIImpl >::getGEPCost(), llvm::BPFTTIImpl::getIntImmCost(), llvm::SystemZTTIImpl::getIntImmCost(), llvm::PPCTTIImpl::getIntImmCost(), llvm::LanaiTTIImpl::getIntImmCost(), llvm::AArch64TTIImpl::getIntImmCost(), llvm::ARMTTIImpl::getIntImmCost(), llvm::X86TTIImpl::getIntImmCost(), llvm::SystemZTTIImpl::getIntImmCostInst(), llvm::RISCVTTIImpl::getIntImmCostInst(), llvm::PPCTTIImpl::getIntImmCostInst(), llvm::ARMTTIImpl::getIntImmCostInst(), llvm::SystemZTTIImpl::getIntImmCostIntrin(), llvm::PPCTTIImpl::getIntImmCostIntrin(), llvm::AArch64TTIImpl::getIntImmCostIntrin(), llvm::X86TTIImpl::getIntImmCostIntrin(), llvm::RISCVMatInt::getIntMatCost(), llvm::GetPointerBaseWithConstantOffset(), llvm::getPointersDiff(), llvm::getPtrStride(), getSalvageOpsForGEP(), llvm::ConstantInt::getSExtValue(), llvm::getStrideFromPointer(), getVShiftImm(), llvm::TargetTransformInfoImplBase::isConstantStridedAccessLessThan(), llvm::RISCVTargetLowering::isDesirableToCommuteWithShift(), llvm::SIInstrInfo::isInlineConstant(), llvm::AMDGPULegalizerInfo::legalizeExtractVectorElt(), llvm::AMDGPULegalizerInfo::legalizeInsertVectorElt(), LLVMGenericValueToInt(), llvm::AsmPrinter::lowerConstant(), llvm::AArch64TargetLowering::shouldConvertConstantLoadToIntImm(), llvm::TargetLowering::SimplifySetCC(), toString(), and tryCombineShiftImm().

◆ getSignedMaxValue()

static APInt llvm::APInt::getSignedMaxValue ( unsigned  numBits)
inlinestatic

◆ getSignedMinValue()

static APInt llvm::APInt::getSignedMinValue ( unsigned  numBits)
inlinestatic

◆ getSignMask()

static APInt llvm::APInt::getSignMask ( unsigned  BitWidth)
inlinestatic

◆ getSplat()

APInt APInt::getSplat ( unsigned  NewLen,
const APInt V 
)
static

◆ getZExtValue()

uint64_t llvm::APInt::getZExtValue ( ) const
inline

Get zero extended value.

This method attempts to return the value of this APInt as a zero extended uint64_t. The bitwidth must be <= 64 or the value must fit within a uint64_t. Otherwise an assertion will result.

Definition at line 1631 of file APInt.h.

References assert().

Referenced by llvm::DwarfExpression::addConstantFP(), llvm::DwarfUnit::addConstantValue(), llvm::KnownBits::ashr(), canEvaluateShiftedShift(), canEvaluateZExtd(), checkMDProf(), collectBitParts(), combineCMov(), combineCMP(), combineExtractWithShuffle(), llvm::PPCInstrInfo::combineRLWINM(), combineShiftAnd1ToBitTest(), CombineVMOVDRRCandidateWithVecOp(), llvm::AMDGPUTargetLowering::computeKnownBitsForTargetNode(), computeKnownBitsFromShiftOperator(), llvm::computeMinimumValueSizes(), llvm::X86TargetLowering::ComputeNumSignBitsForTargetNode(), ComputeNumSignBitsImpl(), llvm::ConstantFoldTerminator(), convertIntToDoubleImm(), llvm::Interpreter::exitCalled(), llvm::SIInstrInfo::expandMovDPP64(), llvm::SIInstrInfo::expandPostRAPseudo(), ExtractConstantBytes(), llvm::extractConstantMask(), extractShiftForRotate(), llvm::InstCombinerImpl::foldICmpShlConstant(), llvm::InstCombinerImpl::foldICmpTruncConstant(), llvm::InstCombinerImpl::FoldShiftByConstant(), GetBranchWeights(), llvm::ExecutionEngine::getConstantValue(), llvm::Function::getEntryCount(), getExtMask(), llvm::AArch64_AM::getFP16Imm(), llvm::ARM_AM::getFP16Imm(), llvm::AArch64_AM::getFP32Imm(), llvm::ARM_AM::getFP32Imm(), llvm::AArch64_AM::getFP64Imm(), llvm::ARM_AM::getFP64Imm(), getFpImmVal(), llvm::SystemZTTIImpl::getIntImmCost(), llvm::PPCTTIImpl::getIntImmCost(), llvm::LanaiTTIImpl::getIntImmCost(), llvm::ARMTTIImpl::getIntImmCost(), llvm::SystemZTTIImpl::getIntImmCostInst(), llvm::PPCTTIImpl::getIntImmCostInst(), llvm::X86TTIImpl::getIntImmCostInst(), llvm::SystemZTTIImpl::getIntImmCostIntrin(), llvm::SelectionDAG::getNode(), llvm::getObjectSize(), getVariantMatchScore(), llvm::ConstantInt::getZExtValue(), IncorporateWeight(), llvm::mca::initializeUsedResources(), isEXTMask(), llvm::AArch64TargetLowering::isFPImmLegal(), isKnownTypeIdMember(), llvm::SystemZVectorConstantInfo::isVectorConstantLegal(), LLVMGenericValueToInt(), llvm::WebAssemblyMCInstLower::lower(), LowerScalarImmediateShift(), llvm::KnownBits::lshr(), matchAndOrChain(), NormalizeBuildVector(), optimizeLogicalImm(), parseHexOcta(), PerformANDCombine(), llvm::AMDGPUTargetLowering::PerformDAGCombine(), performDSPShiftCombine(), PerformORCombine(), PerformVMOVrhCombine(), printConstant(), llvm::NVPTXFloatMCExpr::printImpl(), llvm::ExecutionEngine::runFunctionAsMain(), llvm::PPCTargetLowering::SelectAddressRegImm(), llvm::PPCTargetLowering::SelectAddressRegImm34(), selectI64ImmDirect(), selectI64ImmDirectPrefix(), llvm::AVRDAGToDAGISel::SelectInlineAsmMemoryOperand(), llvm::KnownBits::shl(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::InstCombinerImpl::SimplifyMultipleUseDemandedBits(), llvm::InstCombinerImpl::simplifyShrShlDemandedBits(), simplifyX86extrq(), simplifyX86insertq(), simplifyX86varShift(), toString(), llvm::detail::IEEEFloat::toString(), toString(), tryBitfieldInsertOpFromOrAndImm(), llvm::tryPromoteCall(), udivrem(), urem(), llvm::Interpreter::visitAllocaInst(), llvm::InstCombinerImpl::visitAnd(), llvm::InstCombinerImpl::visitAShr(), llvm::Interpreter::visitAShr(), llvm::Interpreter::visitExtractElementInst(), llvm::Interpreter::visitInsertElementInst(), llvm::InstCombinerImpl::visitLShr(), llvm::Interpreter::visitLShr(), llvm::InstCombinerImpl::visitShl(), llvm::Interpreter::visitShl(), and WriteConstantInternal().

◆ insertBits() [1/2]

void APInt::insertBits ( const APInt SubBits,
unsigned  bitPosition 
)

◆ insertBits() [2/2]

void APInt::insertBits ( uint64_t  SubBits,
unsigned  bitPosition,
unsigned  numBits 
)

Definition at line 399 of file APInt.cpp.

◆ intersects()

bool llvm::APInt::intersects ( const APInt RHS) const
inline

◆ isAllOnesValue()

bool llvm::APInt::isAllOnesValue ( ) const
inline

Determine if all bits are set.

This checks to see if the value has all bits of the APInt are set or not.

Definition at line 401 of file APInt.h.

References llvm::BitWidth.

Referenced by areUsedBitsDense(), llvm::TargetLowering::BuildSDIV(), clearAssumptionsOfUsers(), combineSetCCMOVMSK(), combineX86ShufflesRecursively(), createAndInstr(), EltsFromConsecutiveLoads(), llvm::extractConstantMask(), findDemandedEltsByAllUsers(), llvm::InstCombinerImpl::foldICmpDivConstant(), llvm::InstCombinerImpl::foldICmpShrConstConst(), llvm::ARMTTIImpl::getIntImmCostInst(), getTargetConstantBitsFromNode(), llvm::KnownBits::isAllOnes(), llvm::ISD::isConstantSplatVectorAllOnes(), llvm::TargetLowering::isConstTrueVal(), llvm::ConstantInt::isMinusOne(), isMultiple(), llvm::isSafeToSpeculativelyExecute(), isSelect01(), llvm::InstCombiner::isSignBitCheck(), isVectorAllOnes(), llvm::KnownBits::isZero(), lowerShuffleAsVTRUNC(), lowerShuffleWithVPMOV(), lowerVECTOR_SHUFFLE(), makeExactMulNSWRegion(), matchShuffleAsEXTRQ(), matchShuffleAsVTRUNC(), llvm::recognizeBSwapOrBitReverseIdiom(), llvm::ConstantRange::sdiv(), sdiv_ov(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::InstCombinerImpl::SimplifyDemandedVectorElts(), llvm::TargetLowering::SimplifyDemandedVectorElts(), llvm::X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode(), llvm::X86TargetLowering::SimplifyDemandedVectorEltsForTargetShuffle(), llvm::RegisterBankInfo::ValueMapping::verify(), llvm::InstCombinerImpl::visitExtractElementInst(), and llvm::InstCombinerImpl::visitOr().

◆ isIntN()

bool llvm::APInt::isIntN ( unsigned  N) const
inline

◆ isMask() [1/2]

bool llvm::APInt::isMask ( ) const
inline
Returns
true if this APInt is a non-empty sequence of ones starting at the least significant bit with the remainder zero. Ex. isMask(0x0000FFFFU) == true.

Definition at line 513 of file APInt.h.

References llvm::BitWidth, and llvm::isMask_64().

◆ isMask() [2/2]

bool llvm::APInt::isMask ( unsigned  numBits) const
inline
Returns
true if this APInt value is a sequence of
Parameters
numBitsones starting at the least significant bit with the remainder zero.

Definition at line 500 of file APInt.h.

References assert(), and llvm::BitWidth.

Referenced by combineAndMaskToShift(), combineSetCCMOVMSK(), combineShiftRightLogical(), detectUSatPattern(), llvm::InstCombinerImpl::foldAddWithConstant(), processAnd(), simplifyAMDGCNMemoryIntrinsicDemanded(), SimplifyOrInst(), and llvm::InstCombinerImpl::visitSub().

◆ isMaxSignedValue()

bool llvm::APInt::isMaxSignedValue ( ) const
inline

Determine if this is the largest signed value.

This checks to see if the value of this APInt is the maximum signed value for the APInt's bit width.

Definition at line 432 of file APInt.h.

References llvm::BitWidth.

Referenced by llvm::InstCombinerImpl::foldICmpXorConstant(), llvm::ConstantInt::isMaxValue(), llvm::InstCombiner::isSignBitCheck(), LowerVSETCC(), matchMinMax(), and SimplifySubInst().

◆ isMaxValue()

bool llvm::APInt::isMaxValue ( ) const
inline

Determine if this is the largest unsigned value.

This checks to see if the value of this APInt is the maximum unsigned value for the APInt's bit width.

Definition at line 426 of file APInt.h.

Referenced by incDecVectorConstant(), llvm::ConstantInt::isMaxValue(), and simplifyAndOrOfICmpsWithLimitConst().

◆ isMinSignedValue()

bool llvm::APInt::isMinSignedValue ( ) const
inline

◆ isMinValue()

bool llvm::APInt::isMinValue ( ) const
inline

Determine if this is the smallest unsigned value.

This checks to see if the value of this APInt is the minimum unsigned value for the APInt's bit width.

Definition at line 442 of file APInt.h.

Referenced by llvm::InstCombinerImpl::commonIRemTransforms(), llvm::InstCombinerImpl::Descale(), IncorporateWeight(), llvm::ConstantInt::isMinValue(), isMultiple(), LinearizeExprTree(), and simplifyAndOrOfICmpsWithLimitConst().

◆ isNegative()

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

Determine sign of this APInt.

This tests the high bit of this APInt to determine if it is set.

Returns
true if this APInt is negative, false otherwise

Definition at line 364 of file APInt.h.

References llvm::BitWidth.

Referenced by llvm::TargetLowering::BuildSDIV(), combineMOVMSK(), combineShiftRightArithmetic(), combineVectorPack(), llvm::SelectionDAG::computeKnownBits(), computePointerICmp(), llvm::detail::IEEEFloat::convertFromAPInt(), llvm::InstCombinerImpl::foldAddWithConstant(), llvm::InstCombinerImpl::foldICmpAndConstConst(), llvm::InstCombinerImpl::foldICmpAndShift(), llvm::InstCombinerImpl::foldICmpBinOp(), llvm::InstCombinerImpl::foldICmpMulConstant(), llvm::InstCombinerImpl::foldICmpShrConstConst(), llvm::InstCombinerImpl::foldICmpUsingKnownBits(), llvm::InstCombinerImpl::foldICmpXorConstant(), genConstMult(), getBitsNeeded(), llvm::ARMTTIImpl::getIntImmCostInst(), getRangeForAffineARHelper(), llvm::ScalarEvolution::isKnownNegative(), llvm::ScalarEvolution::isKnownNonNegative(), llvm::APSInt::isNegative(), llvm::ConstantInt::isNegative(), isSSATMinMaxPattern(), makeExactMulNSWRegion(), multiplicativeInverse(), llvm::APIntOps::RoundingSDiv(), sadd_sat(), sdiv(), sdivrem(), sext(), llvm::ConstantRange::signedAddMayOverflow(), llvm::ConstantRange::signedSubMayOverflow(), smul_sat(), llvm::APIntOps::SolveQuadraticEquationWrap(), srem(), sshl_sat(), ssub_sat(), llvm::RISCVTargetLowering::targetShrinkDemandedConstant(), toString(), toString(), truncSSat(), and umul_ov().

◆ isNonNegative()

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

◆ isNonPositive()

bool llvm::APInt::isNonPositive ( ) const
inline

Determine if this APInt Value is non-positive (<= 0).

Returns
true if this APInt is non-positive.

Definition at line 396 of file APInt.h.

◆ isNullValue()

bool llvm::APInt::isNullValue ( ) const
inline

Determine if all bits are clear.

This checks to see if the value has all bits of the APInt are clear or not.

Definition at line 411 of file APInt.h.

Referenced by llvm::KnownBits::abs(), bitTrackingDCE(), canWidenShuffleElements(), llvm::PPCInstrInfo::combineRLWINM(), combineSetCCAtomicArith(), combineSetCCMOVMSK(), combineX86ShufflesRecursively(), llvm::InstCombinerImpl::commonIDivTransforms(), computeKnownBitsFromOperator(), createAndInstr(), llvm::APFixedPoint::div(), EltsFromConsecutiveLoads(), foldCttzCtlz(), llvm::InstCombinerImpl::foldICmpDivConstant(), llvm::InstCombinerImpl::foldICmpMulConstant(), llvm::InstCombinerImpl::foldICmpShlConstConst(), llvm::InstCombinerImpl::foldICmpShrConstConst(), foldSelectICmpAnd(), foldSignedTruncationCheck(), getFauxShuffleMask(), getShuffleDemandedElts(), incDecVectorConstant(), llvm::ISD::isConstantSplatVectorAllZeros(), isMultiple(), llvm::KnownBits::isNonZero(), isSelect01(), llvm::InstCombiner::isSignBitCheck(), llvm::KnownBits::isStrictlyPositive(), llvm::KnownBits::isUnknown(), llvm::ConstantRange::isWrappedSet(), llvm::ConstantInt::isZero(), llvm::LegalizerHelper::narrowScalarShiftByConstant(), llvm::ConstantRange::sdiv(), llvm::ConstantRange::shl(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), llvm::X86TTIImpl::simplifyDemandedUseBitsIntrinsic(), llvm::InstCombinerImpl::SimplifyDemandedVectorElts(), SimplifyGEPInst(), simplifyIntrinsic(), llvm::TargetLowering::SimplifyMultipleUseDemandedBits(), simplifyX86immShift(), llvm::APIntOps::SolveQuadraticEquationWrap(), llvm::ConstantRange::srem(), llvm::ConstantRange::udiv(), llvm::ConstantRange::unionWith(), and llvm::ConstantRange::urem().

◆ isOneValue()

bool llvm::APInt::isOneValue ( ) const
inline

◆ isPowerOf2()

bool llvm::APInt::isPowerOf2 ( ) const
inline

◆ isSameValue()

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

Determine if two APInts have the same value, after zero-extending one of them (if needed!) to ensure that the bit-widths match.

Definition at line 678 of file APInt.h.

References getBitWidth(), and zext().

Referenced by llvm::MDNodeKeyImpl< DIEnumerator >::isKeyOf(), and llvm::PatternMatch::specific_intval< AllowUndefs >::match().

◆ isShiftedMask()

bool llvm::APInt::isShiftedMask ( ) const
inline

Return true if this APInt value contains a sequence of ones with the remainder zero.

Definition at line 522 of file APInt.h.

References llvm::BitWidth, llvm::countTrailingZeros(), and llvm::isShiftedMask_64().

Referenced by llvm::InstCombinerImpl::foldAddWithConstant().

◆ isSignBitClear()

bool llvm::APInt::isSignBitClear ( ) const
inline

Determine if sign bit of this APInt is clear.

This tests the high bit of this APInt to determine if it is clear.

Returns
true if this APInt has its sign bit clear, false otherwise.

Definition at line 383 of file APInt.h.

Referenced by llvm::KnownBits::getSignedMaxValue(), and llvm::KnownBits::getSignedMinValue().

◆ isSignBitSet()

bool llvm::APInt::isSignBitSet ( ) const
inline

Determine if sign bit of this APInt is set.

This tests the high bit of this APInt to determine if it is set.

Returns
true if this APInt has its sign bit set, false otherwise.

Definition at line 376 of file APInt.h.

References llvm::BitWidth.

Referenced by llvm::APFixedPoint::compare(), computeKnownBitsFromOperator(), llvm::KnownBits::isNegative(), llvm::KnownBits::isNonNegative(), llvm::KnownBits::isStrictlyPositive(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), and SimplifyShift().

◆ isSignedIntN()

bool llvm::APInt::isSignedIntN ( unsigned  N) const
inline

◆ isSignMask()

bool llvm::APInt::isSignMask ( ) const
inline

◆ isSplat()

bool APInt::isSplat ( unsigned  SplatSizeInBits) const

Check if the APInt consists of a repeated bit pattern.

e.g. 0x01010101 satisfies isSplat(8).

Parameters
SplatSizeInBitsThe size of the pattern in bits. Must divide bit width without remainder.

Definition at line 553 of file APInt.cpp.

References assert(), getBitWidth(), and rotl().

◆ isStrictlyPositive()

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

Determine if this APInt Value is positive.

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

Returns
true if this APInt is positive.

Definition at line 391 of file APInt.h.

References isNonNegative().

Referenced by llvm::ConstantRange::abs(), llvm::SwitchCG::SwitchLowering::buildBitTests(), llvm::TargetLowering::BuildSDIV(), ComputeNumSignBitsImpl(), llvm::ConstantRange::isAllNegative(), llvm::ScalarEvolution::isKnownNonPositive(), and llvm::ScalarEvolution::isKnownPositive().

◆ isSubsetOf()

bool llvm::APInt::isSubsetOf ( const APInt RHS) const
inline

◆ logBase2()

unsigned llvm::APInt::logBase2 ( ) const
inline

◆ lshr() [1/2]

APInt llvm::APInt::lshr ( const APInt ShiftAmt) const
inline

Logical right-shift function.

Logical right-shift this APInt by shiftAmt.

Definition at line 1036 of file APInt.h.

References llvm::RISCVFenceField::R.

◆ lshr() [2/2]

APInt llvm::APInt::lshr ( unsigned  shiftAmt) const
inline

Logical right-shift function.

Logical right-shift this APInt by shiftAmt.

Definition at line 987 of file APInt.h.

References llvm::RISCVFenceField::R.

Referenced by llvm::DwarfExpression::addConstantFP(), areUsedBitsDense(), llvm::SparcTargetLowering::bitcastConstantFPToInt(), llvm::TargetLowering::BuildUDIV(), combineShiftRightLogical(), llvm::SelectionDAG::computeKnownBits(), computeKnownBitsFromOperator(), llvm::SelectionDAG::ComputeNumSignBits(), llvm::ConstantFoldBinaryInstruction(), llvm::InstCombinerImpl::foldICmpAndShift(), llvm::InstCombinerImpl::foldICmpShlConstant(), llvm::InstCombinerImpl::foldICmpShrConstant(), llvm::InstCombinerImpl::foldICmpShrConstConst(), foldICmpWithTruncSignExtendedVal(), llvm::SelectionDAG::getConstant(), getConstVector(), getDemandedSrcElements(), llvm::AArch64_AM::getFP16Imm(), llvm::ARM_AM::getFP16Imm(), llvm::AArch64_AM::getFP32Imm(), llvm::ARM_AM::getFP32Imm(), llvm::AArch64_AM::getFP64Imm(), llvm::ARM_AM::getFP64Imm(), getHiBits(), getHopForBuildVector(), llvm::APFixedPoint::getMax(), llvm::BlockFrequencyInfoImplBase::getProfileCountFromFreq(), llvm::X86TTIImpl::instCombineIntrinsic(), llvm::BuildVectorSDNode::isConstantSplat(), llvm::SystemZVectorConstantInfo::isVectorConstantLegal(), lowerMSABinaryBitImmIntr(), llvm::ConstantRange::lshr(), magicu(), llvm::CombinerHelper::matchCombineUnmergeConstant(), llvm::APFixedPoint::mul(), llvm::LegalizerHelper::narrowScalar(), llvm::RISCVTargetLowering::PerformDAGCombine(), rotl(), rotr(), setLimitsForBinOp(), llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), llvm::InstCombinerImpl::SimplifyDemandedVectorElts(), llvm::X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode(), llvm::X86TTIImpl::simplifyDemandedVectorEltsIntrinsic(), llvm::InstCombinerImpl::simplifyShrShlDemandedBits(), llvm::SystemZVectorConstantInfo::SystemZVectorConstantInfo(), umul_ov(), llvm::Interpreter::visitLShr(), and llvm::InstCombinerImpl::visitXor().

◆ lshrInPlace() [1/2]

void APInt::lshrInPlace ( const APInt shiftAmt)

Logical right-shift this APInt by ShiftAmt in place.

Logical right-shift this APInt by shiftAmt.

Logical right-shift function.

Definition at line 1033 of file APInt.cpp.

References getLimitedValue(), and lshrInPlace().

◆ lshrInPlace() [2/2]

void llvm::APInt::lshrInPlace ( unsigned  ShiftAmt)
inline

◆ magic()

APInt::ms APInt::magic ( ) const

Calculate the magic numbers required to implement a signed integer division by a constant as a sequence of multiplies, adds and shifts.

Requires that the divisor not be 0, 1, or -1. Taken from "Hacker's Delight", Henry S. Warren, Jr., chapter 10.

Definition at line 1225 of file APInt.cpp.

References d, getSignedMinValue(), llvm::APInt::ms::m, p, r1, r2, llvm::APInt::ms::s, udiv(), ult(), and urem().

Referenced by llvm::TargetLowering::BuildSDIV().

◆ magicu()

APInt::mu APInt::magicu ( unsigned  LeadingZeros = 0) const

Calculate the magic numbers required to implement an unsigned integer division by a constant as a sequence of multiplies, adds and shifts.

Requires that the divisor not be 0. Taken from "Hacker's Delight", Henry S. Warren, Jr., chapter 10. LeadingZeros can be used to simplify the calculation if the upper bits of the divided value are known zero.

Definition at line 1269 of file APInt.cpp.

References llvm::APInt::mu::a, allOnes(), d, getAllOnesValue(), getSignedMaxValue(), getSignedMinValue(), lshr(), llvm::APInt::mu::m, p, r1, r2, llvm::APInt::mu::s, udiv(), uge(), ult(), and urem().

Referenced by llvm::TargetLowering::BuildUDIV().

◆ multiplicativeInverse()

APInt APInt::multiplicativeInverse ( const APInt modulo) const

Computes the multiplicative inverse of this APInt for a given modulo.

Returns
the multiplicative inverse for a given modulo.

The iterative extended Euclidean algorithm is used to solve for this value, however we simplify it to speed up calculating only the inverse, and take advantage of div+rem calculations. We also use some tricks to avoid copying (potentially large) APInts around. WARNING: a value of '0' may be returned, signifying that no multiplicative inverse exists!

Definition at line 1179 of file APInt.cpp.

References APInt(), assert(), i, isNegative(), move, udivrem(), and ult().

Referenced by BinomialCoefficient(), and SolveLinEquationWithOverflow().

◆ ne()

bool llvm::APInt::ne ( const APInt RHS) const
inline

Inequality comparison.

Compares this APInt with RHS for the validity of the inequality relationship.

Returns
true if *this != Val

Definition at line 1197 of file APInt.h.

◆ nearestLogBase2()

unsigned llvm::APInt::nearestLogBase2 ( ) const
inline
Returns
the nearest log base 2 of this APInt. Ties round up.

NOTE: When we have a BitWidth of 1, we define:

log2(0) = UINT32_MAX log2(1) = 0

to get around any mathematical concerns resulting from referencing 2 in a space where 2 does no exist.

Definition at line 1834 of file APInt.h.

References llvm::BitWidth.

◆ needsCleanup()

bool llvm::APInt::needsCleanup ( ) const
inline

Returns whether this instance allocated memory.

Definition at line 349 of file APInt.h.

◆ negate()

void llvm::APInt::negate ( )
inline

Negate this APInt in place.

Definition at line 1563 of file APInt.h.

Referenced by llvm::InstCombinerImpl::foldICmpDivConstant(), llvm::operator-(), sdivrem(), and toString().

◆ operator!()

bool llvm::APInt::operator! ( ) const
inline

Logical negation operator.

Performs logical negation operation on this APInt.

Returns
true if *this is zero, false otherwise.

Definition at line 741 of file APInt.h.

References llvm::BitWidth.

◆ operator!=() [1/2]

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

Inequality operator.

Compares this APInt with RHS for the validity of the inequality relationship.

Returns
true if *this != Val

Definition at line 1181 of file APInt.h.

◆ operator!=() [2/2]

bool llvm::APInt::operator!= ( uint64_t  Val) const
inline

Inequality operator.

Compares this APInt with a uint64_t for the validity of the inequality relationship.

Returns
true if *this != Val

Definition at line 1189 of file APInt.h.

◆ operator&=() [1/2]

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

Bitwise AND assignment operator.

Performs a bitwise AND operation on this APInt and RHS. The result is assigned to *this.

Returns
*this after ANDing with RHS.

Definition at line 810 of file APInt.h.

References assert(), llvm::BitWidth, and VAL.

◆ operator&=() [2/2]

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

Bitwise AND assignment operator.

Performs a bitwise AND operation on this APInt and RHS. RHS is logically zero-extended or truncated to match the bit-width of the LHS.

Definition at line 824 of file APInt.h.

References VAL.

◆ operator*()

APInt APInt::operator* ( const APInt RHS) const

Multiplication operator.

Multiplies this APInt by RHS and returns the result.

Definition at line 230 of file APInt.cpp.

References APInt(), assert(), getBitWidth(), getMemory(), getNumWords(), pVal, tcMultiply(), and VAL.

◆ operator*=() [1/2]

APInt & APInt::operator*= ( const APInt RHS)

Multiplication assignment operator.

Multiplies this APInt by RHS and assigns the result to *this.

Returns
*this

Definition at line 255 of file APInt.cpp.

References assert().

◆ operator*=() [2/2]

APInt & APInt::operator*= ( uint64_t  RHS)

Definition at line 261 of file APInt.cpp.

References getNumWords(), and tcMultiplyPart().

◆ operator++() [1/2]

APInt & APInt::operator++ ( )

Prefix increment operator.

Prefix increment operator. Increments the APInt by one.

Returns
*this incremented by one

Definition at line 173 of file APInt.cpp.

References getNumWords(), and tcIncrement().

◆ operator++() [2/2]

const APInt llvm::APInt::operator++ ( int  )
inline

Postfix increment operator.

Increments *this by 1.

Returns
a new APInt value representing the original value of *this.

Definition at line 709 of file APInt.h.

◆ operator+=() [1/2]

APInt & APInt::operator+= ( const APInt RHS)

Addition assignment operator.

Adds the RHS APInt to this APInt.

Adds RHS to *this and assigns the result to *this.

Returns
*this
this, after addition of RHS. Addition assignment operator.

Definition at line 193 of file APInt.cpp.

References assert(), getNumWords(), pVal, tcAdd(), and VAL.

◆ operator+=() [2/2]

APInt & APInt::operator+= ( uint64_t  RHS)

Definition at line 202 of file APInt.cpp.

References getNumWords(), and tcAddPart().

◆ operator--() [1/2]

APInt & APInt::operator-- ( )

Prefix decrement operator.

Prefix decrement operator. Decrements the APInt by one.

Returns
*this decremented by one.

Definition at line 182 of file APInt.cpp.

References getNumWords(), and tcDecrement().

◆ operator--() [2/2]

const APInt llvm::APInt::operator-- ( int  )
inline

Postfix decrement operator.

Decrements *this by 1.

Returns
a new APInt value representing the original value of *this.

Definition at line 725 of file APInt.h.

◆ operator-=() [1/2]

APInt & APInt::operator-= ( const APInt RHS)

Subtraction assignment operator.

Subtracts the RHS APInt from this APInt.

Subtracts RHS from *this and assigns the result to *this.

Returns
*this
this, after subtraction Subtraction assignment operator.

Definition at line 213 of file APInt.cpp.

References assert(), getNumWords(), pVal, tcSubtract(), and VAL.

◆ operator-=() [2/2]

APInt & APInt::operator-= ( uint64_t  RHS)

Definition at line 222 of file APInt.cpp.

References getNumWords(), and tcSubtractPart().

◆ operator<<() [1/2]

APInt llvm::APInt::operator<< ( const APInt Bits) const
inline

Left logical shift operator.

Shifts this APInt left by Bits and returns the result.

Definition at line 958 of file APInt.h.

References llvm::tgtok::Bits, and shl.

◆ operator<<() [2/2]

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

Left logical shift operator.

Shifts this APInt left by Bits and returns the result.

Definition at line 953 of file APInt.h.

References llvm::tgtok::Bits, and shl.

◆ operator<<=() [1/2]

APInt & APInt::operator<<= ( const APInt shiftAmt)

Left-shift assignment function.

Left-shift this APInt by shiftAmt.

Shifts *this left by shiftAmt and assigns the result to *this.

Returns
*this after shifting left by ShiftAmt

Left-shift function.

Definition at line 1045 of file APInt.cpp.

References getLimitedValue().

◆ operator<<=() [2/2]

APInt& llvm::APInt::operator<<= ( unsigned  ShiftAmt)
inline

Left-shift assignment function.

Shifts *this left by shiftAmt and assigns the result to *this.

Returns
*this after shifting left by ShiftAmt

Definition at line 921 of file APInt.h.

References assert(), llvm::BitWidth, and clearUnusedBits().

◆ operator=() [1/3]

APInt& llvm::APInt::operator= ( APInt &&  that)
inline

Move assignment operator.

Definition at line 767 of file APInt.h.

References assert(), llvm::BitWidth, memcpy(), and that.

◆ operator=() [2/3]

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

Copy assignment operator.

Returns
*this after assignment of RHS.

Definition at line 754 of file APInt.h.

References llvm::BitWidth, clearUnusedBits(), and VAL.

Referenced by llvm::APSInt::operator=().

◆ operator=() [3/3]

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

Assignment operator.

The RHS value is assigned to *this. If the significant bits in RHS exceed the bit width, the excess bits are truncated. If the bit width is larger than 64, the value is zero filled in the unspecified high order bits.

Returns
*this after assignment of RHS value.

Definition at line 794 of file APInt.h.

References clearUnusedBits(), and VAL.

◆ operator==() [1/2]

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

Equality operator.

Compares this APInt with RHS for the validity of the equality relationship.

Definition at line 1150 of file APInt.h.

References assert(), llvm::BitWidth, and VAL.

◆ operator==() [2/2]

bool llvm::APInt::operator== ( uint64_t  Val) const
inline

Equality operator.

Compares this APInt with a uint64_t for the validity of the equality relationship.

Returns
true if *this == Val

Definition at line 1163 of file APInt.h.

◆ operator[]()

bool llvm::APInt::operator[] ( unsigned  bitPosition) const
inline

Array-indexing support.

Returns
the bit value at bitPosition

Definition at line 1137 of file APInt.h.

References assert(), and getBitWidth().

◆ operator^=() [1/2]

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

Bitwise XOR assignment operator.

Performs a bitwise XOR operation on this APInt and RHS. The result is assigned to *this.

Returns
*this after XORing with RHS.

Definition at line 869 of file APInt.h.

References assert(), llvm::BitWidth, and VAL.

◆ operator^=() [2/2]

APInt& llvm::APInt::operator^= ( uint64_t  RHS)
inline

Bitwise XOR assignment operator.

Performs a bitwise XOR operation on this APInt and RHS. RHS is logically zero-extended or truncated to match the bit-width of the LHS.

Definition at line 883 of file APInt.h.

References clearUnusedBits(), and VAL.

◆ operator|=() [1/2]

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

Bitwise OR assignment operator.

Performs a bitwise OR operation on this APInt and RHS. The result is assigned *this;

Returns
*this after ORing with RHS.

Definition at line 840 of file APInt.h.

References assert(), llvm::BitWidth, and VAL.

◆ operator|=() [2/2]

APInt& llvm::APInt::operator|= ( uint64_t  RHS)
inline

Bitwise OR assignment operator.

Performs a bitwise OR operation on this APInt and RHS. RHS is logically zero-extended or truncated to match the bit-width of the LHS.

Definition at line 854 of file APInt.h.

References clearUnusedBits(), and VAL.

◆ print()

void APInt::print ( raw_ostream OS,
bool  isSigned 
) const

Definition at line 2298 of file APInt.cpp.

References S, and toString().

◆ Profile()

void APInt::Profile ( FoldingSetNodeID id) const

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

This method 'profiles' an APInt for use with FoldingSet.

Definition at line 159 of file APInt.cpp.

References getNumWords(), and i.

Referenced by llvm::APSInt::Profile().

◆ reverseBits()

APInt APInt::reverseBits ( ) const
Returns
the value with the bit representation reversed of this APInt Value.

Definition at line 691 of file APInt.cpp.

References APInt(), lshrInPlace(), and S.

Referenced by computeKnownBitsFromOperator(), determineLiveOperandBitsAddCarry(), llvm::SelectionDAG::getNode(), llvm::KnownBits::reverseBits(), and llvm::TargetLowering::SimplifyDemandedBits().

◆ rotl() [1/2]

APInt APInt::rotl ( const APInt rotateAmt) const

Rotate left by rotateAmt.

Definition at line 1069 of file APInt.cpp.

References rotateModulo(), and rotl().

◆ rotl() [2/2]

APInt APInt::rotl ( unsigned  rotateAmt) const

Rotate left by rotateAmt.

Definition at line 1073 of file APInt.cpp.

References lshr(), and shl().

Referenced by llvm::PPCInstrInfo::combineRLWINM(), isSplat(), and rotl().

◆ rotr() [1/2]

APInt APInt::rotr ( const APInt rotateAmt) const

Rotate right by rotateAmt.

Definition at line 1080 of file APInt.cpp.

References rotateModulo(), and rotr().

◆ rotr() [2/2]

APInt APInt::rotr ( unsigned  rotateAmt) const

Rotate right by rotateAmt.

Definition at line 1084 of file APInt.cpp.

References lshr(), and shl().

Referenced by rotr(), selectI64ImmDirect(), and selectI64ImmDirectPrefix().

◆ roundToDouble() [1/2]

double llvm::APInt::roundToDouble ( ) const
inline

Converts this unsigned APInt to a double value.

Definition at line 1772 of file APInt.h.

References roundToDouble().

Referenced by roundToDouble().

◆ roundToDouble() [2/2]

double APInt::roundToDouble ( bool  isSigned) const

Converts this APInt to a double value.

This function converts this APInt to a double.

The layout for double is as following (IEEE Standard 754):

Sign Exponent Fraction Bias
1[63] 11[62-52] 52[51-00] 1023

Definition at line 801 of file APInt.cpp.

References APINT_BITS_PER_WORD, assert(), double, getActiveBits(), I, n, pVal, sext(), and llvm::SignExtend64().

Referenced by llvm::ExecutionEngine::getConstantValue(), and llvm::APIntOps::RoundAPIntToDouble().

◆ sadd_ov()

APInt APInt::sadd_ov ( const APInt RHS,
bool &  Overflow 
) const

◆ sadd_sat()

APInt APInt::sadd_sat ( const APInt RHS) const

◆ sdiv() [1/2]

APInt APInt::sdiv ( const APInt RHS) const

◆ sdiv() [2/2]

APInt APInt::sdiv ( int64_t  RHS) const

Definition at line 1682 of file APInt.cpp.

References isNegative(), and udiv().

◆ sdiv_ov()

APInt APInt::sdiv_ov ( const APInt RHS,
bool &  Overflow 
) const

Definition at line 1981 of file APInt.cpp.

References isAllOnesValue(), isMinSignedValue(), and sdiv().

◆ sdivrem() [1/2]

void APInt::sdivrem ( const APInt LHS,
const APInt RHS,
APInt Quotient,
APInt Remainder 
)
static

◆ sdivrem() [2/2]

void APInt::sdivrem ( const APInt LHS,
int64_t  RHS,
APInt Quotient,
int64_t &  Remainder 
)
static

Definition at line 1935 of file APInt.cpp.

References isNegative(), negate(), llvm::RISCVFenceField::R, and udivrem().

◆ setAllBits()

void llvm::APInt::setAllBits ( )
inline

◆ setBit()

void llvm::APInt::setBit ( unsigned  BitPosition)
inline

◆ setBits()

void llvm::APInt::setBits ( unsigned  loBit,
unsigned  hiBit 
)
inline

Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.

This function handles case when loBit <= hiBit.

Definition at line 1481 of file APInt.h.

References assert(), and llvm::BitWidth.

Referenced by llvm::LanaiTargetLowering::computeKnownBitsForTargetNode(), llvm::extractConstantMask(), getBitsSet(), getTargetConstantBitsFromNode(), llvm::BuildVectorSDNode::isConstantSplat(), matchBinaryShuffle(), and llvm::TargetLowering::SimplifyDemandedVectorElts().

◆ setBitsFrom()

void llvm::APInt::setBitsFrom ( unsigned  loBit)
inline

◆ setBitsWithWrap()

void llvm::APInt::setBitsWithWrap ( unsigned  loBit,
unsigned  hiBit 
)
inline

Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.

This function handles "wrap" case when loBit >= hiBit, and calls setBits when loBit < hiBit. For loBit == hiBit wrap case, set every bit to 1.

Definition at line 1468 of file APInt.h.

References assert(), and llvm::BitWidth.

Referenced by getBitsSetWithWrap().

◆ setBitVal()

void llvm::APInt::setBitVal ( unsigned  BitPosition,
bool  BitValue 
)
inline

◆ setHighBits()

void llvm::APInt::setHighBits ( unsigned  hiBits)
inline

◆ setLowBits()

void llvm::APInt::setLowBits ( unsigned  loBits)
inline

◆ setSignBit()

void llvm::APInt::setSignBit ( )
inline

◆ sext()

APInt APInt::sext ( unsigned  width) const

◆ sextOrSelf()

APInt APInt::sextOrSelf ( unsigned  width) const

Sign extend or truncate to width.

Make this APInt have the bit width given by width. The value is sign extended, or left alone to make it that width.

Definition at line 976 of file APInt.cpp.

References sext().

Referenced by llvm::ConstantRange::castOp(), llvm::APFixedPoint::div(), llvm::APFixedPoint::mul(), llvm::APFixedPoint::shl(), and SolveQuadraticAddRecRange().

◆ sextOrTrunc()

APInt APInt::sextOrTrunc ( unsigned  width) const

◆ sge() [1/2]

bool llvm::APInt::sge ( const APInt RHS) const
inline

Signed greater or equal comparison.

Regards both *this and RHS as signed quantities and compares them for validity of the greater-or-equal relationship.

Returns
true if *this >= RHS when both are considered signed.

Definition at line 1329 of file APInt.h.

Referenced by llvm::ConstantFoldCompareInstruction(), performMulCombine(), simplifyBinaryIntrinsic(), and TryMULWIDECombine().

◆ sge() [2/2]

bool llvm::APInt::sge ( int64_t  RHS) const
inline

Signed greater or equal comparison.

Regards both *this as a signed quantity and compares it with RHS for the validity of the greater-or-equal relationship.

Returns
true if *this >= RHS when considered signed.

Definition at line 1337 of file APInt.h.

◆ sgt() [1/2]

bool llvm::APInt::sgt ( const APInt RHS) const
inline

◆ sgt() [2/2]

bool llvm::APInt::sgt ( int64_t  RHS) const
inline

Signed greater than comparison.

Regards both *this as a signed quantity and compares it with RHS for the validity of the greater-than relationship.

Returns
true if *this > RHS when considered signed.

Definition at line 1302 of file APInt.h.

◆ shl() [1/2]

APInt llvm::APInt::shl ( const APInt ShiftAmt) const
inline

Left-shift function.

Left-shift this APInt by shiftAmt.

Definition at line 1048 of file APInt.h.

References llvm::RISCVFenceField::R.

◆ shl() [2/2]

APInt llvm::APInt::shl ( unsigned  shiftAmt) const
inline

◆ signedRoundToDouble()

double llvm::APInt::signedRoundToDouble ( ) const
inline

Converts this signed APInt to a double value.

Definition at line 1775 of file APInt.h.

Referenced by llvm::ExecutionEngine::getConstantValue(), llvm::APIntOps::RoundSignedAPIntToDouble(), and llvm::APIntOps::RoundSignedAPIntToFloat().

◆ sle() [1/2]

bool llvm::APInt::sle ( const APInt RHS) const
inline

Signed less or equal comparison.

Regards both *this and RHS as signed quantities and compares them for validity of the less-or-equal relationship.

Returns
true if *this <= RHS when both are considered signed.

Definition at line 1259 of file APInt.h.

Referenced by llvm::SelectionDAG::computeKnownBits(), llvm::SelectionDAG::ComputeNumSignBits(), llvm::ConstantFoldCompareInstruction(), llvm::InstCombinerImpl::foldICmpUsingKnownBits(), isSignedMinMaxClamp(), performMulCombine(), llvm::KnownBits::sgt(), and simplifyBinaryIntrinsic().

◆ sle() [2/2]

bool llvm::APInt::sle ( uint64_t  RHS) const
inline

Signed less or equal comparison.

Regards both *this as a signed quantity and compares it with RHS for the validity of the less-or-equal relationship.

Returns
true if *this <= RHS when considered signed.

Definition at line 1267 of file APInt.h.

◆ slt() [1/2]

bool llvm::APInt::slt ( const APInt RHS) const
inline

◆ slt() [2/2]

bool llvm::APInt::slt ( int64_t  RHS) const
inline

Signed less than comparison.

Regards both *this as a signed quantity and compares it with RHS for the validity of the less-than relationship.

Returns
true if *this < RHS when considered signed.

Definition at line 1232 of file APInt.h.

◆ smul_ov()

APInt APInt::smul_ov ( const APInt RHS,
bool &  Overflow 
) const

Definition at line 1987 of file APInt.cpp.

References sdiv().

Referenced by llvm::checkedMul(), llvm::APFixedPoint::mul(), MulWillOverflow(), and smul_sat().

◆ smul_sat()

APInt APInt::smul_sat ( const APInt RHS) const

◆ sqrt()

APInt APInt::sqrt ( ) const

Compute the square root.

Definition at line 1098 of file APInt.cpp.

References APInt(), assert(), getActiveBits(), i, round(), shl(), udiv(), ule(), and ult().

◆ srem() [1/2]

APInt APInt::srem ( const APInt RHS) const

◆ srem() [2/2]

int64_t APInt::srem ( int64_t  RHS) const

Definition at line 1774 of file APInt.cpp.

References isNegative(), and urem().

◆ sshl_ov()

APInt APInt::sshl_ov ( const APInt Amt,
bool &  Overflow 
) const

Definition at line 2014 of file APInt.cpp.

References APInt(), llvm::BitWidth, countLeadingOnes(), countLeadingZeros(), getBitWidth(), isNonNegative(), and uge().

Referenced by sshl_sat().

◆ sshl_sat()

APInt APInt::sshl_sat ( const APInt RHS) const

◆ ssub_ov()

APInt APInt::ssub_ov ( const APInt RHS,
bool &  Overflow 
) const

◆ ssub_sat()

APInt APInt::ssub_sat ( const APInt RHS) const

◆ tcAdd()

APInt::WordType APInt::tcAdd ( WordType dst,
const WordType rhs,
WordType  carry,
unsigned  parts 
)
static

DST += RHS + CARRY where CARRY is zero or one. Returns the carry flag.

Definition at line 2449 of file APInt.cpp.

References assert(), c, i, and l.

Referenced by operator+=().

◆ tcAddPart()

APInt::WordType APInt::tcAddPart ( WordType dst,
WordType  src,
unsigned  parts 
)
static

DST += RHS. Returns the carry flag.

This function adds a single "word" integer, src, to the multiple "word" integer array, dst[].

dst[] is modified to reflect the addition and 1 is returned if there is a carry out, otherwise 0 is returned.

Returns
the carry of the addition.

Definition at line 2471 of file APInt.cpp.

References i.

Referenced by operator+=().

◆ tcAnd()

void APInt::tcAnd ( WordType dst,
const WordType rhs,
unsigned  parts 
)
static

The obvious AND, OR and XOR and complement operations.

Definition at line 2764 of file APInt.cpp.

References i.

◆ tcAssign()

void APInt::tcAssign ( WordType dst,
const WordType src,
unsigned  parts 
)
static

◆ tcClearBit()

void APInt::tcClearBit ( WordType parts,
unsigned  bit 
)
static

Clear the given bit of a bignum. Zero-based.

Definition at line 2380 of file APInt.cpp.

References bit.

Referenced by llvm::detail::IEEEFloat::makeNaN().

◆ tcCompare()

int APInt::tcCompare ( const WordType lhs,
const WordType rhs,
unsigned  parts 
)
static

Comparison (unsigned) of two bignums.

Definition at line 2788 of file APInt.cpp.

Referenced by llvm::detail::IEEEFloat::compareAbsoluteValue(), and tcDivide().

◆ tcComplement()

void APInt::tcComplement ( WordType dst,
unsigned  parts 
)
static

Definition at line 2782 of file APInt.cpp.

References i.

Referenced by tcNegate().

◆ tcDecrement()

static WordType llvm::APInt::tcDecrement ( WordType dst,
unsigned  parts 
)
inlinestatic

Decrement a bignum in-place. Return the borrow flag.

Definition at line 2009 of file APInt.h.

Referenced by llvm::detail::IEEEFloat::next(), and operator--().

◆ tcDivide()

int APInt::tcDivide ( WordType lhs,
const WordType rhs,
WordType remainder,
WordType scratch,
unsigned  parts 
)
static

If RHS is zero LHS and REMAINDER are left unchanged, return one.

Otherwise set LHS to LHS / RHS with the fractional part discarded, set REMAINDER to the remainder, return zero. i.e.

OLD_LHS = RHS * LHS + REMAINDER

SCRATCH is a bignum of the same size as the operands and result for use by the routine; its contents need not be initialized and are destroyed. LHS, REMAINDER and SCRATCH must be distinct.

Definition at line 2669 of file APInt.cpp.

References APINT_BITS_PER_WORD, assert(), llvm::ScaledNumbers::compare(), n, remainder, tcAssign(), tcCompare(), tcMSB(), tcSet(), tcShiftLeft(), tcShiftRight(), and tcSubtract().

◆ tcExtract()

void APInt::tcExtract ( WordType dst,
unsigned  dstCount,
const WordType src,
unsigned  srcBits,
unsigned  srcLSB 
)
static

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.

All high bits above srcBITS in DST are zero-filled.

Definition at line 2419 of file APInt.cpp.

References APINT_BITS_PER_WORD, assert(), lowBitMask(), n, shift, tcAssign(), and tcShiftRight().

◆ tcExtractBit()

int APInt::tcExtractBit ( const WordType parts,
unsigned  bit 
)
static

◆ tcFullMultiply()

void APInt::tcFullMultiply ( WordType dst,
const WordType lhs,
const WordType rhs,
unsigned  lhsParts,
unsigned  rhsParts 
)
static

DST = LHS * RHS, where DST has width the sum of the widths of the operands.

No overflow occurs. DST must be disjoint from both operands.

Definition at line 2644 of file APInt.cpp.

References assert(), i, tcMultiplyPart(), and tcSet().

Referenced by llvm::powerOf5().

◆ tcIncrement()

static WordType llvm::APInt::tcIncrement ( WordType dst,
unsigned  parts 
)
inlinestatic

Increment a bignum in-place. Return the carry flag.

Definition at line 2004 of file APInt.h.

Referenced by operator++(), and tcNegate().

◆ tcIsZero()

bool APInt::tcIsZero ( const WordType src,
unsigned  parts 
)
static

Returns true if a bignum is zero, false otherwise.

Definition at line 2361 of file APInt.cpp.

References i.

Referenced by llvm::detail::IEEEFloat::makeNaN().

◆ tcLSB()

unsigned APInt::tcLSB ( const WordType parts,
unsigned  n 
)
static

Returns the bit number of the least or most significant set bit of a number.

If the input number has no bits set -1U is returned.

Definition at line 2386 of file APInt.cpp.

References APINT_BITS_PER_WORD, i, n, and partLSB().

Referenced by llvm::lostFractionThroughTruncation().

◆ tcMSB()

unsigned APInt::tcMSB ( const WordType parts,
unsigned  n 
)
static

Definition at line 2400 of file APInt.cpp.

References APINT_BITS_PER_WORD, n, and partMSB().

Referenced by tcDivide().

◆ tcMultiply()

int APInt::tcMultiply ( WordType dst,
const WordType lhs,
const WordType rhs,
unsigned  parts 
)
static

DST = LHS * RHS, where DST has the same width as the operands and is filled with the least significant parts of the result.

Returns one if overflow occurred, otherwise zero. DST must be disjoint from both operands.

Definition at line 2628 of file APInt.cpp.

References assert(), i, tcMultiplyPart(), and tcSet().

Referenced by operator*().

◆ tcMultiplyPart()

int APInt::tcMultiplyPart ( WordType dst,
const WordType src,
WordType  multiplier,
WordType  carry,
unsigned  srcParts,
unsigned  dstParts,
bool  add 
)
static

DST += SRC * MULTIPLIER + PART if add is true DST = SRC * MULTIPLIER + PART if add is false.

Requires 0 <= DSTPARTS <= SRCPARTS + 1. If DST overlaps SRC they must start at the same point, i.e. DST == SRC.

If DSTPARTS == SRC_PARTS + 1 no overflow occurs and zero is returned. Otherwise DST is filled with the least significant DSTPARTS parts of the result, and if all of the omitted higher parts were zero return zero, otherwise overflow occurred and return one.

Definition at line 2539 of file APInt.cpp.

References llvm::ARM_AM::add, APINT_BITS_PER_WORD, assert(), highHalf(), i, lowHalf(), llvm::min(), and n.

Referenced by operator*=(), tcFullMultiply(), and tcMultiply().

◆ tcNegate()

void APInt::tcNegate ( WordType dst,
unsigned  parts 
)
static

Negate a bignum in-place.

Definition at line 2523 of file APInt.cpp.

References tcComplement(), and tcIncrement().

Referenced by llvm::detail::IEEEFloat::convertFromSignExtendedInteger().

◆ tcOr()

void APInt::tcOr ( WordType dst,
const WordType rhs,
unsigned  parts 
)
static

Definition at line 2770 of file APInt.cpp.

References i.

◆ tcSet()

void APInt::tcSet ( WordType dst,
WordType  part,
unsigned  parts 
)
static

Sets the least significant part of a bignum to the input value, and zeroes out higher parts.

Definition at line 2346 of file APInt.cpp.

References assert(), and i.

Referenced by llvm::detail::IEEEFloat::convert(), llvm::detail::IEEEFloat::makeInf(), llvm::detail::IEEEFloat::makeNaN(), llvm::detail::IEEEFloat::makeSmallest(), llvm::detail::IEEEFloat::makeZero(), llvm::detail::IEEEFloat::next(), tcDivide(), tcFullMultiply(), and tcMultiply().

◆ tcSetBit()

void APInt::tcSetBit ( WordType parts,
unsigned  bit 
)
static

Set the given bit of a bignum. Zero-based.

Definition at line 2375 of file APInt.cpp.

References bit.

Referenced by llvm::detail::IEEEFloat::convert(), llvm::detail::IEEEFloat::makeNaN(), llvm::detail::IEEEFloat::makeQuiet(), and llvm::detail::IEEEFloat::next().

◆ tcSetLeastSignificantBits()

void APInt::tcSetLeastSignificantBits ( WordType dst,
unsigned  parts,
unsigned  bits 
)
static

Set the least significant BITS and clear the rest.

Definition at line 2801 of file APInt.cpp.

References APINT_BITS_PER_WORD, bits, and i.

Referenced by llvm::detail::IEEEFloat::convertToInteger().

◆ tcShiftLeft()

void APInt::tcShiftLeft ( WordType Dst,
unsigned  Words,
unsigned  Count 
)
static

Shift a bignum left Count bits.

Shift a bignum left Cound bits in-place.

Shifted in bits are zero. There are no restrictions on Count.

Definition at line 2711 of file APInt.cpp.

References APINT_BITS_PER_WORD, APINT_WORD_SIZE, and llvm::min().

Referenced by llvm::detail::IEEEFloat::convert(), llvm::detail::IEEEFloat::convertToInteger(), and tcDivide().

◆ tcShiftRight()

void APInt::tcShiftRight ( WordType Dst,
unsigned  Words,
unsigned  Count 
)
static

Shift a bignum right Count bits.

Shift a bignum right Count bits in-place.

Shifted in bits are zero. There are no restrictions on Count.

Definition at line 2738 of file APInt.cpp.

References APINT_BITS_PER_WORD, APINT_WORD_SIZE, i, and llvm::min().

Referenced by llvm::shiftRight(), tcDivide(), and tcExtract().

◆ tcSubtract()

APInt::WordType APInt::tcSubtract ( WordType dst,
const WordType rhs,
WordType  carry,
unsigned  parts 
)
static

DST -= RHS + CARRY where CARRY is zero or one. Returns the carry flag.

Definition at line 2484 of file APInt.cpp.

References assert(), c, i, and l.

Referenced by operator-=(), and tcDivide().

◆ tcSubtractPart()

APInt::WordType APInt::tcSubtractPart ( WordType dst,
WordType  src,
unsigned  parts 
)
static

DST -= RHS. Returns the carry flag.

This function subtracts a single "word" (64-bit word), src, from the multi-word integer array, dst[], propagating the borrowed 1 value until no further borrowing is needed or it runs out of "words" in dst.

The result is 1 if "borrowing" exhausted the digits in dst, or 0 if dst was not exhausted. In other words, if src > dst then this function returns 1, otherwise 0.

Returns
the borrow out of the subtraction

Definition at line 2509 of file APInt.cpp.

References i.

Referenced by operator-=().

◆ tcXor()

void APInt::tcXor ( WordType dst,
const WordType rhs,
unsigned  parts 
)
static

Definition at line 2776 of file APInt.cpp.

References i.

◆ toString() [1/2]

void APInt::toString ( SmallVectorImpl< char > &  Str,
unsigned  Radix,
bool  Signed,
bool  formatAsCLiteral = false 
) const

◆ toString() [2/2]

std::string APInt::toString ( unsigned  Radix = 10,
bool  Signed = true 
) const

Return the APInt as a std::string.

Returns the APInt as a std::string.

Note that this is an inefficient method. It is better to pass in a SmallVector/SmallString to the methods above to avoid thrashing the heap for the string.

Note that this is an inefficient method. It is better to pass in a SmallVector/SmallString to the methods above.

Definition at line 2282 of file APInt.cpp.

References S, Signed, and toString().

◆ toStringSigned()

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

Considers the APInt to be signed and converts it into a string in the radix given.

The radix can be 2, 8, 10, 16, or 36.

Definition at line 1750 of file APInt.h.

References llvm::toString().

Referenced by dump().

◆ toStringUnsigned()

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

Considers the APInt to be unsigned and converts it into a string in the radix given.

The radix can be 2, 8, 10 16, or 36.

Definition at line 1744 of file APInt.h.

References llvm::toString().

Referenced by dump().

◆ trunc()

APInt APInt::trunc ( unsigned  width) const

Truncate to new width.

Truncate the APInt to a specified width. It is an error to specify a width that is greater than or equal to the current width.

Definition at line 858 of file APInt.cpp.

References APInt(), APINT_BITS_PER_WORD, assert(), bits, getMemory(), getNumWords(), getRawData(), and i.

Referenced by llvm::APSInt::APSInt(), areUsedBitsDense(), BinomialCoefficient(), combineVectorPack(), llvm::SelectionDAG::computeKnownBits(), llvm::SelectionDAG::ComputeNumSignBits(), llvm::InstCombinerImpl::Descale(), ExtractConstantBytes(), extractConstantWithoutWrapping(), llvm::SelectionDAG::getConstant(), llvm::ExecutionEngine::getConstantValue(), llvm::getConstantVRegValWithLookThrough(), getConstVector(), getDemandedSrcElements(), llvm::ARM_AM::getFP32FP16Imm(), llvm::SelectionDAG::getNode(), llvm::BuildVectorSDNode::isConstantSplat(), llvm::TargetLowering::isConstTrueVal(), llvm::SystemZVectorConstantInfo::isVectorConstantLegal(), lowerMSABinaryBitImmIntr(), llvm::CombinerHelper::matchCombineUnmergeConstant(), llvm::LegalizerHelper::narrowScalar(), llvm::RISCVTargetLowering::PerformDAGCombine(), processUMulZExtIdiom(), sextOrTrunc(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), llvm::TargetLowering::SimplifySetCC(), SolveLinEquationWithOverflow(), llvm::SystemZVectorConstantInfo::SystemZVectorConstantInfo(), llvm::X86TargetLowering::targetShrinkDemandedConstant(), llvm::APSInt::trunc(), llvm::KnownBits::trunc(), llvm::ConstantRange::truncate(), truncOrSelf(), truncSSat(), truncUSat(), llvm::InstCombinerImpl::visitSwitchInst(), and zextOrTrunc().

◆ truncOrSelf()

APInt APInt::truncOrSelf ( unsigned  width) const

Truncate to width.

Make this APInt have the bit width given by width. The value is truncated or left alone to make it that width.

Definition at line 964 of file APInt.cpp.

References trunc().

Referenced by llvm::ISD::isConstantSplatVector().

◆ truncSSat()

APInt APInt::truncSSat ( unsigned  width) const

Truncate to new width with signed saturation.

If this APInt, treated as signed integer, can be losslessly truncated to the new bitwidth, then return truncated APInt. Else, return either signed min value if the APInt was negative, or signed max value.

Definition at line 893 of file APInt.cpp.

References assert(), getSignedMaxValue(), getSignedMinValue(), isNegative(), isSignedIntN(), and trunc().

◆ truncUSat()

APInt APInt::truncUSat ( unsigned  width) const

Truncate to new width with unsigned saturation.

If the APInt, treated as unsigned integer, can be losslessly truncated to the new bitwidth, then return truncated APInt. Else, return max value.

Definition at line 881 of file APInt.cpp.

References assert(), getMaxValue(), isIntN(), and trunc().

◆ uadd_ov()

APInt APInt::uadd_ov ( const APInt RHS,
bool &  Overflow 
) const

◆ uadd_sat()

APInt APInt::uadd_sat ( const APInt RHS) const

◆ udiv() [1/2]

APInt APInt::udiv ( const APInt RHS) const

◆ udiv() [2/2]

APInt APInt::udiv ( uint64_t  RHS) const

Definition at line 1638 of file APInt.cpp.

References APInt(), assert(), llvm::BitWidth, getActiveBits(), getNumWords(), pVal, and ult().

◆ udivrem() [1/2]

void APInt::udivrem ( const APInt LHS,
const APInt RHS,
APInt Quotient,
APInt Remainder 
)
static

Dual division/remainder interface.

Sometimes it is convenient to divide two APInt values and obtain both the quotient and remainder. This function does both operations in the same computation making it a little more efficient. The pair of input arguments may overlap with the pair of output arguments. It is safe to call udivrem(X, Y, X, Y), for example.

Definition at line 1785 of file APInt.cpp.

References APInt(), APINT_WORD_SIZE, assert(), llvm::BitWidth, getActiveBits(), getNumWords(), pVal, ult(), and VAL.

Referenced by extractShiftForRotate(), isMultiple(), multiplicativeInverse(), llvm::APIntOps::RoundingUDiv(), sdivrem(), llvm::detail::IEEEFloat::toString(), and toString().

◆ udivrem() [2/2]

void APInt::udivrem ( const APInt LHS,
uint64_t  RHS,
APInt Quotient,
uint64_t &  Remainder 
)
static

◆ uge() [1/2]

bool llvm::APInt::uge ( const APInt RHS) const
inline

◆ uge() [2/2]

bool llvm::APInt::uge ( uint64_t  RHS) const
inline

Unsigned greater or equal comparison.

Regards both *this as an unsigned quantity and compares it with RHS for the validity of the greater-or-equal relationship.

Returns
true if *this >= RHS when considered unsigned.

Definition at line 1321 of file APInt.h.

◆ ugt() [1/2]

bool llvm::APInt::ugt ( const APInt RHS) const
inline

◆ ugt() [2/2]

bool llvm::APInt::ugt ( uint64_t  RHS) const
inline

Unsigned greater than comparison.

Regards both *this as an unsigned quantity and compares it with RHS for the validity of the greater-than relationship.

Returns
true if *this > RHS when considered unsigned.

Definition at line 1283 of file APInt.h.

◆ ule() [1/2]

bool llvm::APInt::ule ( const APInt RHS) const
inline

◆ ule() [2/2]

bool llvm::APInt::ule ( uint64_t  RHS) const
inline

Unsigned less or equal comparison.

Regards both *this as an unsigned quantity and compares it with RHS for the validity of the less-or-equal relationship.

Returns
true if *this <= RHS when considered unsigned.

Definition at line 1251 of file APInt.h.

◆ ult() [1/2]

bool llvm::APInt::ult ( const APInt RHS) const
inline

Unsigned less than comparison.

Regards both *this and RHS as unsigned quantities and compares them for the validity of the less-than relationship.

Returns
true if *this < RHS when both are considered unsigned.

Definition at line 1205 of file APInt.h.

References llvm::ScaledNumbers::compare().

Referenced by annotateAnyAllocSite(), llvm::KnownBits::ashr(), canEvaluateShiftedShift(), canEvaluateTruncated(), combineCMov(), combineCMP(), combineExtractWithShuffle(), llvm::APFixedPoint::compare(), CompareSCEVComplexity(), llvm::ARMTargetLowering::computeKnownBitsForTargetNode(), computePointerICmp(), llvm::ConstantFoldCompareInstruction(), ConstantIntSortPredicate(), llvm::ConstantRange::contains(), llvm::TargetLowering::expandMUL_LOHI(), findDemandedEltsBySingleUser(), llvm::InstCombinerImpl::foldICmpUsingKnownBits(), foldICmpWithTruncSignExtendedVal(), foldShiftIntoShiftInAnotherHandOfAndInICmp(), llvm::ScalarEvolution::getAddExpr(), llvm::omp::getBestVariantMatchForContext(), getRangeForAffineARHelper(), llvm::SelectionDAG::getValidShiftAmountConstant(), IncorporateWeight(), llvm::ConstantRange::intersectWith(), isSafePHIToSpeculate(), llvm::KnownBits::lshr(), magic(), magicu(), matchFunnelShift(), multiplicativeInverse(), llvm::AVRDAGToDAGISel::SelectInlineAsmMemoryOperand(), llvm::KnownBits::shl(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), llvm::InstCombinerImpl::SimplifyMultipleUseDemandedBits(), simplifyX86immShift(), sqrt(), llvm::ConstantRange::truncate(), uadd_ov(), udiv(), udivrem(), umul_ov(), llvm::ConstantRange::unionWith(), llvm::ConstantRange::unsignedSubMayOverflow(), urem(), llvm::InstCombinerImpl::visitAShr(), llvm::InstCombinerImpl::visitLShr(), and llvm::InstCombinerImpl::visitShl().

◆ ult() [2/2]

bool llvm::APInt::ult ( uint64_t  RHS) const
inline

Unsigned less than comparison.

Regards both *this as an unsigned quantity and compares it with RHS for the validity of the less-than relationship.

Returns
true if *this < RHS when considered unsigned.

Definition at line 1213 of file APInt.h.

◆ umul_ov()

APInt APInt::umul_ov ( const APInt RHS,
bool &  Overflow 
) const

◆ umul_sat()

APInt APInt::umul_sat ( const APInt RHS) const

Definition at line 2088 of file APInt.cpp.

References llvm::BitWidth, getMaxValue(), and umul_ov().

Referenced by llvm::ConstantRange::umul_sat().

◆ urem() [1/2]

APInt APInt::urem ( const APInt RHS) const

Unsigned remainder operation.

Perform an unsigned remainder operation on this APInt with RHS being the divisor. Both this and RHS are treated as unsigned quantities for purposes of this operation. Note that this is a true remainder operation and not a modulo operation because the sign follows the sign of the dividend which is *this.

Returns
a new APInt value containing the remainder result

Definition at line 1693 of file APInt.cpp.

References APInt(), assert(), llvm::BitWidth, getActiveBits(), getNumWords(), pVal, ult(), and VAL.

Referenced by combineExtractWithShuffle(), computeKnownBitsFromOperator(), llvm::ConstantFoldBinaryInstruction(), llvm::ExecutionEngine::getConstantValue(), llvm::ScalarEvolution::getUDivExpr(), isLoadCombineCandidateImpl(), isNonZeroModBitWidthOrUndef(), LowerFunnelShift(), LowerRotate(), magic(), magicu(), rotateModulo(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), simplifyICmpWithConstant(), simplifyIntrinsic(), llvm::APIntOps::SolveQuadraticEquationWrap(), srem(), and llvm::Interpreter::visitBinaryOperator().

◆ urem() [2/2]

uint64_t APInt::urem ( uint64_t  RHS) const

Definition at line 1731 of file APInt.cpp.

References assert(), getActiveBits(), getNumWords(), getZExtValue(), and ult().

◆ ushl_ov()

APInt APInt::ushl_ov ( const APInt Amt,
bool &  Overflow 
) const

◆ ushl_sat()

APInt APInt::ushl_sat ( const APInt RHS) const

Definition at line 2107 of file APInt.cpp.

References llvm::BitWidth, getMaxValue(), and ushl_ov().

Referenced by llvm::ConstantRange::ushl_sat().

◆ usub_ov()

APInt APInt::usub_ov ( const APInt RHS,
bool &  Overflow 
) const

Definition at line 1975 of file APInt.cpp.

References ugt().

Referenced by llvm::APFixedPoint::sub(), subWithOverflow(), and usub_sat().

◆ usub_sat()

APInt APInt::usub_sat ( const APInt RHS) const

Definition at line 2066 of file APInt.cpp.

References APInt(), llvm::BitWidth, and usub_ov().

Referenced by llvm::APFixedPoint::sub(), and llvm::ConstantRange::usub_sat().

◆ zext()

APInt APInt::zext ( unsigned  width) const

Zero extend to a new width.

This operation zero extends the APInt to a new width. The high order bits are filled with 0 bits. It is an error to specify a width that is less than or equal to the current width.

Definition at line 930 of file APInt.cpp.

References APInt(), APINT_BITS_PER_WORD, APINT_WORD_SIZE, assert(), getMemory(), getNumWords(), getRawData(), and memcpy().

Referenced by llvm::KnownBits::anyext(), BinomialCoefficient(), combineX86ShufflesRecursively(), llvm::SelectionDAG::computeKnownBits(), detectSSatPattern(), extractConstantWithoutWrapping(), llvm::InstCombinerImpl::foldICmpAndConstConst(), llvm::InstCombinerImpl::foldICmpEquality(), llvm::InstCombinerImpl::foldICmpTruncConstant(), foldSignedTruncationCheck(), llvm::ExecutionEngine::getConstantValue(), llvm::getConstantVRegValWithLookThrough(), insertInteger(), isSameValue(), llvm::ConstantRange::multiply(), llvm::PPCTargetLowering::PerformDAGCombine(), processUMulZExtIdiom(), rotateModulo(), llvm::ConstantRange::signExtend(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode(), llvm::X86TTIImpl::simplifyDemandedVectorEltsIntrinsic(), llvm::APFixedPoint::toString(), llvm::detail::IEEEFloat::toString(), llvm::LegalizationArtifactCombiner::tryCombineZExt(), tryToMergePartialOverlappingStores(), llvm::InstCombinerImpl::visitAnd(), llvm::LegalizerHelper::widenScalar(), llvm::ConstantRange::zeroExtend(), llvm::KnownBits::zext(), zextOrSelf(), and zextOrTrunc().

◆ zextOrSelf()

APInt APInt::zextOrSelf ( unsigned  width) const

◆ zextOrTrunc()

APInt APInt::zextOrTrunc ( unsigned  width) const

Friends And Related Function Documentation

◆ APSInt

friend class APSInt
friend

Definition at line 102 of file APInt.h.

◆ DenseMapInfo< APInt >

friend struct DenseMapInfo< APInt >
friend

Definition at line 100 of file APInt.h.

◆ hash_value

hash_code hash_value ( const APInt Arg)
friend

Overload to compute a hash_code for an APInt value.

Member Data Documentation

◆ pVal

uint64_t* llvm::APInt::pVal

Used to store the >64 bits integer value.

Definition at line 95 of file APInt.h.

Referenced by operator*(), operator+=(), operator-=(), roundToDouble(), udiv(), udivrem(), and urem().

◆ VAL

uint64_t llvm::APInt::VAL

◆ WORDTYPE_MAX

constexpr WordType llvm::APInt::WORDTYPE_MAX = ~WordType(0)
staticconstexpr

Definition at line 88 of file APInt.h.

Referenced by insertBits().


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