LLVM API Documentation

llvm::APInt Class Reference

Class for arbitrary precision integers. More...

#include <APInt.h>

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

List of all members.

Value Generators

Gets maximum unsigned value of APInt for specific bit width.

APInt getHiBits (unsigned numBits) const
 HiBits - This function returns the high "numBits" bits of this APInt.
APInt getLoBits (unsigned numBits) const
 LoBits - This function returns the low "numBits" bits of this APInt.
uint64_t getHashValue () const
 Get a hash value based on this APInt.
const uint64_t * getRawData () const
static APInt getMaxValue (unsigned numBits)
static APInt getSignedMaxValue (unsigned numBits)
 Gets maximum signed value of APInt for a specific bit width.
static APInt getMinValue (unsigned numBits)
 Gets minimum unsigned value of APInt for a specific bit width.
static APInt getSignedMinValue (unsigned numBits)
 Gets minimum signed value of APInt for a specific bit width.
static APInt getSignBit (unsigned BitWidth)
 Get the SignBit for a specific bit width.
static APInt getAllOnesValue (unsigned numBits)
 Get the all-ones value.
static APInt getNullValue (unsigned numBits)
 Get the '0' value.
static APInt getBitsSet (unsigned numBits, unsigned loBit, unsigned hiBit)
 Get a value with a block of bits set.
static APInt getHighBitsSet (unsigned numBits, unsigned hiBitsSet)
 Get a value with high bits set.
static APInt getLowBitsSet (unsigned numBits, unsigned loBitsSet)
 Get a value with low bits set.

Binary Operators

Bitwise AND operator.

Performs a bitwise AND operation on *this and RHS.

Returns:
An APInt value representing the bitwise AND of *this and RHS.


APInt operator & (const APInt &RHS) const
APInt And (const APInt &RHS) const
APInt operator| (const APInt &RHS) const
 Bitwise OR operator.
APInt Or (const APInt &RHS) const
APInt operator^ (const APInt &RHS) const
 Bitwise XOR operator.
APInt Xor (const APInt &RHS) const
APInt operator* (const APInt &RHS) const
 Multiplication operator.
APInt operator+ (const APInt &RHS) const
 Addition operator.
APInt operator+ (uint64_t RHS) const
APInt operator- (const APInt &RHS) const
 Subtraction operator.
APInt operator- (uint64_t RHS) const
APInt operator<< (unsigned Bits) const
APInt operator<< (const APInt &Bits) const
APInt ashr (unsigned shiftAmt) const
 Arithmetic right-shift function.
APInt lshr (unsigned shiftAmt) const
 Logical right-shift function.
APInt shl (unsigned shiftAmt) const
 Left-shift function.
APInt rotl (unsigned rotateAmt) const
 Rotate left by rotateAmt.
APInt rotr (unsigned rotateAmt) const
 Rotate right by rotateAmt.
APInt ashr (const APInt &shiftAmt) const
 Arithmetic right-shift function.
APInt lshr (const APInt &shiftAmt) const
 Logical right-shift function.
APInt shl (const APInt &shiftAmt) const
 Left-shift function.
APInt rotl (const APInt &rotateAmt) const
 Rotate left by rotateAmt.
APInt rotr (const APInt &rotateAmt) const
 Rotate right by rotateAmt.
APInt udiv (const APInt &RHS) const
 Unsigned division operation.
APInt sdiv (const APInt &RHS) const
 Signed division function for APInt.
APInt urem (const APInt &RHS) const
 Unsigned remainder operation.
APInt srem (const APInt &RHS) const
 Function for signed remainder operation.
bool operator[] (unsigned bitPosition) const
 Array-indexing support.
static void udivrem (const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
 Dual division/remainder interface.
static void sdivrem (const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)

Value Characterization Functions

unsigned getBitWidth () const
unsigned getNumWords () const
 Get the number of words.
unsigned getActiveBits () const
 Compute the number of active bits in the value.
unsigned getActiveWords () const
unsigned getMinSignedBits () const
 Get the minimum bit size for this signed APInt.
uint64_t getZExtValue () const
 Get zero extended value.
int64_t getSExtValue () const
 Get sign extended value.
unsigned countLeadingZeros () const
unsigned countLeadingOnes () const
 Count the number of leading one bits.
unsigned countTrailingZeros () const
 Count the number of trailing zero bits.
unsigned countTrailingOnes () const
 Count the number of trailing one bits.
unsigned countPopulation () const
 Count the number of bits set.
static unsigned getBitsNeeded (const char *str, unsigned slen, uint8_t radix)
 Get bits required for string value.

Building-block Operations for APInt and APFloat

void dump () const
 debug method
*static void tcSet (integerPart *, integerPart, unsigned int)
static void tcAssign (integerPart *, const integerPart *, unsigned int)
 Assign one bignum to another.
static bool tcIsZero (const integerPart *, unsigned int)
 Returns true if a bignum is zero, false otherwise.
static int tcExtractBit (const integerPart *, unsigned int bit)
 Extract the given bit of a bignum; returns 0 or 1. Zero-based.
static void tcExtract (integerPart *, unsigned int dstCount, const integerPart *, unsigned int srcBits, unsigned int srcLSB)
static void tcSetBit (integerPart *, unsigned int bit)
 Set the given bit of a bignum. Zero-based.
static unsigned int tcLSB (const integerPart *, unsigned int)
static unsigned int tcMSB (const integerPart *parts, unsigned int n)
static void tcNegate (integerPart *, unsigned int)
 Negate a bignum in-place.
static integerPart tcAdd (integerPart *, const integerPart *, integerPart carry, unsigned)
static integerPart tcSubtract (integerPart *, const integerPart *, integerPart carry, unsigned)
static int tcMultiplyPart (integerPart *dst, const integerPart *src, integerPart multiplier, integerPart carry, unsigned int srcParts, unsigned int dstParts, bool add)
static int tcMultiply (integerPart *, const integerPart *, const integerPart *, unsigned)
static unsigned int tcFullMultiply (integerPart *, const integerPart *, const integerPart *, unsigned, unsigned)
static int tcDivide (integerPart *lhs, const integerPart *rhs, integerPart *remainder, integerPart *scratch, unsigned int parts)
static void tcShiftLeft (integerPart *, unsigned int parts, unsigned int count)
static void tcShiftRight (integerPart *, unsigned int parts, unsigned int count)
static void tcAnd (integerPart *, const integerPart *, unsigned int)
 The obvious AND, OR and XOR and complement operations.
static void tcOr (integerPart *, const integerPart *, unsigned int)
static void tcXor (integerPart *, const integerPart *, unsigned int)
static void tcComplement (integerPart *, unsigned int)
static int tcCompare (const integerPart *, const integerPart *, unsigned int)
 Comparison (unsigned) of two bignums.
static integerPart tcIncrement (integerPart *, unsigned int)
 Increment a bignum in-place. Return the carry flag.
static void tcSetLeastSignificantBits (integerPart *, unsigned int, unsigned int bits)
 Set the least significant BITS and clear the rest.

Public Member Functions

Constructors
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:
numBits the bit width of the constructed APInt
val the initial value of the APInt
isSigned how to treat signedness of val


 APInt (unsigned numBits, uint64_t val, bool isSigned=false)
 APInt (unsigned numBits, unsigned numWords, const uint64_t bigVal[])
 Construct an APInt of numBits width, initialized as bigVal[].
 APInt (unsigned numBits, const char strStart[], unsigned slen, uint8_t radix)
 Construct an APInt from a string representation.
 APInt (const APInt &that)
 Copy Constructor.
 ~APInt ()
 Destructor.
 APInt ()
void Profile (FoldingSetNodeID &id) const
 Profile - This method 'profiles' an APInt for use with FoldingSet.
void Emit (Serializer &S) const
 Used by the Bitcode serializer to emit APInts to Bitcode.
void Read (Deserializer &D)
 Used by the Bitcode deserializer to deserialize APInts.
Value Tests
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


bool isNegative () const
bool isNonNegative () const
 Determine if this APInt Value is non-negative (>= 0).
bool isStrictlyPositive () const
 Determine if this APInt Value is positive.
bool isAllOnesValue () const
 Determine if all bits are set.
bool isMaxValue () const
 Determine if this is the largest unsigned value.
bool isMaxSignedValue () const
 Determine if this is the largest signed value.
bool isMinValue () const
 Determine if this is the smallest unsigned value.
bool isMinSignedValue () const
 Determine if this is the smallest signed value.
bool isIntN (unsigned N) const
 Check if this APInt has an N-bits unsigned integer value.
bool isSignedIntN (unsigned N) const
 Check if this APInt has an N-bits signed integer value.
bool isPowerOf2 () const
bool isSignBit () const
 isSignBit - Return true if this is the value returned by getSignBit.
bool getBoolValue () const
 Boolean conversion function.
uint64_t getLimitedValue (uint64_t Limit=~0ULL) const
Unary Operators
Postfix increment operator.

Returns:
a new APInt value representing *this incremented by one


const APInt operator++ (int)
APInt & operator++ ()
 Prefix increment operator.
const APInt operator-- (int)
 Postfix decrement operator.
APInt & operator-- ()
 Prefix decrement operator.
APInt operator~ () const
 Unary bitwise complement operator.
APInt operator- () const
 Unary negation operator.
bool operator! () const
 Logical negation operator.
Assignment Operators
Copy assignment operator.

Returns:
*this after assignment of RHS.


APInt & operator= (const APInt &RHS)
APInt & operator= (uint64_t RHS)
 Assignment operator.
APInt & operator &= (const APInt &RHS)
 Bitwise AND assignment operator.
APInt & operator|= (const APInt &RHS)
 Bitwise OR assignment operator.
APInt & operator^= (const APInt &RHS)
 Bitwise XOR assignment operator.
APInt & operator*= (const APInt &RHS)
 Multiplication assignment operator.
APInt & operator+= (const APInt &RHS)
 Addition assignment operator.
APInt & operator-= (const APInt &RHS)
 Subtraction assignment operator.
APInt & operator<<= (unsigned shiftAmt)
 Left-shift assignment function.
Comparison Operators
Equality operator.

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

bool operator== (const APInt &RHS) const
bool operator== (uint64_t Val) const
 Equality operator.
bool eq (const APInt &RHS) const
 Equality comparison.
bool operator!= (const APInt &RHS) const
 Inequality operator.
bool operator!= (uint64_t Val) const
 Inequality operator.
bool ne (const APInt &RHS) const
 Inequality comparison.
bool ult (const APInt &RHS) const
 Unsigned less than comparison.
bool slt (const APInt &RHS) const
 Signed less than comparison.
bool ule (const APInt &RHS) const
 Unsigned less or equal comparison.
bool sle (const APInt &RHS) const
 Signed less or equal comparison.
bool ugt (const APInt &RHS) const
 Unsigned greather than comparison.
bool sgt (const APInt &RHS) const
 Signed greather than comparison.
bool uge (const APInt &RHS) const
 Unsigned greater or equal comparison.
bool sge (const APInt &RHS) const
 Signed greather or equal comparison.
bool intersects (const APInt &RHS) const
Resizing Operators
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.

APInt & trunc (unsigned width)
APInt & sext (unsigned width)
 Sign extend to a new width.
APInt & zext (unsigned width)
 Zero extend to a new width.
APInt & sextOrTrunc (unsigned width)
 Sign extend or truncate to width.
APInt & zextOrTrunc (unsigned width)
 Zero extend or truncate to width.
Bit Manipulation Operators
Set every bit to 1.

APInt & set ()
APInt & set (unsigned bitPosition)
 Set a given bit to 1.
APInt & clear ()
 Set every bit to 0.
APInt & clear (unsigned bitPosition)
 Set a given bit to 0.
APInt & flip ()
 Toggle every bit to its opposite value.
APInt & flip (unsigned bitPosition)
 Toggles a given bit to its opposite value.
Conversion Functions
void print (raw_ostream &OS, bool isSigned) const
void toString (SmallVectorImpl< char > &Str, unsigned Radix, bool Signed) const
void toStringUnsigned (SmallVectorImpl< char > &Str, unsigned Radix=10) const
void toStringSigned (SmallVectorImpl< char > &Str, unsigned Radix=10) const
std::string toString (unsigned Radix, bool Signed) const
APInt byteSwap () const
double roundToDouble (bool isSigned) const
 Converts this APInt to a double value.
double roundToDouble () const
 Converts this unsigned APInt to a double value.
double signedRoundToDouble () const
 Converts this signed APInt to a double value.
double bitsToDouble () const
 Converts APInt bits to a double.
float bitsToFloat () const
 Converts APInt bits to a double.
APInt & doubleToBits (double V)
 Converts a double to APInt bits.
APInt & floatToBits (float V)
 Converts a float to APInt bits.
Mathematics Operations
unsigned logBase2 () const
int32_t exactLogBase2 () const
APInt sqrt () const
 Compute the square root.
APInt abs () const
 Get the absolute value;.
APInt multiplicativeInverse (const APInt &modulo) const


Detailed Description

Class for arbitrary precision integers.

APInt - This class represents arbitrary precision constant integral values. It 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: All bit, byte, and word positions are zero-based. Once the bit width is set, it doesn't change except by the Truncate, SignExtend, or ZeroExtend operations. All binary operators must be on APInt instances of the same bit width. Attempting to use these operators on instances with different bit widths will yield an assertion. The value is stored canonically as an unsigned value. For operations where it makes a difference, there are both signed and unsigned variants of the operation. For example, sdiv and udiv. However, because the bit widths must be the same, operations such as Mul and Add produce the same results regardless of whether the values are interpreted as signed or not. In general, the class tries to follow the style of computation that LLVM uses in its IR. This simplifies its use for LLVM.

Definition at line 71 of file APInt.h.


Constructor & Destructor Documentation

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

Definition at line 212 of file APInt.h.

References VAL.

APInt::APInt ( unsigned  numBits,
unsigned  numWords,
const uint64_t  bigVal[] 
)

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

Note that numWords can be smaller or larger than the corresponding bit width but any extraneous bits will be dropped.

Parameters:
numBits the bit width of the constructed APInt
numWords the number of words in bigVal
bigVal a sequence of words to form the initial value of the APInt

Definition at line 59 of file APInt.cpp.

References getClearedMemory(), getNumWords(), llvm::Intrinsic::memcpy, pVal, and VAL.

APInt::APInt ( unsigned  numBits,
const char  strStart[],
unsigned  slen,
uint8_t  radix 
)

Construct an APInt from a string representation.

This constructor interprets the slen characters starting at StrStart as a string in the given radix. The interpretation stops when the first character that is not suitable for the radix is encountered. Acceptable radix values are 2, 8, 10 and 16. It is an error for the value implied by the string to require more bits than numBits.

Parameters:
numBits the bit width of the constructed APInt
strStart the start of the string to be interpreted
slen the maximum number of characters to interpret
radix the radix to use for the conversion

Definition at line 77 of file APInt.cpp.

llvm::APInt::APInt ( const APInt &  that  )  [inline]

Copy Constructor.

Simply makes *this a copy of that.

Definition at line 244 of file APInt.h.

References VAL.

llvm::APInt::~APInt (  )  [inline]

Destructor.

Definition at line 254 of file APInt.h.

References pVal.

llvm::APInt::APInt (  )  [inline, explicit]

Default constructor that creates an uninitialized APInt. This is useful for object deserialization (pair this with the static method Read).

Definition at line 261 of file APInt.h.

Referenced by ashr(), byteSwap(), getAllOnesValue(), getHighBitsSet(), getLowBitsSet(), getMaxValue(), getMinValue(), getNullValue(), getSignedMaxValue(), getSignedMinValue(), isPowerOf2(), lshr(), multiplicativeInverse(), operator &(), operator*(), operator+(), operator-(), operator^(), operator|(), shl(), sqrt(), udiv(), udivrem(), and urem().


Member Function Documentation

void APInt::Profile ( FoldingSetNodeID &  id  )  const

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

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

Reimplemented in llvm::APSInt.

Definition at line 127 of file APInt.cpp.

References llvm::FoldingSetNodeID::AddInteger(), getNumWords(), and pVal.

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

void APInt::Emit ( Serializer &  S  )  const

Used by the Bitcode serializer to emit APInts to Bitcode.

Definition at line 20 of file SerializeAPInt.cpp.

References llvm::Serializer::EmitInt(), getNumWords(), pVal, and VAL.

void APInt::Read ( Deserializer &  D  ) 

Used by the Bitcode deserializer to deserialize APInts.

Definition at line 20 of file DeserializeAPInt.cpp.

References pVal, llvm::Deserializer::ReadInt(), and VAL.

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

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

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

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

Definition at line 285 of file APInt.h.

References isNegative().

Referenced by 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 293 of file APInt.h.

References isNonNegative().

Referenced by llvm::TargetLowering::BuildSDIV(), llvm::ComputeMaskedBits(), and llvm::SelectionDAG::ComputeMaskedBits().

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 299 of file APInt.h.

References countPopulation().

Referenced by llvm::ConstantInt::isAllOnesValue(), and llvm::TargetLowering::SimplifyDemandedBits().

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 306 of file APInt.h.

References countPopulation().

Referenced by llvm::ConstantRange::ConstantRange(), llvm::ConstantRange::isFullSet(), and llvm::ConstantInt::isMaxValue().

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 313 of file APInt.h.

References countPopulation(), isNegative(), and VAL.

Referenced by llvm::ConstantInt::isMaxValue().

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 321 of file APInt.h.

References countPopulation().

Referenced by llvm::ConstantRange::ConstantRange(), llvm::ConstantRange::isEmptySet(), llvm::ConstantInt::isMinValue(), and SolveQuadraticEquation().

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

Determine if this is the smallest signed value.

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

Definition at line 328 of file APInt.h.

References countPopulation(), isNegative(), and VAL.

Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::ConstantInt::isMinValue(), and isSignBit().

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

Check if this APInt has an N-bits unsigned integer value.

Definition at line 334 of file APInt.h.

References getBitWidth(), getNumWords(), pVal, VAL, and zext().

Referenced by llvm::APIntOps::isIntN().

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

Check if this APInt has an N-bits signed integer value.

Definition at line 347 of file APInt.h.

References getMinSignedBits().

Referenced by llvm::APIntOps::isSignedIntN().

bool APInt::isPowerOf2 (  )  const

Returns:
true if the argument APInt value is a power of two > 0.

Definition at line 650 of file APInt.cpp.

References APInt().

Referenced by llvm::ComputeMaskedBits(), llvm::SelectionDAG::ComputeMaskedBits(), exactLogBase2(), isOneBitSet(), and llvm::SCEVExpander::visitUDivExpr().

bool llvm::APInt::isSignBit (  )  const [inline]

isSignBit - Return true if this is the value returned by getSignBit.

Definition at line 356 of file APInt.h.

References isMinSignedValue().

Referenced by isSignBitCheck().

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

Boolean conversion function.

This converts the APInt to a boolean value as a test against zero.

Definition at line 360 of file APInt.h.

Referenced by llvm::SelectionDAG::ComputeMaskedBits(), and llvm::PPCTargetLowering::SelectAddressRegReg().

uint64_t llvm::APInt::getLimitedValue ( uint64_t  Limit = ~0ULL  )  const [inline]

getLimitedValue - If this value is smaller than the specified limit, return it, otherwise return the limit value. This causes the value to saturate to the limit.

Definition at line 367 of file APInt.h.

References getActiveBits(), and getZExtValue().

Referenced by ashr(), llvm::ConstantInt::getLimitedValue(), lshr(), rotl(), rotr(), and shl().

static APInt llvm::APInt::getMaxValue ( unsigned  numBits  )  [inline, static]

static APInt llvm::APInt::getSignedMaxValue ( unsigned  numBits  )  [inline, static]

Gets maximum signed value of APInt for a specific bit width.

Definition at line 381 of file APInt.h.

References APInt().

Referenced by llvm::APSInt::getMaxValue(), llvm::ConstantRange::getSignedMax(), magic(), magicu(), and llvm::TargetLowering::SimplifySetCC().

static APInt llvm::APInt::getMinValue ( unsigned  numBits  )  [inline, static]

Gets minimum unsigned value of APInt for a specific bit width.

Definition at line 386 of file APInt.h.

References APInt().

Referenced by llvm::ConstantRange::ConstantRange(), llvm::APSInt::getMinValue(), llvm::ConstantRange::getUnsignedMin(), llvm::ICmpInst::makeConstantRange(), and llvm::TargetLowering::SimplifySetCC().

static APInt llvm::APInt::getSignedMinValue ( unsigned  numBits  )  [inline, static]

static APInt llvm::APInt::getSignBit ( unsigned  BitWidth  )  [inline, static]

Get the SignBit for a specific bit width.

getSignBit - This is just a wrapper function of getSignedMinValue(), and it helps code readability when we want to get a SignBit.

Definition at line 398 of file APInt.h.

References getSignedMinValue().

Referenced by llvm::ComputeMaskedBits(), llvm::SelectionDAG::ComputeMaskedBits(), llvm::SelectionDAG::SignBitIsZero(), and llvm::TargetLowering::SimplifyDemandedBits().

static APInt llvm::APInt::getAllOnesValue ( unsigned  numBits  )  [inline, static]

static APInt llvm::APInt::getNullValue ( unsigned  numBits  )  [inline, static]

Get the '0' value.

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

Definition at line 410 of file APInt.h.

References APInt().

APInt APInt::getHiBits ( unsigned  numBits  )  const

HiBits - 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 640 of file APInt.cpp.

References llvm::APIntOps::lshr().

APInt APInt::getLoBits ( unsigned  numBits  )  const

LoBits - 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 645 of file APInt.cpp.

References llvm::APIntOps::lshr(), and llvm::APIntOps::shl().

static APInt llvm::APInt::getBitsSet ( unsigned  numBits,
unsigned  loBit,
unsigned  hiBit 
) [inline, static]

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. If hiBit is less than loBit then the set bits "wrap". For example, with parameters (32, 28, 4), you would get 0xF000000F.

Parameters:
numBits the intended bit width of the result
loBit the index of the lowest bit set.
hiBit the index of the highest bit set.
Returns:
An APInt value with the requested bits set.

Definition at line 434 of file APInt.h.

References getHighBitsSet(), getLowBitsSet(), and shl().

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

static APInt llvm::APInt::getHighBitsSet ( unsigned  numBits,
unsigned  hiBitsSet 
) [inline, static]

Get a value with high bits set.

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

Parameters:
numBits the bitwidth of the result
hiBitsSet the number of high-order bits set in the result.

Definition at line 447 of file APInt.h.

References APInt().

Referenced by llvm::ComputeMaskedBits(), llvm::SelectionDAG::ComputeMaskedBits(), llvm::X86TargetLowering::computeMaskedBitsForTargetNode(), getBitsSet(), llvm::ConstantRange::signExtend(), llvm::TargetLowering::SimplifyDemandedBits(), and llvm::TargetLowering::SimplifySetCC().

static APInt llvm::APInt::getLowBitsSet ( unsigned  numBits,
unsigned  loBitsSet 
) [inline, static]

Get a value with low bits set.

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

Parameters:
numBits the bitwidth of the result
loBitsSet the number of low-order bits set in the result.

Definition at line 463 of file APInt.h.

References APInt().

Referenced by llvm::ComputeMaskedBits(), llvm::SelectionDAG::ComputeMaskedBits(), llvm::ConstantFoldBinaryInstruction(), llvm::ConstantFoldInstOperands(), getBitsSet(), llvm::SelectionDAG::getZeroExtendInReg(), llvm::APIntOps::isMask(), PerformBTCombine(), llvm::ConstantRange::signExtend(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::TargetLowering::SimplifySetCC(), and llvm::ConstantRange::truncate().

uint64_t APInt::getHashValue (  )  const

Get a hash value based on this APInt.

The hash value is computed as the sum of the words and the bit width.

Returns:
A hash value computed from the sum of the APInt words.

Definition at line 626 of file APInt.cpp.

References getNumWords(), hash(), and pVal.

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

This function returns a pointer to the internal storage of the APInt. This is useful for writing out the APInt in binary form without any conversions.

Definition at line 484 of file APInt.h.

References pVal, and VAL.

Referenced by llvm::APFloat::convertFromAPInt(), llvm::APFloat::convertFromZeroExtendedInteger(), LoadIntFromMemory(), StoreIntToMemory(), llvm::ExecutionEngine::StoreValueToMemory(), toString(), WriteConstantInt(), and WriteConstants().

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

Reimplemented in llvm::APSInt.

Definition at line 495 of file APInt.h.

APInt & APInt::operator++ (  ) 

Prefix increment operator.

Prefix increment operator. Increments the APInt by one.

Returns:
*this incremented by one

Reimplemented in llvm::APSInt.

Definition at line 158 of file APInt.cpp.

References add_1(), getNumWords(), and pVal.

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

Postfix decrement operator.

Returns:
a new APInt representing *this decremented by one.

Reimplemented in llvm::APSInt.

Definition at line 507 of file APInt.h.

APInt & APInt::operator-- (  ) 

Prefix decrement operator.

Prefix decrement operator. Decrements the APInt by one.

Returns:
*this decremented by one.

Reimplemented in llvm::APSInt.

Definition at line 187 of file APInt.cpp.

References getNumWords(), pVal, and sub_1().

APInt llvm::APInt::operator~ (  )  const [inline]

Unary bitwise complement operator.

Performs a bitwise complement operation on this APInt.

Returns:
an APInt that is the bitwise complement of *this

Reimplemented in llvm::APSInt.

Definition at line 520 of file APInt.h.

References flip().

APInt llvm::APInt::operator- (  )  const [inline]

Unary negation operator.

Negates *this using two's complement logic.

Returns:
An APInt value representing the negation of *this.

Reimplemented in llvm::APSInt.

Definition at line 529 of file APInt.h.

References APInt().

bool APInt::operator! (  )  const

Logical negation operator.

Performs logical negation operation on this APInt.

Returns:
true if *this is zero, false otherwise.

Definition at line 421 of file APInt.cpp.

References getNumWords(), and pVal.

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

Reimplemented in llvm::APSInt.

Definition at line 543 of file APInt.h.

References BitWidth, isSingleWord(), and VAL.

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

APInt & APInt::operator= ( uint64_t  RHS  ) 

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.

Reimplemented in llvm::APSInt.

Definition at line 116 of file APInt.cpp.

References getNumWords(), llvm::Intrinsic::memset, and pVal.

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

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 358 of file APInt.cpp.

References BitWidth, getNumWords(), pVal, and VAL.

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

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 370 of file APInt.cpp.

References BitWidth, getNumWords(), pVal, and VAL.

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

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 382 of file APInt.cpp.

References BitWidth, getNumWords(), pVal, and VAL.

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 317 of file APInt.cpp.

References BitWidth, clear(), getActiveBits(), getMemory(), getNumWords(), llvm::Intrinsic::memcpy, mul(), pVal, and VAL.

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

Addition assignment operator.

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

Returns:
*this
Adds the RHS APint to this APInt.
Returns:
this, after addition of RHS.

Definition at line 213 of file APInt.cpp.

References BitWidth, getNumWords(), pVal, and VAL.

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

Subtraction assignment operator.

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

Returns:
*this
Subtracts the RHS APInt from this APInt
Returns:
this, after subtraction

Definition at line 240 of file APInt.cpp.

References BitWidth, getNumWords(), pVal, sub(), and VAL.

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

Reimplemented in llvm::APSInt.

Definition at line 597 of file APInt.h.

References shl().

APInt llvm::APInt::operator & ( const APInt &  RHS  )  const [inline]

Definition at line 608 of file APInt.h.

References APInt(), BitWidth, getBitWidth(), and VAL.

Referenced by And().

APInt llvm::APInt::And ( const APInt &  RHS  )  const [inline]

Definition at line 614 of file APInt.h.

References operator &().

APInt llvm::APInt::operator| ( const APInt &  RHS  )  const [inline]

Bitwise OR operator.

Performs a bitwise OR operation on *this and RHS.

Returns:
An APInt value representing the bitwise OR of *this and RHS.

Definition at line 621 of file APInt.h.

References APInt(), BitWidth, getBitWidth(), and VAL.

Referenced by Or().

APInt llvm::APInt::Or ( const APInt &  RHS  )  const [inline]

Definition at line 627 of file APInt.h.

References operator|().

APInt llvm::APInt::operator^ ( const APInt &  RHS  )  const [inline]

Bitwise XOR operator.

Performs a bitwise XOR operation on *this and RHS.

Returns:
An APInt value representing the bitwise XOR of *this and RHS.

Definition at line 634 of file APInt.h.

References APInt(), BitWidth, and VAL.

Referenced by Xor().

APInt llvm::APInt::Xor ( const APInt &  RHS  )  const [inline]

Definition at line 640 of file APInt.h.

References operator^().

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

Multiplication operator.

Multiplies this APInt by RHS and returns the result.

Definition at line 431 of file APInt.cpp.

References APInt(), BitWidth, clearUnusedBits(), and VAL.

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

Addition operator.

Adds RHS to this APInt and returns the result.

Definition at line 440 of file APInt.cpp.

References APInt(), BitWidth, clearUnusedBits(), getNumWords(), pVal, and VAL.

APInt llvm::APInt::operator+ ( uint64_t  RHS  )  const [inline]

Definition at line 651 of file APInt.h.

References APInt().

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

Subtraction operator.

Subtracts RHS from this APInt and returns the result.

Definition at line 449 of file APInt.cpp.

References APInt(), BitWidth, clearUnusedBits(), getNumWords(), pVal, sub(), and VAL.

APInt llvm::APInt::operator- ( uint64_t  RHS  )  const [inline]

Definition at line 658 of file APInt.h.

References APInt().

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

Reimplemented in llvm::APSInt.

Definition at line 662 of file APInt.h.

References shl().

APInt llvm::APInt::operator<< ( const APInt &  Bits  )  const [inline]

Definition at line 666 of file APInt.h.

References shl().

APInt APInt::ashr ( unsigned  shiftAmt  )  const

APInt APInt::lshr ( unsigned  shiftAmt  )  const

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

APInt APInt::rotl ( unsigned  rotateAmt  )  const

Rotate left by rotateAmt.

Definition at line 1200 of file APInt.cpp.

References lshr(), and shl().

Referenced by llvm::SelectionDAG::FoldConstantArithmetic(), and rotl().

APInt APInt::rotr ( unsigned  rotateAmt  )  const

Rotate right by rotateAmt.

Definition at line 1215 of file APInt.cpp.

References lshr(), and shl().

Referenced by llvm::SelectionDAG::FoldConstantArithmetic(), and rotr().

APInt APInt::ashr ( const APInt &  shiftAmt  )  const

Arithmetic right-shift function.

Arithmetic right-shift this APInt by shiftAmt.

Definition at line 984 of file APInt.cpp.

References ashr(), and getLimitedValue().

APInt APInt::lshr ( const APInt &  shiftAmt  )  const

Logical right-shift function.

Logical right-shift this APInt by shiftAmt.

Definition at line 1073 of file APInt.cpp.

References getLimitedValue(), and lshr().

APInt APInt::shl ( const APInt &  shiftAmt  )  const

Left-shift function.

Left-shift this APInt by shiftAmt.

Definition at line 1141 of file APInt.cpp.

References getLimitedValue(), and shl().

APInt APInt::rotl ( const APInt &  rotateAmt  )  const

Rotate left by rotateAmt.

Definition at line 1196 of file APInt.cpp.

References getLimitedValue(), and rotl().

APInt APInt::rotr ( const APInt &  rotateAmt  )  const

Rotate right by rotateAmt.

Definition at line 1211 of file APInt.cpp.

References getLimitedValue(), and rotr().

APInt APInt::udiv ( const APInt &  RHS  )  const

Unsigned division operation.

Perform an unsigned divide operation on this APInt by RHS. Both this and RHS are treated as unsigned quantities for purposes of this division.

Returns:
a new APInt value containing the division result

Definition at line 1719 of file APInt.cpp.

References APInt(), BitWidth, getActiveBits(), pVal, ult(), and VAL.

Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::SelectionDAG::FoldConstantArithmetic(), llvm::ExecutionEngine::getConstantValue(), magic(), magicu(), llvm::APSInt::operator/(), llvm::APSInt::operator/=(), sdiv(), sqrt(), llvm::APIntOps::udiv(), and llvm::Interpreter::visitBinaryOperator().

APInt llvm::APInt::sdiv ( const APInt &  RHS  )  const [inline]

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 1756 of file APInt.cpp.

References APInt(), BitWidth, getActiveBits(), pVal, ult(), and VAL.

Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::SelectionDAG::FoldConstantArithmetic(), llvm::ExecutionEngine::getConstantValue(), magic(), llvm::APSInt::operator%(), llvm::APSInt::operator%=(), srem(), llvm::APIntOps::urem(), and llvm::Interpreter::visitBinaryOperator().

APInt llvm::APInt::srem ( const APInt &  RHS  )  const [inline]

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 1793 of file APInt.cpp.

References APInt(), getActiveBits(), getBitWidth(), isSingleWord(), pVal, ult(), and VAL.

Referenced by multiplicativeInverse(), and sdivrem().

static void llvm::APInt::sdivrem ( const APInt &  LHS,
const APInt &  RHS,
APInt &  Quotient,
APInt &  Remainder 
) [inline, static]

Definition at line 764 of file APInt.h.

References isNegative(), and udivrem().

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

Array-indexing support.

Returns:
the bit value at bitPosition

Definition at line 458 of file APInt.cpp.

References pVal.

bool llvm::APInt::operator== ( const APInt &  RHS  )  const [inline]

Definition at line 792 of file APInt.h.

References BitWidth, and VAL.

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 803 of file APInt.h.

References VAL.

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 813 of file APInt.h.

Referenced by sgt(), sle(), ugt(), and ule().

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 821 of file APInt.h.

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 829 of file APInt.h.

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 837 of file APInt.h.

bool APInt::ult ( const APInt &  RHS  )  const

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 491 of file APInt.cpp.

References BitWidth, getActiveBits(), pVal, and VAL.

Referenced by AddWithOverflow(), llvm::ConstantFoldCompareInstruction(), llvm::ConstantRange::contains(), llvm::SelectionDAG::FoldSetCC(), llvm::ConstantRange::intersectWith(), magicu(), llvm::ConstantRange::maximalIntersectWith(), multiplicativeInverse(), llvm::APSInt::operator<(), slt(), sqrt(), udiv(), udivrem(), uge(), ugt(), ule(), llvm::APIntOps::umin(), llvm::ConstantRange::unionWith(), and urem().

bool APInt::slt ( const APInt &  RHS  )  const

Signed less than comparison.

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

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

Definition at line 523 of file APInt.cpp.

References BitWidth, flip(), isNegative(), ugt(), ult(), and VAL.

Referenced by AddWithOverflow(), llvm::ConstantFoldCompareInstruction(), llvm::SelectionDAG::FoldSetCC(), MultiplyOverflows(), llvm::APSInt::operator<(), sge(), sgt(), sle(), llvm::APIntOps::smin(), and SubWithOverflow().

bool llvm::APInt::ule ( const APInt &  RHS  )  const [inline]

Unsigned less or equal comparison.

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

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

Definition at line 857 of file APInt.h.

References eq(), and ult().

Referenced by llvm::ConstantFoldCompareInstruction(), llvm::ConstantRange::contains(), llvm::SelectionDAG::FoldSetCC(), magic(), llvm::ConstantRange::maximalIntersectWith(), llvm::APSInt::operator<=(), sqrt(), and llvm::ConstantRange::unionWith().

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 865 of file APInt.h.

References eq(), and slt().

Referenced by llvm::ConstantFoldCompareInstruction(), llvm::SelectionDAG::FoldSetCC(), and llvm::APSInt::operator<=().

bool llvm::APInt::ugt ( const APInt &  RHS  )  const [inline]

Unsigned greather than comparison.

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

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

Definition at line 873 of file APInt.h.

References eq(), and ult().

Referenced by llvm::ConstantFoldCompareInstruction(), llvm::SelectionDAG::FoldSetCC(), llvm::ConstantRange::isWrappedSet(), MultiplyOverflows(), llvm::APSInt::operator>(), slt(), SubWithOverflow(), llvm::APIntOps::umax(), and llvm::ConstantRange::unionWith().

bool llvm::APInt::sgt ( const APInt &  RHS  )  const [inline]

Signed greather than comparison.

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

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

Definition at line 881 of file APInt.h.

References eq(), and slt().

Referenced by AddWithOverflow(), llvm::ConstantFoldCompareInstruction(), llvm::SelectionDAG::FoldSetCC(), MultiplyOverflows(), llvm::APSInt::operator>(), llvm::APIntOps::smax(), and SubWithOverflow().

bool llvm::APInt::uge ( const APInt &  RHS  )  const [inline]

Unsigned greater or equal comparison.

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

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

Definition at line 889 of file APInt.h.

References ult().

Referenced by llvm::ConstantFoldCompareInstruction(), llvm::SelectionDAG::FoldSetCC(), magic(), magicu(), and llvm::APSInt::operator>=().

bool llvm::APInt::sge ( const APInt &  RHS  )  const [inline]

Signed greather 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 897 of file APInt.h.

References slt().

Referenced by llvm::ConstantFoldCompareInstruction(), llvm::SelectionDAG::FoldSetCC(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), and llvm::APSInt::operator>=().

bool llvm::APInt::intersects ( const APInt &  RHS  )  const [inline]

This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are both set.

Definition at line 903 of file APInt.h.

Referenced by llvm::SelectionDAGISel::CheckAndMask(), llvm::SelectionDAGISel::CheckOrMask(), and llvm::TargetLowering::SimplifyDemandedBits().

APInt & APInt::trunc ( unsigned  width  ) 

APInt & APInt::sext ( unsigned  width  ) 

Sign extend to a new width.

This operation sign extends the APInt to a new width. If the high order bit is set, the fill on the left will be done with 1 bits, otherwise zero. It is an error to specify a width that is less than or equal to the current width.

Definition at line 900 of file APInt.cpp.

References getMemory(), getNumWords(), isNegative(), and zext().

Referenced by ComputeRange(), llvm::APSInt::extend(), llvm::ExecutionEngine::getConstantValue(), MultiplyOverflows(), roundToDouble(), sextOrTrunc(), and llvm::ConstantRange::signExtend().

APInt & APInt::zext ( unsigned  width  ) 

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 947 of file APInt.cpp.

References getClearedMemory(), and getNumWords().

Referenced by BinomialCoefficient(), llvm::SelectionDAG::ComputeMaskedBits(), llvm::APSInt::extend(), llvm::ExecutionEngine::getConstantValue(), isIntN(), MultiplyOverflows(), sext(), llvm::TargetLowering::SimplifyDemandedBits(), SolveLinEquationWithOverflow(), llvm::ConstantRange::zeroExtend(), and zextOrTrunc().

APInt & APInt::sextOrTrunc ( unsigned  width  ) 

Sign extend or truncate to width.

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

Definition at line 974 of file APInt.cpp.

References sext(), and trunc().

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

APInt & APInt::zextOrTrunc ( unsigned  width  ) 

Zero extend or truncate to width.

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

Definition at line 966 of file APInt.cpp.

References trunc(), and zext().

Referenced by llvm::ComputeMaskedBits(), llvm::Interpreter::exitCalled(), llvm::APSInt::extOrTrunc(), llvm::ExecutionEngine::getConstantValue(), and ShrinkDemandedConstant().

APInt& llvm::APInt::set (  )  [inline]

Definition at line 942 of file APInt.h.

References getNumWords(), pVal, and VAL.

Referenced by ComputeSignedMinMaxValuesFromKnownBits(), and SolveLinEquationWithOverflow().

APInt & APInt::set ( unsigned  bitPosition  ) 

Set a given bit to 1.

Set the given bit to 1 whose position is given as "bitPosition".

Definition at line 559 of file APInt.cpp.

References pVal.

APInt& llvm::APInt::clear (  )  [inline]

Set every bit to 0.

Definition at line 960 of file APInt.h.

References getNumWords(), llvm::Intrinsic::memset, pVal, and VAL.

Referenced by llvm::ComputeMaskedBits(), ComputeSignedMinMaxValuesFromKnownBits(), flip(), and operator*=().

APInt & APInt::clear ( unsigned  bitPosition  ) 

Set a given bit to 0.

Set the given bit to 0 whose position is given as "bitPosition".

Definition at line 569 of file APInt.cpp.

References pVal.

APInt& llvm::APInt::flip (  )  [inline]

Toggle every bit to its opposite value.

Definition at line 973 of file APInt.h.

References getNumWords(), pVal, and VAL.

Referenced by operator~(), slt(), and toString().

APInt & APInt::flip ( unsigned  bitPosition  ) 

Toggles a given bit to its opposite value.

Toggle every bit to its opposite value.

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

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 582 of file APInt.cpp.

References clear().

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

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 1000 of file APInt.h.

Referenced by APInt(), ashr(), clear(), llvm::APFloat::convertFromAPInt(), countLeadingOnes(), countTrailingZeros(), Emit(), flip(), getHashValue(), isIntN(), lshr(), operator &=(), operator!(), operator*=(), operator+(), operator++(), operator+=(), operator-(), operator--(), operator-=(), operator=(), operator^=(), operator|=(), Profile(), set(), sext(), toString(), trunc(), and zext().

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

Compute the number of active bits in the value.

This function returns the number of active bits which is defined as the bit width minus the number of leading zeros. This is used in several computations to see how "wide" the value is.

Definition at line 1008 of file APInt.h.

References countLeadingZeros().

Referenced by getActiveWords(), getLimitedValue(), getMinSignedBits(), llvm::LoopBase< BlockT >::getSmallConstantTripMultiple(), getZExtValue(), isRunOfOnes(), operator*=(), roundToDouble(), sqrt(), udiv(), udivrem(), llvm::ConstantInt::uge(), ult(), and urem().

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

This function returns 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 1015 of file APInt.h.

References getActiveBits().

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 1026 of file APInt.h.

References countLeadingOnes(), getActiveBits(), and isNegative().

Referenced by getSExtValue(), and isSignedIntN().

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

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 1047 of file APInt.h.

References getMinSignedBits(), pVal, and VAL.

Referenced by llvm::ConstantInt::getSExtValue(), LLVMGenericValueToInt(), and toString().

unsigned APInt::getBitsNeeded ( const char *  str,
unsigned  slen,
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 of length slen.

Definition at line 589 of file APInt.cpp.

References isNegative(), and logBase2().

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

countLeadingZeros - This function is an APInt version of the countLeadingZeros_{32,64} 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.

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

Definition at line 1066 of file APInt.h.

References llvm::CountLeadingZeros_64(), and VAL.

Referenced by llvm::ComputeNumSignBits(), llvm::SelectionDAG::ComputeNumSignBits(), getActiveBits(), llvm::SelectionDAG::getNode(), and logBase2().

unsigned APInt::countLeadingOnes (  )  const

Count the number of leading one bits.

countLeadingOnes - This function is an APInt version of the countLeadingOnes_{32,64} 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

the number of 1 bits from the most significant to the least

Definition at line 681 of file APInt.cpp.

References countLeadingOnes_64(), getNumWords(), and pVal.

Referenced by llvm::SelectionDAG::ComputeNumSignBits(), llvm::RegsForValue::getCopyFromRegs(), and getMinSignedBits().

unsigned APInt::countTrailingZeros (  )  const

Count the number of trailing zero bits.

countTrailingZeros - This function is an APInt version of the countTrailingZeros_{32,64} functions in MathExtras.h. It counts the number of zeros from the least significant bit to the first set bit.

Returns:
BitWidth if the value is zero.

the number of zeros from the least significant bit to the first one bit.

Definition at line 708 of file APInt.cpp.

References llvm::CountTrailingZeros_64(), getNumWords(), and pVal.

Referenced by BinomialCoefficient(), llvm::SelectionDAG::getNode(), and SolveLinEquationWithOverflow().

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

Count the number of trailing one bits.

countTrailingOnes - This function is an APInt version of the countTrailingOnes_{32,64} 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.

the number of ones from the least significant bit to the first zero bit.

Definition at line 1098 of file APInt.h.

References llvm::CountTrailingOnes_64(), and VAL.

Referenced by llvm::ComputeMaskedBits().

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

Count the number of bits set.

countPopulation - This function is an APInt version of the countPopulation_{32,64} functions in MathExtras.h. It counts the number of 1 bits in the APInt value.

Returns:
0 if the value is zero.

the number of set bits.

Definition at line 1110 of file APInt.h.

References llvm::CountPopulation_64(), and VAL.

Referenced by llvm::SelectionDAG::getNode(), isAllOnesValue(), isMaxSignedValue(), isMaxValue(), isMinSignedValue(), isMinValue(), and ValueHasExactlyOneBitSet().

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

Definition at line 2004 of file APInt.cpp.

References llvm::SmallString< InternalLen >::c_str(), and toString().

Referenced by llvm::operator<<().

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

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 or 16.

Definition at line 1127 of file APInt.h.

References toString().

Referenced by dump(), llvm::AsmPrinter::EmitConstantValueOnly(), llvm::AsmPrinter::EmitGlobalConstant(), and llvm::Interpreter::run().

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 or 16.

Definition at line 1133 of file APInt.h.

References toString().

Referenced by dump().

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

toString - This 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.

toString - This 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.

Definition at line 1990 of file APInt.cpp.

References llvm::SmallString< InternalLen >::c_str(), and toString().

APInt APInt::byteSwap (  )  const

Returns:
a byte-swapped representation of this APInt Value.

Definition at line 737 of file APInt.cpp.

References APInt(), llvm::ByteSwap_16(), llvm::ByteSwap_32(), llvm::ByteSwap_64(), and pVal.

Referenced by llvm::APIntOps::byteSwap(), and llvm::SelectionDAG::getNode().

double APInt::roundToDouble ( bool  isSigned  )  const

Converts this APInt to a double value.

RoundToDouble - This function convert 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 817 of file APInt.cpp.

References llvm::Intrinsic::exp, getActiveBits(), pVal, sext(), and T.

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

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

Converts this unsigned APInt to a double value.

Definition at line 1150 of file APInt.h.

Referenced by signedRoundToDouble().

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

Converts this signed APInt to a double value.

Definition at line 1155 of file APInt.h.

References roundToDouble().

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

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 1163 of file APInt.h.

References pVal, T, and VAL.

Referenced by llvm::APFloat::convertToDouble(), llvm::ExecutionEngine::getConstantValue(), and llvm::SelectionDAG::getNode().

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

Converts APInt bits to a double.

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 1176 of file APInt.h.

References F, pVal, T, and VAL.

Referenced by llvm::APFloat::convertToFloat(), llvm::ExecutionEngine::getConstantValue(), and llvm::SelectionDAG::getNode().

APInt& llvm::APInt::doubleToBits ( double  V  )  [inline]

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. Note that it is valid to do this on any bit width but bits from V may get truncated.

Definition at line 1189 of file APInt.h.

References pVal, T, and VAL.

Referenced by llvm::APFloat::APFloat(), and llvm::ExecutionEngine::getConstantValue().

APInt& llvm::APInt::floatToBits ( float  V  )  [inline]

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. Note that it is valid to do this on any bit width but bits from V may get truncated.

Definition at line 1206 of file APInt.h.

References F, pVal, T, and VAL.

Referenced by llvm::APFloat::APFloat(), and llvm::ExecutionEngine::getConstantValue().

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

Returns:
the floor log base 2 of this APInt.

Definition at line 1224 of file APInt.h.

References countLeadingZeros().

Referenced by exactLogBase2(), getBitsNeeded(), llvm::APIntOps::logBase2(), LowerEXTRACT_VECTOR_ELT(), and llvm::SCEVExpander::visitUDivExpr().

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 1230 of file APInt.h.

References isPowerOf2(), and logBase2().

APInt APInt::sqrt (  )  const

Compute the square root.

Definition at line 1233 of file APInt.cpp.

References APInt(), getActiveBits(), offset, shl(), udiv(), ule(), and ult().

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

Get the absolute value;.

If *this is < 0 then return -(*this), otherwise *this;

Definition at line 1241 of file APInt.h.

References isNegative().

Referenced by magic().

APInt APInt::multiplicativeInverse ( const APInt &  modulo  )  const

Returns:
the multiplicative inverse for a given modulo.
Computes the multiplicative inverse of this APInt 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.

Definition at line 1321 of file APInt.cpp.

References APInt(), isNegative(), udivrem(), and ult().

Referenced by BinomialCoefficient(), and SolveLinEquationWithOverflow().

void APInt::tcSet ( integerPart *  dst,
integerPart  part,
unsigned int  parts 
) [static]

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

Definition at line 2099 of file APInt.cpp.

Referenced by llvm::APFloat::convert(), and tcDivide().

void APInt::tcAssign ( integerPart *  dst,
const integerPart *  src,
unsigned int  parts 
) [static]

Assign one bignum to another.

Definition at line 2112 of file APInt.cpp.

Referenced by llvm::APFloat::convert(), llvm::APFloat::convertFromSignExtendedInteger(), tcDivide(), and tcExtract().

bool APInt::tcIsZero ( const integerPart *  src,
unsigned int  parts 
) [static]

Returns true if a bignum is zero, false otherwise.

Definition at line 2122 of file APInt.cpp.

int APInt::tcExtractBit ( const integerPart *  parts,
unsigned int  bit 
) [static]

Extract the given bit of a bignum; returns 0 or 1. Zero-based.

Definition at line 2135 of file APInt.cpp.

References llvm::integerPartWidth.

Referenced by llvm::APFloat::convertFromSignExtendedInteger(), and llvm::APFloat::convertFromZeroExtendedInteger().

void APInt::tcExtract ( integerPart *  dst,
unsigned int  dstCount,
const integerPart *  src,
unsigned int  srcBits,
unsigned int  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 2191 of file APInt.cpp.

References llvm::integerPartWidth, lowBitMask(), tcAssign(), and tcShiftRight().

void APInt::tcSetBit ( integerPart *  parts,
unsigned int  bit 
) [static]

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

Definition at line 2143 of file APInt.cpp.

References llvm::integerPartWidth.

unsigned int APInt::tcLSB ( const integerPart *  parts,
unsigned int  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 2151 of file APInt.cpp.

References llvm::integerPartWidth, and partLSB().

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

unsigned int APInt::tcMSB ( const integerPart *  parts,
unsigned int  n 
) [static]

Definition at line 2169 of file APInt.cpp.

References llvm::integerPartWidth, and partMSB().

Referenced by tcDivide().

void APInt::tcNegate ( integerPart *  dst,
unsigned int  parts 
) [static]

Negate a bignum in-place.

Definition at line 2275 of file APInt.cpp.

References tcComplement(), and tcIncrement().

Referenced by llvm::APFloat::convertFromSignExtendedInteger().

static integerPart llvm::APInt::tcAdd ( integerPart *  ,
const integerPart *  ,
integerPart  carry,
unsigned   
) [static]

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

static integerPart llvm::APInt::tcSubtract ( integerPart *  ,
const integerPart *  ,
integerPart  carry,
unsigned   
) [static]

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

Referenced by tcDivide().

int APInt::tcMultiplyPart ( integerPart *  dst,
const integerPart *  src,
integerPart  multiplier,
integerPart  carry,
unsigned int  srcParts,
unsigned int  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 2293 of file APInt.cpp.

References highHalf(), llvm::integerPartWidth, and lowHalf().

static int llvm::APInt::tcMultiply ( integerPart *  ,
const integerPart *  ,
const integerPart *  ,
unsigned   
) [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.

static unsigned int llvm::APInt::tcFullMultiply ( integerPart *  ,
const integerPart *  ,
const integerPart *  ,
unsigned  ,
unsigned   
) [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. Returns the number of parts required to hold the result.

int APInt::tcDivide ( integerPart *  lhs,
const integerPart *  rhs,
integerPart *  remainder,
integerPart *  scratch,
unsigned int  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 2443 of file APInt.cpp.

References compare(), llvm::integerPartWidth, tcAssign(), tcCompare(), tcMSB(), tcSet(), tcShiftLeft(), tcShiftRight(), and tcSubtract().

void APInt::tcShiftLeft ( integerPart *  dst,
unsigned int  parts,
unsigned int  count 
) [static]

Shift a bignum left COUNT bits. Shifted in bits are zero. There are no restrictions on COUNT.

Definition at line 2490 of file APInt.cpp.

References llvm::integerPartWidth.

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

void APInt::tcShiftRight ( integerPart *  dst,
unsigned int  parts,
unsigned int  count 
) [static]

Shift a bignum right COUNT bits. Shifted in bits are zero. There are no restrictions on COUNT.

Definition at line 2524 of file APInt.cpp.

References llvm::integerPartWidth.

Referenced by llvm::APFloat::convert(), tcDivide(), and tcExtract().

void APInt::tcAnd ( integerPart *  dst,
const integerPart *  rhs,
unsigned int  parts 
) [static]

The obvious AND, OR and XOR and complement operations.

Definition at line 2556 of file APInt.cpp.

void APInt::tcOr ( integerPart *  dst,
const integerPart *  rhs,
unsigned int  parts 
) [static]

Definition at line 2566 of file APInt.cpp.

void APInt::tcXor ( integerPart *  dst,
const integerPart *  rhs,
unsigned int  parts 
) [static]

Definition at line 2576 of file APInt.cpp.

void APInt::tcComplement ( integerPart *  dst,
unsigned int  parts 
) [static]

Definition at line 2586 of file APInt.cpp.

Referenced by tcNegate().

int APInt::tcCompare ( const integerPart *  lhs,
const integerPart *  rhs,
unsigned int  parts 
) [static]

Comparison (unsigned) of two bignums.

Definition at line 2596 of file APInt.cpp.

Referenced by tcDivide().

integerPart APInt::tcIncrement ( integerPart *  dst,
unsigned int  parts 
) [static]

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

Definition at line 2615 of file APInt.cpp.

Referenced by tcNegate().

void APInt::tcSetLeastSignificantBits ( integerPart *  dst,
unsigned int  parts,
unsigned int  bits 
) [static]

Set the least significant BITS and clear the rest.

Definition at line 2629 of file APInt.cpp.

References llvm::integerPartWidth.

Referenced by llvm::APFloat::convertToInteger().

void APInt::dump (  )  const

debug method

Definition at line 1997 of file APInt.cpp.

References llvm::SmallString< InternalLen >::c_str(), toStringSigned(), and toStringUnsigned().


Member Data Documentation

uint64_t llvm::APInt::VAL

uint64_t* llvm::APInt::pVal


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