LLVM API Documentation
LLVM Constant Representation. More...
#include <Constant.h>
Public Types | |
enum | PossibleRelocationsTy { NoRelocation = 0, LocalRelocation = 1, GlobalRelocations = 2 } |
![]() | |
typedef Use * | op_iterator |
typedef const Use * | const_op_iterator |
![]() | |
enum | ValueTy { ArgumentVal, BasicBlockVal, FunctionVal, GlobalAliasVal, GlobalVariableVal, UndefValueVal, BlockAddressVal, ConstantExprVal, ConstantAggregateZeroVal, ConstantDataArrayVal, ConstantDataVectorVal, ConstantIntVal, ConstantFPVal, ConstantArrayVal, ConstantStructVal, ConstantVectorVal, ConstantPointerNullVal, MDNodeVal, MDStringVal, InlineAsmVal, PseudoSourceValueVal, FixedStackPseudoSourceValueVal, InstructionVal, ConstantFirstVal = FunctionVal, ConstantLastVal = ConstantPointerNullVal } |
typedef value_use_iterator< User > | use_iterator |
typedef value_use_iterator < const User > | const_use_iterator |
Public Member Functions | |
bool | isNullValue () const |
bool | isAllOnesValue () const |
bool | isNegativeZeroValue () const |
bool | isZeroValue () const |
Return true if the value is negative zero or null value. More... | |
bool | canTrap () const |
bool | isThreadDependent () const |
isThreadDependent - Return true if the value can vary between threads. More... | |
bool | isConstantUsed () const |
PossibleRelocationsTy | getRelocationInfo () const |
Constant * | getAggregateElement (unsigned Elt) const |
Constant * | getAggregateElement (Constant *Elt) const |
Constant * | getSplatValue () const |
const APInt & | getUniqueInteger () const |
virtual void | destroyConstant () |
virtual void | replaceUsesOfWithOnConstant (Value *, Value *, Use *) |
void | removeDeadConstantUsers () const |
![]() | |
~User () | |
void | operator delete (void *Usr) |
operator delete - free memory allocated for User and Use objects More... | |
void | operator delete (void *, unsigned) |
placement delete - required by std, but never called. More... | |
void | operator delete (void *, unsigned, bool) |
placement delete - required by std, but never called. More... | |
Value * | getOperand (unsigned i) const |
void | setOperand (unsigned i, Value *Val) |
const Use & | getOperandUse (unsigned i) const |
Use & | getOperandUse (unsigned i) |
unsigned | getNumOperands () const |
op_iterator | op_begin () |
const_op_iterator | op_begin () const |
op_iterator | op_end () |
const_op_iterator | op_end () const |
value_op_iterator | value_op_begin () |
value_op_iterator | value_op_end () |
void | dropAllReferences () |
void | replaceUsesOfWith (Value *From, Value *To) |
![]() | |
virtual | ~Value () |
void | dump () const |
dump - Support for debugging, callable in GDB: V->dump() More... | |
void | print (raw_ostream &O, AssemblyAnnotationWriter *AAW=0) const |
Type * | getType () const |
LLVMContext & | getContext () const |
All values hold a context through their type. More... | |
bool | hasName () const |
ValueName * | getValueName () const |
void | setValueName (ValueName *VN) |
StringRef | getName () const |
void | setName (const Twine &Name) |
void | takeName (Value *V) |
void | replaceAllUsesWith (Value *V) |
bool | use_empty () const |
use_iterator | use_begin () |
const_use_iterator | use_begin () const |
use_iterator | use_end () |
const_use_iterator | use_end () const |
User * | use_back () |
const User * | use_back () const |
bool | hasOneUse () const |
bool | hasNUses (unsigned N) const |
bool | hasNUsesOrMore (unsigned N) const |
bool | isUsedInBasicBlock (const BasicBlock *BB) const |
unsigned | getNumUses () const |
void | addUse (Use &U) |
unsigned | getValueID () const |
unsigned | getRawSubclassOptionalData () const |
void | clearSubclassOptionalData () |
bool | hasSameSubclassOptionalData (const Value *V) const |
void | intersectOptionalDataWith (const Value *V) |
bool | hasValueHandle () const |
Value * | stripPointerCasts () |
Strips off any unneeded pointer casts, all-zero GEPs and aliases from the specified value, returning the original uncasted value. More... | |
const Value * | stripPointerCasts () const |
Value * | stripPointerCastsNoFollowAliases () |
Strips off any unneeded pointer casts and all-zero GEPs from the specified value, returning the original uncasted value. More... | |
const Value * | stripPointerCastsNoFollowAliases () const |
Value * | stripInBoundsConstantOffsets () |
Strips off unneeded pointer casts and all-constant GEPs from the specified value, returning the original pointer value. More... | |
const Value * | stripInBoundsConstantOffsets () const |
Value * | stripAndAccumulateInBoundsConstantOffsets (const DataLayout &DL, APInt &Offset) |
Strips like stripInBoundsConstantOffsets but also accumulates the constant offset stripped. More... | |
const Value * | stripAndAccumulateInBoundsConstantOffsets (const DataLayout &DL, APInt &Offset) const |
Value * | stripInBoundsOffsets () |
Strips off unneeded pointer casts and any in-bounds offsets from the specified value, returning the original pointer value. More... | |
const Value * | stripInBoundsOffsets () const |
bool | isDereferenceablePointer () const |
Value * | DoPHITranslation (const BasicBlock *CurBB, const BasicBlock *PredBB) |
const Value * | DoPHITranslation (const BasicBlock *CurBB, const BasicBlock *PredBB) const |
void | mutateType (Type *Ty) |
Static Public Member Functions | |
static bool | classof (const Value *V) |
static Constant * | getNullValue (Type *Ty) |
static Constant * | getAllOnesValue (Type *Ty) |
Get the all ones value. More... | |
static Constant * | getIntegerValue (Type *Ty, const APInt &V) |
![]() | |
static bool | classof (const Value *V) |
Protected Member Functions | |
Constant (Type *ty, ValueTy vty, Use *Ops, unsigned NumOps) | |
void | destroyConstantImpl () |
![]() | |
void * | operator new (size_t s, unsigned Us) |
User (Type *ty, unsigned vty, Use *OpList, unsigned NumOps) | |
Use * | allocHungoffUses (unsigned) const |
void | dropHungoffUses () |
template<int Idx> | |
Use & | Op () |
template<int Idx> | |
const Use & | Op () const |
![]() | |
virtual void | printCustom (raw_ostream &O) const |
Value (Type *Ty, unsigned scid) | |
unsigned short | getSubclassDataFromValue () const |
void | setValueSubclassData (unsigned short D) |
Additional Inherited Members | |
![]() | |
static const unsigned | MaximumAlignment = 1u << 29 |
![]() | |
template<int Idx, typename U > | |
static Use & | OpFrom (const U *that) |
![]() | |
Use * | OperandList |
unsigned | NumOperands |
![]() | |
unsigned char | SubclassOptionalData: 7 |
LLVM Constant Representation.
This is an important base class in LLVM. It provides the common facilities of all constant values in an LLVM program. A constant is a value that is immutable at runtime. Functions are constants because their address is immutable. Same with global variables.
All constants share the capabilities provided in this class. All constants can have a null value. They can have an operand list. Constants can be simple (integer and floating point values), complex (arrays and structures), or expression based (computations yielding a constant value composed of only certain operators and other constant values).
Note that Constants are immutable (once created they never change) and are fully shared by structural equivalence. This means that two structurally equivalent constants will always have the same address. Constants are created on demand as needed and never deleted: thus clients don't have to worry about the lifetime of the objects.
Definition at line 41 of file Constant.h.
Enumerator | |
---|---|
NoRelocation | |
LocalRelocation | |
GlobalRelocations |
Definition at line 78 of file Constant.h.
Definition at line 47 of file Constant.h.
bool Constant::canTrap | ( | ) | const |
canTrap - Return true if evaluation of this constant could trap. This is true for things like constant expressions that could divide by zero.
Definition at line 275 of file Constants.cpp.
References canTrapImpl().
Referenced by SplitCriticalSideEffectEdges().
Definition at line 125 of file Constant.h.
References llvm::Value::ConstantFirstVal, llvm::Value::ConstantLastVal, and llvm::Value::getValueID().
|
inlinevirtual |
destroyConstant - Called if some element of this constant is no longer valid. At this point only other constants may be on the use_list for this constant. Any constants on our Use list must also be destroy'd. The implementation must be sure to remove the constant from the list of available cached constants. Implementations should call destroyConstantImpl as the last thing they do, to destroy all users and delete this.
Reimplemented in llvm::UndefValue, llvm::ConstantExpr, llvm::BlockAddress, llvm::ConstantDataSequential, llvm::ConstantPointerNull, llvm::ConstantVector, llvm::ConstantStruct, llvm::ConstantArray, llvm::ConstantAggregateZero, and llvm::GlobalValue.
Definition at line 122 of file Constant.h.
References llvm_unreachable.
Referenced by destroyConstantImpl(), RemoveDeadConstant(), and llvm::BitcodeReaderValueList::ResolveConstantForwardRefs().
|
protected |
Definition at line 212 of file Constants.cpp.
References llvm::dbgs(), destroyConstant(), llvm::Value::use_back(), and llvm::Value::use_empty().
Referenced by llvm::ConstantAggregateZero::destroyConstant(), llvm::ConstantArray::destroyConstant(), llvm::ConstantStruct::destroyConstant(), llvm::ConstantVector::destroyConstant(), llvm::ConstantPointerNull::destroyConstant(), llvm::ConstantDataSequential::destroyConstant(), llvm::BlockAddress::destroyConstant(), llvm::ConstantExpr::destroyConstant(), and llvm::UndefValue::destroyConstant().
getAggregateElement - For aggregates (struct/array/vector) return the constant that corresponds to the specified element if possible, or null if not. This can return null if the element index is a ConstantExpr, or if 'this' is a constant expr.
Definition at line 183 of file Constants.cpp.
Referenced by llvm::ConstantFoldCall(), llvm::ConstantFoldExtractElementInstruction(), llvm::ConstantFoldExtractValueInstruction(), llvm::ConstantFoldInsertValueInstruction(), llvm::ConstantFoldLoadThroughGEPConstantExpr(), llvm::ConstantFoldLoadThroughGEPIndices(), EvaluateStoreInto(), FindScalarElement(), FoldBitCast(), llvm::InstCombiner::FoldCmpLoadFromIndexedGlobal(), getAggregateElement(), getArrayElements(), llvm::ShuffleVectorInst::getMaskValue(), llvm::ShuffleVectorInst::getShuffleMask(), getUniqueInteger(), isZero(), ReadDataFromGlobal(), llvm::InstCombiner::visitCallInst(), llvm::InstCombiner::visitExtractValueInst(), llvm::InstCombiner::visitSRem(), and llvm::WriteConstantInternal().
Definition at line 204 of file Constants.cpp.
References getAggregateElement(), and llvm::Value::getType().
Get the all ones value.
Definition at line 163 of file Constants.cpp.
References llvm::ConstantInt::get(), llvm::ConstantFP::get(), llvm::APFloat::getAllOnesValue(), llvm::APInt::getAllOnesValue(), llvm::Type::getContext(), llvm::SequentialType::getElementType(), llvm::VectorType::getNumElements(), llvm::Type::getPrimitiveSizeInBits(), llvm::ConstantVector::getSplat(), llvm::Type::isFloatingPointTy(), and llvm::Type::isPPC_FP128Ty().
Referenced by BitCastConstantVector(), llvm::ConstantFoldBinaryInstruction(), llvm::ConstantFoldCompareInstruction(), llvm::BinaryOperator::CreateNot(), DoInitialMatch(), FoldBitCast(), llvm::InstCombiner::FoldICmpAddOpCst(), foldLogOpOfMaskedICmpsHelper(), llvm::X86InstrInfo::foldMemoryOperandImpl(), llvm::ConstantExpr::getBinOpAbsorber(), llvm::ConstantExpr::getBinOpIdentity(), llvm::ScalarEvolution::getNegativeSCEV(), llvm::ConstantExpr::getNot(), llvm::ScalarEvolution::getNotSCEV(), GetSelectFoldableConstant(), getTrue(), LLVMConstAllOnes(), LowerNegateToMultiply(), OptimizeAndOrXor(), SimplifyAddInst(), SimplifyAShrInst(), SimplifyOrInst(), SimplifyXorInst(), ThreadCmpOverSelect(), llvm::InstCombiner::visitICmpInst(), llvm::InstCombiner::visitICmpInstWithCastAndCast(), and llvm::InstCombiner::visitURem().
getIntegerValue - Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value.
Definition at line 146 of file Constants.cpp.
References llvm::CallingConv::C, llvm::ConstantInt::get(), llvm::Type::getContext(), llvm::ConstantExpr::getIntToPtr(), llvm::Type::getScalarType(), and llvm::ConstantVector::getSplat().
Definition at line 111 of file Constants.cpp.
References llvm::lltok::APFloat, llvm::Type::ArrayTyID, llvm::Type::DoubleTyID, llvm::Type::FloatTyID, llvm::Type::FP128TyID, llvm::ConstantInt::get(), llvm::ConstantFP::get(), llvm::ConstantAggregateZero::get(), llvm::ConstantPointerNull::get(), llvm::Type::getContext(), llvm::APInt::getNullValue(), llvm::Type::getTypeID(), llvm::APFloat::getZero(), llvm::Type::HalfTyID, llvm::APFloat::IEEEdouble, llvm::APFloat::IEEEhalf, llvm::APFloat::IEEEquad, llvm::APFloat::IEEEsingle, llvm::Type::IntegerTyID, llvm_unreachable, llvm::Type::PointerTyID, llvm::Type::PPC_FP128TyID, llvm::APFloat::PPCDoubleDouble, llvm::Type::StructTyID, llvm::Type::VectorTyID, llvm::Type::X86_FP80TyID, and llvm::APFloat::x87DoubleExtended.
Referenced by BitCastConstantVector(), BreakUpSubtract(), llvm::cleanseInlinedVariable(), CleanupConstantGlobalUsers(), llvm::InstCombiner::commonIDivTransforms(), ConnectProlog(), llvm::ConstantFoldBinaryInstruction(), llvm::ConstantFoldCall(), llvm::ConstantFoldCastInstruction(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldCompareInstruction(), llvm::ConstantFoldExtractElementInstruction(), llvm::ConstantFoldLoadFromConstPtr(), llvm::DIBuilder::createComplexVariable(), llvm::DIBuilder::createGlobalVariable(), llvm::IRBuilder< true, TargetFolder >::CreateIsNotNull(), llvm::IRBuilder< true, TargetFolder >::CreateIsNull(), llvm::DIBuilder::createLocalVariable(), llvm::DIBuilder::createMethod(), llvm::DIBuilder::createStaticVariable(), llvm::DIBuilder::createSubroutineType(), decomposeBitTestICmp(), llvm::EmitGEPOffset(), evaluateICmpRelation(), ExtractConstantBytes(), FoldBitCast(), llvm::InstCombiner::FoldGEPICmp(), foldLogOpOfMaskedICmps(), llvm::X86InstrInfo::foldMemoryOperandImpl(), llvm::InstCombiner::FoldShiftByConstant(), foldUDivNegCst(), llvm::ConstantExpr::getAlignOf(), llvm::ConstantExpr::getBinOpAbsorber(), llvm::ConstantExpr::getBinOpIdentity(), getFalse(), getFoldedSizeOf(), llvm::ConstantFP::getNegativeZero(), llvm::ConstantExpr::getOffsetOf(), llvm::DIBuilder::getOrCreateArray(), GetSelectFoldableConstant(), llvm::ConstantAggregateZero::getSequentialElement(), GetShiftedValue(), llvm::ConstantExpr::getSizeOf(), getSplatValue(), llvm::ConstantAggregateZero::getStructElement(), llvm::ConstantFP::getZeroValueForNegation(), InstallGlobalCtors(), InstCombineLoadCast(), InstCombineStoreToCast(), llvm::isBytewiseValue(), LLVMConstNull(), llvm::NVPTXTargetLowering::LowerFormalArguments(), llvm::IntrinsicLowering::LowerIntrinsicCall(), LowerNegateToMultiply(), LowerToTLSExecModel(), OptimizeAndOrXor(), OptimizeIntegerToVectorInsertions(), OptimizeVectorResize(), PerformHeapAllocSRoA(), RewriteHeapSROALoadUser(), SimplifyAndInst(), SimplifyAShrInst(), SimplifyDiv(), SimplifyFAddInst(), SimplifyFSubInst(), SimplifyICmpInst(), SimplifyLShrInst(), SimplifyMulInst(), SimplifyRem(), SimplifyShlInst(), SimplifySubInst(), SimplifyXorInst(), SRAGlobal(), llvm::UpgradeInstWithTBAATag(), llvm::InstCombiner::visitAllocaInst(), llvm::InstCombiner::visitAnd(), llvm::InstCombiner::visitBitCast(), llvm::InstCombiner::visitCallInst(), llvm::InstCombiner::visitFCmpInst(), llvm::InstCombiner::visitGetElementPtrInst(), llvm::InstCombiner::visitICmpInst(), llvm::InstCombiner::visitICmpInstWithInstAndIntCst(), llvm::InstCombiner::visitLandingPadInst(), llvm::InstCombiner::visitLoadInst(), llvm::InstCombiner::visitMul(), and llvm::InstCombiner::visitTrunc().
Constant::PossibleRelocationsTy Constant::getRelocationInfo | ( | ) | const |
getRelocationInfo - This method classifies the entry according to whether or not it may generate a relocation entry. This must be conservative, so if it might codegen to a relocatable entry, it should say so. The return values are:
NoRelocation: This constant pool entry is guaranteed to never have a relocation applied to it (because it holds a simple constant like '4'). LocalRelocation: This entry has relocations, but the entries are guaranteed to be resolvable by the static linker, so the dynamic linker will never see them. GlobalRelocations: This entry may have arbitrary relocations.
FIXME: This really should not be in VMCore.
getRelocationInfo - This method classifies the entry according to whether or not it may generate a relocation entry. This must be conservative, so if it might codegen to a relocatable entry, it should say so. The return values are:
NoRelocation: This constant pool entry is guaranteed to never have a relocation applied to it (because it holds a simple constant like '4'). LocalRelocation: This entry has relocations, but the entries are guaranteed to be resolvable by the static linker, so the dynamic linker will never see them. GlobalRelocations: This entry may have arbitrary relocations.
FIXME: This really should not be in IR.
Definition at line 337 of file Constants.cpp.
References llvm::dyn_cast(), llvm::User::getNumOperands(), llvm::ConstantExpr::getOpcode(), llvm::User::getOperand(), GlobalRelocations, LocalRelocation, and NoRelocation.
Referenced by llvm::TargetLoweringObjectFile::getKindForGlobal().
Constant * Constant::getSplatValue | ( | ) | const |
getSplatValue - If this is a splat vector constant, meaning that all of the elements have the same value, return that value. Otherwise return 0.
Definition at line 1276 of file Constants.cpp.
References getNullValue(), and llvm::Value::getType().
Referenced by llvm::ComputeMaskedBits(), getUniqueInteger(), llvm::CompositeType::indexValid(), and isAllOnesValue().
const APInt & Constant::getUniqueInteger | ( | ) | const |
If C is a constant integer then return its value, otherwise C must be a vector of constant integers, all equal, and the common value is returned.
Definition at line 1301 of file Constants.cpp.
References llvm::CallingConv::C, getAggregateElement(), and getSplatValue().
bool Constant::isAllOnesValue | ( | ) | const |
isAllOnesValue - Return true if this is the value that would be returned by getAllOnesValue.
Definition at line 88 of file Constants.cpp.
References getSplatValue().
Referenced by BitCastConstantVector(), ConstantFold(), llvm::ConstantFoldSelectInstruction(), decomposeBitTestICmp(), FoldBitCast(), llvm::InstCombiner::FoldICmpDivCst(), isSelect01(), isSignBitCheck(), and isSignTest().
bool Constant::isConstantUsed | ( | ) | const |
isConstantUsed - Return true if the constant has users other than constant exprs and other dangling things.
Definition at line 309 of file Constants.cpp.
References llvm::dyn_cast(), isConstantUsed(), llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by isConstantUsed().
bool Constant::isNegativeZeroValue | ( | ) | const |
isNegativeZeroValue - Return true if the value is what would be returned by getZeroValueForNegation.
Definition at line 45 of file Constants.cpp.
References llvm::Value::getType(), llvm::Type::isFPOrFPVectorTy(), and isNullValue().
Referenced by llvm::InstCombiner::visitFAdd().
bool Constant::isNullValue | ( | ) | const |
isNullValue - Return true if this is the value that would be returned by getNullValue.
Definition at line 75 of file Constants.cpp.
Referenced by BitCastConstantVector(), computePointerICmp(), ConstantFold(), llvm::ConstantFoldCastInstruction(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldCompareInstruction(), llvm::ConstantFoldExtractElementInstruction(), ConstantFoldGetElementPtrImpl(), llvm::ConstantFoldSelectInstruction(), evaluateICmpRelation(), ExtractConstantBytes(), FindScalarElement(), FoldBitCast(), llvm::ConstantArray::get(), llvm::ConstantStruct::get(), llvm::ConstantVector::get(), llvm::getConstantStringInfo(), llvm::LazyValueInfo::getPredicateOnEdge(), isCatchAll(), isNegativeZeroValue(), IsOnlyUsedInZeroEqualityComparison(), isSuitableForBSS(), isZeroValue(), nvptx::LowerConstant(), lowerConstant(), OptimizeOnceStoredGlobal(), ParseGlobalCtors(), passingValueIsAlwaysUndefined(), llvm::ConstantArray::replaceUsesOfWithOnConstant(), llvm::ConstantStruct::replaceUsesOfWithOnConstant(), llvm::ExecutionEngine::runStaticConstructorsDestructors(), TryToShrinkGlobalToBoolean(), TurnSwitchRangeIntoICmp(), llvm::InstCombiner::visitICmpInstWithInstAndIntCst(), and WriteConstants().
bool Constant::isThreadDependent | ( | ) | const |
isThreadDependent - Return true if the value can vary between threads.
Definition at line 281 of file Constants.cpp.
References llvm::CallingConv::C, llvm::dyn_cast(), llvm::SmallVectorBase::empty(), llvm::User::getNumOperands(), llvm::User::getOperand(), I, llvm::SmallPtrSet< PtrType, SmallSize >::insert(), llvm::SmallVectorImpl< T >::pop_back_val(), and llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back().
bool Constant::isZeroValue | ( | ) | const |
Return true if the value is negative zero or null value.
Definition at line 66 of file Constants.cpp.
References isNullValue().
Referenced by llvm::ComputeMaskedBits(), and isZero().
void Constant::removeDeadConstantUsers | ( | ) | const |
removeDeadConstantUsers - If there are any dead constant users dangling off of this constant, remove them. This method is useful for clients that want to check to see if a global is unused, but don't want to deal with potentially dead constants hanging off of the globals.
Definition at line 395 of file Constants.cpp.
References llvm::dyn_cast(), I, removeDeadUsersOfConstant(), llvm::Value::use_begin(), and llvm::Value::use_end().
Referenced by AddressIsTaken(), hasAddressTakenAndUsed(), INITIALIZE_PASS(), llvm::Inliner::removeDeadFunctions(), and llvm::GlobalValue::~GlobalValue().
|
inlinevirtual |
replaceUsesOfWithOnConstant - This method is a special form of User::replaceUsesOfWith (which does not work on constants) that does work on constants. Basically this method goes through the trouble of building a new constant that is equivalent to the current one, with all uses of From replaced with uses of To. After this construction is completed, all of the users of 'this' are replaced to use the new constant, and then 'this' is deleted. In general, you should not call this method, instead, use Value::replaceAllUsesWith, which automatically dispatches to this method as needed.
Reimplemented in llvm::ConstantExpr, llvm::BlockAddress, llvm::ConstantVector, llvm::ConstantStruct, llvm::ConstantArray, and llvm::GlobalVariable.
Definition at line 140 of file Constant.h.
References llvm::User::getNumOperands(), and llvm_unreachable.