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 ()
 getTrue/getFalse - Return the singleton true/false values.
static ConstantInt * getFalse ()
static ConstantInt * get (const Type *Ty, uint64_t V, bool isSigned=false)
 Get a ConstantInt for a specific value.
static ConstantInt * get (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 ConstantInt * getAllOnesValue (const Type *Ty)
 Get the all ones value.
static bool classof (const ConstantInt *)
 Methods to support type inquiry through isa, cast, and dyn_cast.
static bool classof (const Value *V)
static void ResetTrueFalse ()

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 46 of file Constants.h.


Member Function Documentation

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

Reimplemented from llvm::User.

Definition at line 54 of file Constants.h.

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

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

getBitWidth - Return the bitwidth of this constant.

Definition at line 66 of file Constants.h.

References llvm::APInt::getBitWidth().

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

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

Return the zero extended value.

Return the constant as a 64-bit unsigned integer value after it has been zero 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 73 of file Constants.h.

References llvm::APInt::getZExtValue().

Referenced by llvm::ConstantFoldLoadThroughGEPConstantExpr(), DecomposeSimpleLinearExpr(), EvaluateFunction(), EvaluateGEPOffsetExpression(), EvaluateStoreInto(), llvm::Interpreter::executeGEPOperation(), FoldCondBranchOnPHI(), getAggregateConstantElement(), llvm::GetConstantStringInfo(), GetOffsetFromIndex(), llvm::LoopBase< BlockT >::getSmallConstantTripMultiple(), IsConstantOffsetFromGlobal(), IsUserOfGlobalSafeForSRA(), and OptimizeGlobalAddressOfMalloc().

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 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 82 of file Constants.h.

References llvm::APInt::getSExtValue().

Referenced by EvaluateGEPOffsetExpression(), GetOffsetFromIndex(), IsConstantOffsetFromGlobal(), 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 90 of file Constants.h.

static ConstantInt* llvm::ConstantInt::getTrue (  )  [inline, static]

static ConstantInt* llvm::ConstantInt::getFalse (  )  [inline, static]

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

Get a ConstantInt for a specific 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 252 of file Constants.cpp.

References llvm::IntegerType::getBitWidth().

Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::ConstantFoldCall(), llvm::ConstantFoldCastInstruction(), llvm::ConstantFoldCompareInstruction(), llvm::ConstantFoldInstOperands(), llvm::DIFactory::CreateBasicType(), llvm::DIFactory::CreateCompileUnit(), llvm::DIFactory::CreateCompositeType(), llvm::DIFactory::CreateDerivedType(), llvm::DIFactory::CreateEnumerator(), llvm::IRBuilder< preserveNames, T >::CreateGlobalStringPtr(), llvm::DIFactory::CreateGlobalVariable(), llvm::IRBuilder< preserveNames, T >::CreateStructGEP(), llvm::DIFactory::CreateSubprogram(), llvm::DIFactory::CreateVariable(), llvm::ARMRegisterInfo::emitLoadConstPool(), llvm::ExtractElementInst::ExtractElementInst(), llvm::ConstantArray::get(), llvm::ScalarEvolution::getAddExpr(), getAISize(), getAllOnesValue(), llvm::Constant::getAllOnesValue(), llvm::SelectionDAG::getConstant(), llvm::ScalarEvolution::getConstant(), llvm::ScalarEvolution::getIntegerSCEV(), getMinusOne(), llvm::ScalarEvolution::getMulExpr(), llvm::Constant::getNullValue(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), llvm::DIFactory::GetOrCreateSubrange(), getPlusOne(), llvm::FastISel::getRegForValue(), llvm::ConstantExpr::getSizeOf(), llvm::ScalarEvolution::getSMaxExpr(), llvm::ScalarEvolution::getUMaxExpr(), llvm::ConstantExpr::getVFCmp(), llvm::ConstantExpr::getVICmp(), llvm::RSProfilers_std::IncrementCounterInBlock(), llvm::IncrementCounterInBlock(), llvm::InlineFunction(), llvm::InsertProfilingInitCall(), llvm::DIFactory::InsertStopPoint(), LowerBSWAP(), LowerCTLZ(), LowerCTPOP(), llvm::IntrinsicLowering::LowerIntrinsicCall(), LowerPartSelect(), LowerPartSet(), llvm::JIT::runFunction(), SRAGlobal(), TryToOptimizeStoreOfMallocToGlobal(), TryToShrinkGlobalToBoolean(), llvm::UpgradeIntrinsicCall(), llvm::SCEVExpander::visitAddRecExpr(), and llvm::SCEVExpander::visitUDivExpr().

ConstantInt * ConstantInt::get ( 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 262 of file Constants.cpp.

References llvm::IntegerType::get(), and llvm::APInt::getBitWidth().

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 118 of file Constants.h.

References llvm::Intrinsic::getType().

Referenced by llvm::ConstantFoldBinaryInstruction(), FoldCondBranchOnPHI(), isRunOfOnes(), isSignBitCheck(), LowerPartSet(), and llvm::MemIntrinsic::setAlignment().

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 935 of file Constants.cpp.

References getBitWidth(), and llvm::Type::Int1Ty.

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

Definition at line 945 of file Constants.cpp.

References getBitWidth(), and llvm::Type::Int1Ty.

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 138 of file Constants.h.

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 145 of file Constants.h.

Referenced by evaluateFCmpRelation(), EvaluateGEPOffsetExpression(), evaluateICmpRelation(), getBitCastOperand(), llvm::GetConstantStringInfo(), GetOffsetFromIndex(), GetStringLengthH(), 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 153 of file Constants.h.

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 161 of file Constants.h.

References llvm::APInt::isAllOnesValue().

Referenced by llvm::ConstantVector::isAllOnesValue(), 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 170 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 182 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 194 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 203 of file Constants.h.

References llvm::APInt::getLimitedValue().

Referenced by dyn_castFoldableMul().

ConstantInt * ConstantInt::getAllOnesValue ( const Type *  Ty  )  [static]

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

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

Definition at line 213 of file Constants.h.

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

Reimplemented from llvm::Constant.

Definition at line 214 of file Constants.h.

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

static void llvm::ConstantInt::ResetTrueFalse (  )  [inline, static]

Definition at line 217 of file Constants.h.

Referenced by llvm::CleanupTrueFalse().


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