LLVM API Documentation

llvm::ConstantInt Class Reference

Class for constant integers. More...

#include <Constants.h>

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

List of all members.

Public Member Functions

const APInt & getValue () const
 Return the constant's value.
unsigned getBitWidth () const
 getBitWidth - Return the bitwidth of this constant.
uint64_t getZExtValue () const
 Return the zero extended value.
int64_t getSExtValue () const
 Return the sign extended value.
bool equalsInt (uint64_t V) const
 Determine if this constant's value is same as an unsigned char.
const IntegerType * getType () const
virtual bool isNullValue () const
 Determine if the value is null.
bool isZero () const
bool isOne () const
 Determine if the value is one.
bool isAllOnesValue () const
 Determine if the value is all ones.
bool isMaxValue (bool isSigned) const
 Determine if the value is maximal.
bool isMinValue (bool isSigned) const
 Determine if the value is minimal.
bool uge (uint64_t Num)
 Determine if the value is greater or equal to the given number.
uint64_t getLimitedValue (uint64_t Limit=~0ULL) const
 Get the constant's value with a saturation limit.

Static Public Member Functions

static ConstantInt * getTrue (LLVMContext &Context)
static ConstantInt * getFalse (LLVMContext &Context)
static Constant * get (const Type *Ty, uint64_t V, bool isSigned=false)
static ConstantInt * get (const IntegerType *Ty, uint64_t V, bool isSigned=false)
 Get a ConstantInt for a specific value.
static ConstantInt * getSigned (const IntegerType *Ty, int64_t V)
 Get a ConstantInt for a specific signed value.
static Constant * getSigned (const Type *Ty, int64_t V)
static ConstantInt * get (LLVMContext &Context, const APInt &V)
static ConstantInt * get (const IntegerType *Ty, const StringRef &Str, uint8_t radix)
static Constant * get (const Type *Ty, const APInt &V)
static bool isValueValidForType (const Type *Ty, uint64_t V)
 Determine if the value is in range for the given type.
static bool isValueValidForType (const Type *Ty, int64_t V)
static bool classof (const ConstantInt *)
 Methods to support type inquiry through isa, cast, and dyn_cast.
static bool classof (const Value *V)

Protected Member Functions

void * operator new (size_t s)


Detailed Description

Class for constant integers.

This is the shared class of boolean and integer constants. This class represents both boolean and integral constants.

Definition at line 47 of file Constants.h.


Member Function Documentation

void* llvm::ConstantInt::operator new ( size_t  s  )  [inline, protected]

Reimplemented from llvm::User.

Definition at line 55 of file Constants.h.

References operator new().

ConstantInt * ConstantInt::getTrue ( LLVMContext &  Context  )  [static]

ConstantInt * ConstantInt::getFalse ( LLVMContext &  Context  )  [static]

Constant * ConstantInt::get ( const Type *  Ty,
uint64_t  V,
bool  isSigned = false 
) [static]

If Ty is a vector type, return a Constant with a splat of the given value. Otherwise return a ConstantInt for the given value.

Definition at line 279 of file Constants.cpp.

References llvm::CallingConv::C, llvm::ConstantVector::get(), and llvm::Type::getScalarType().

Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::ConstantFoldCall(), llvm::ConstantFoldCastInstruction(), llvm::ConstantFoldCompareInstruction(), llvm::ConstantFoldInstOperands(), llvm::DIFactory::CreateBasicType(), llvm::DIFactory::CreateCompileUnit(), llvm::DIFactory::CreateCompositeType(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateConstGEP1_32(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateConstGEP1_64(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateConstGEP2_32(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateConstGEP2_64(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateConstInBoundsGEP1_32(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateConstInBoundsGEP1_64(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateConstInBoundsGEP2_32(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateConstInBoundsGEP2_64(), llvm::DIFactory::CreateDerivedType(), llvm::DIFactory::CreateEnumerator(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateGlobalStringPtr(), llvm::DIFactory::CreateGlobalVariable(), llvm::DIFactory::CreateSubprogram(), llvm::DIFactory::CreateVariable(), llvm::Thumb2RegisterInfo::emitLoadConstPool(), llvm::Thumb1RegisterInfo::emitLoadConstPool(), llvm::ARMBaseRegisterInfo::emitLoadConstPool(), FactorOutConstant(), llvm::ConstantArray::get(), getAISize(), llvm::ConstantExpr::getAlignOf(), llvm::ScalarEvolution::getAllocSizeExpr(), llvm::Constant::getAllOnesValue(), llvm::SelectionDAG::getConstant(), llvm::ScalarEvolution::getConstant(), getFalse(), llvm::ScalarEvolution::getIntegerSCEV(), llvm::Constant::getIntegerValue(), getMinusOne(), llvm::ScalarEvolution::getMulExpr(), llvm::Constant::getNullValue(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), llvm::ConstantExpr::getOffsetOf(), llvm::DIFactory::GetOrCreateSubrange(), getPlusOne(), llvm::FastISel::getRegForValue(), llvm::ConstantExpr::getSizeOf(), llvm::ScalarEvolution::getSMaxExpr(), getTrue(), llvm::ScalarEvolution::getUMaxExpr(), llvm::RSProfilers_std::IncrementCounterInBlock(), llvm::IncrementCounterInBlock(), llvm::InlineFunction(), llvm::InsertProfilingInitCall(), llvm::DIFactory::InsertStopPoint(), LowerBSWAP(), LowerCTLZ(), LowerCTPOP(), llvm::IntrinsicLowering::LowerIntrinsicCall(), llvm::JIT::runFunction(), SimplifyCondBranchToCondBranch(), SolveQuadraticEquation(), SRAGlobal(), TryToOptimizeStoreOfMallocToGlobal(), TryToShrinkGlobalToBoolean(), and llvm::UpgradeIntrinsicCall().

ConstantInt * ConstantInt::get ( const IntegerType *  Ty,
uint64_t  V,
bool  isSigned = false 
) [static]

Get a ConstantInt for a specific value.

Return a ConstantInt with the specified integer value for the specified type. If the type is wider than 64 bits, the value will be zero-extended to fit the type, unless isSigned is true, in which case the value will be interpreted as a 64-bit signed integer and sign-extended to fit the type.

Definition at line 291 of file Constants.cpp.

References llvm::IntegerType::getBitWidth(), and llvm::Type::getContext().

ConstantInt * ConstantInt::getSigned ( const IntegerType *  Ty,
int64_t  V 
) [static]

Get a ConstantInt for a specific signed value.

Return a ConstantInt with the specified value for the specified type. The value V will be canonicalized to a an unsigned APInt. Accessing it with either getSExtValue() or getZExtValue() will yield a correctly sized and signed value for the type Ty.

Definition at line 296 of file Constants.cpp.

Constant * ConstantInt::getSigned ( const Type *  Ty,
int64_t  V 
) [static]

Definition at line 300 of file Constants.cpp.

ConstantInt * ConstantInt::get ( LLVMContext &  Context,
const APInt &  V 
) [static]

Return a ConstantInt with the specified value and an implied Type. The type is the integer type that corresponds to the bit width of the value.

Definition at line 256 of file Constants.cpp.

References llvm::LLVMContextImpl::ConstantsLock, llvm::IntegerType::get(), llvm::APInt::getBitWidth(), llvm::LLVMContextImpl::IntConstants, llvm::LLVMContext::pImpl, llvm::sys::SmartRWMutex< mt_only >::reader_acquire(), and llvm::sys::SmartRWMutex< mt_only >::reader_release().

ConstantInt * ConstantInt::get ( const IntegerType *  Ty,
const StringRef &  Str,
uint8_t  radix 
) [static]

Return a ConstantInt constructed from the string strStart with the given radix.

Definition at line 317 of file Constants.cpp.

References llvm::IntegerType::getBitWidth(), and llvm::Type::getContext().

Constant * ConstantInt::get ( const Type *  Ty,
const APInt &  V 
) [static]

If Ty is a vector type, return a Constant with a splat of the given value. Otherwise return a ConstantInt for the given value.

Definition at line 304 of file Constants.cpp.

References llvm::CallingConv::C, llvm::ConstantVector::get(), llvm::Type::getContext(), llvm::Type::getScalarType(), and getType().

const APInt& llvm::ConstantInt::getValue (  )  const [inline]

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

getBitWidth - Return the bitwidth of this constant.

Definition at line 104 of file Constants.h.

References llvm::APInt::getBitWidth().

Referenced by llvm::SelectionDAG::getConstant(), isValueValidForType(), and MultiplyOverflows().

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

int64_t llvm::ConstantInt::getSExtValue (  )  const [inline]

Return the sign extended value.

Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the type of this constant. Note that this method can assert if the value does not fit in 64 bits.

Deprecated:

Definition at line 120 of file Constants.h.

References llvm::APInt::getSExtValue().

Referenced by EvaluateGEPOffsetExpression(), GetOffsetFromIndex(), IsConstantOffsetFromGlobal(), llvm::MSILWriter::printStaticConstant(), and X86ChooseCmpImmediateOpcode().

bool llvm::ConstantInt::equalsInt ( uint64_t  V  )  const [inline]

Determine if this constant's value is same as an unsigned char.

A helper method that can be used to determine if the constant contained within is equal to a constant. This only works for very small values, because this is all that can be represented with all types.

Definition at line 128 of file Constants.h.

const IntegerType* llvm::ConstantInt::getType (  )  const [inline]

getType - Specialize the getType() method to always return an IntegerType, which reduces the amount of casting needed in parts of the compiler.

Reimplemented from llvm::Value.

Definition at line 135 of file Constants.h.

References llvm::Intrinsic::getType().

Referenced by FoldCondBranchOnPHI(), get(), isRunOfOnes(), isSignBitCheck(), ShrinkDemandedConstant(), and SubOne().

bool ConstantInt::isValueValidForType ( const Type *  Ty,
uint64_t  V 
) [static]

Determine if the value is in range for the given type.

This static method returns true if the type Ty is big enough to represent the value V. This can be used to avoid having the get method assert when V is larger than Ty can represent. Note that there are two versions of this method, one for unsigned and one for signed integers. Although ConstantInt canonicalizes everything to an unsigned integer, the signed version avoids callers having to convert a signed quantity to the appropriate unsigned type before calling the method.

Returns:
true if V is a valid value for type Ty

Definition at line 794 of file Constants.cpp.

References getBitWidth(), llvm::Type::getContext(), and llvm::Type::getInt1Ty().

Referenced by llvm::X86TargetLowering::LowerAsmOperandForConstraint().

bool ConstantInt::isValueValidForType ( const Type *  Ty,
int64_t  V 
) [static]

Definition at line 804 of file Constants.cpp.

References getBitWidth(), llvm::Type::getContext(), and llvm::Type::getInt1Ty().

virtual bool llvm::ConstantInt::isNullValue (  )  const [inline, virtual]

Determine if the value is null.

This function will return true iff this constant represents the "null" value that would be returned by the getNullValue method.

Returns:
true if this is the null integer value.

Implements llvm::Constant.

Definition at line 155 of file Constants.h.

Referenced by llvm::Instruction::isSafeToSpeculativelyExecute().

bool llvm::ConstantInt::isZero (  )  const [inline]

This is just a convenience method to make client code smaller for a common code. It also correctly performs the comparison without the potential for an assertion from getZExtValue().

Definition at line 162 of file Constants.h.

Referenced by evaluateFCmpRelation(), EvaluateGEPOffsetExpression(), evaluateICmpRelation(), FactorOutConstant(), llvm::GetConstantStringInfo(), GetOffsetFromIndex(), GetStringLengthH(), isSelect01(), and isSignBitCheck().

bool llvm::ConstantInt::isOne (  )  const [inline]

Determine if the value is one.

This is just a convenience method to make client code smaller for a common case. It also correctly performs the comparison without the potential for an assertion from getZExtValue().

Definition at line 170 of file Constants.h.

Referenced by isSelect01().

bool llvm::ConstantInt::isAllOnesValue (  )  const [inline]

Determine if the value is all ones.

This function will return true iff every bit in this constant is set to true.

Returns:
true iff this constant's bits are all set to true.

Definition at line 178 of file Constants.h.

References llvm::APInt::isAllOnesValue().

Referenced by llvm::ConstantVector::isAllOnesValue(), llvm::Instruction::isSafeToSpeculativelyExecute(), and isSignBitCheck().

bool llvm::ConstantInt::isMaxValue ( bool  isSigned  )  const [inline]

Determine if the value is maximal.

This function will return true iff this constant represents the largest value that may be represented by the constant's type.

Returns:
true iff this is the largest value that may be represented by this type.

Definition at line 187 of file Constants.h.

References llvm::APInt::isMaxSignedValue(), and llvm::APInt::isMaxValue().

bool llvm::ConstantInt::isMinValue ( bool  isSigned  )  const [inline]

Determine if the value is minimal.

This function will return true iff this constant represents the smallest value that may be represented by this constant's type.

Returns:
true if this is the smallest value that may be represented by this type.

Definition at line 199 of file Constants.h.

References llvm::APInt::isMinSignedValue(), and llvm::APInt::isMinValue().

bool llvm::ConstantInt::uge ( uint64_t  Num  )  [inline]

Determine if the value is greater or equal to the given number.

This function will return true iff this constant represents a value with active bits bigger than 64 bits or a value greater than the given uint64_t value.

Returns:
true iff this constant is greater or equal to the given number.

Definition at line 211 of file Constants.h.

References llvm::APInt::getActiveBits(), and llvm::APInt::getZExtValue().

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

Get the constant's value with a saturation limit.

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

Returns:
the min of the value of the constant and the specified value

Definition at line 220 of file Constants.h.

References llvm::APInt::getLimitedValue().

Referenced by dyn_castFoldableMul().

static bool llvm::ConstantInt::classof ( const ConstantInt *   )  [inline, static]

Methods to support type inquiry through isa, cast, and dyn_cast.

Definition at line 225 of file Constants.h.

static bool llvm::ConstantInt::classof ( const Value *  V  )  [inline, static]

Reimplemented from llvm::Constant.

Definition at line 226 of file Constants.h.

References llvm::Value::ConstantIntVal, and llvm::Value::getValueID().


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