LLVM API Documentation
LLVM Constant Representation. More...
#include <Constant.h>
Public Types | |
enum | PossibleRelocationsTy { NoRelocation = 0, LocalRelocation = 1, GlobalRelocations = 2 } |
Public Member Functions | |
bool | isNullValue () const |
bool | isOneValue () const |
Returns true if the value is one. | |
bool | isAllOnesValue () const |
bool | isNegativeZeroValue () const |
bool | isZeroValue () const |
Return true if the value is negative zero or null value. | |
bool | isNotMinSignedValue () const |
Return true if the value is not the smallest signed value. | |
bool | isMinSignedValue () const |
Return true if the value is the smallest signed value. | |
bool | canTrap () const |
bool | isThreadDependent () const |
isThreadDependent - Return true if the value can vary between threads. | |
bool | isDLLImportDependent () const |
Return true if the value is dependent on a dllimport variable. | |
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 |
Constant * | stripPointerCasts () |
Strips off any unneeded pointer casts, all-zero GEPs and aliases from the specified value, returning the original uncasted value. | |
const Constant * | stripPointerCasts () const |
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. | |
static Constant * | getIntegerValue (Type *Ty, const APInt &V) |
Protected Member Functions | |
Constant (Type *ty, ValueTy vty, Use *Ops, unsigned NumOps) | |
void | destroyConstantImpl () |
void | replaceUsesOfWithOnConstantImpl (Constant *Replacement) |
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.
Definition at line 92 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 343 of file Constants.cpp.
References canTrapImpl().
Referenced by SplitCriticalSideEffectEdges().
static bool llvm::Constant::classof | ( | const Value * | V | ) | [inline, static] |
Reimplemented from llvm::User.
Reimplemented in llvm::UndefValue, llvm::ConstantExpr, llvm::BlockAddress, llvm::ConstantDataVector, llvm::ConstantDataArray, llvm::ConstantDataSequential, llvm::ConstantPointerNull, llvm::ConstantVector, llvm::Function, llvm::ConstantStruct, llvm::ConstantArray, llvm::GlobalValue, llvm::ConstantAggregateZero, llvm::ConstantFP, llvm::ConstantInt, llvm::GlobalVariable, llvm::GlobalAlias, and llvm::GlobalObject.
Definition at line 139 of file Constant.h.
References llvm::Value::ConstantFirstVal, llvm::Value::ConstantLastVal, and llvm::Value::getValueID().
virtual void llvm::Constant::destroyConstant | ( | ) | [inline, virtual] |
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::GlobalValue, and llvm::ConstantAggregateZero.
Definition at line 136 of file Constant.h.
References llvm_unreachable.
Referenced by destroyConstantImpl(), RemoveDeadConstant(), replaceUsesOfWithOnConstantImpl(), and llvm::BitcodeReaderValueList::ResolveConstantForwardRefs().
void Constant::destroyConstantImpl | ( | ) | [protected] |
Definition at line 280 of file Constants.cpp.
References llvm::dbgs(), destroyConstant(), llvm::Value::use_empty(), and llvm::Value::user_back().
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().
Constant * Constant::getAggregateElement | ( | unsigned | Elt | ) | const |
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 250 of file Constants.cpp.
Referenced by llvm::ConstantFoldExtractElementInstruction(), llvm::ConstantFoldExtractValueInstruction(), llvm::ConstantFoldInsertValueInstruction(), ConstantFoldLoadThroughBitcast(), llvm::ConstantFoldLoadThroughGEPConstantExpr(), llvm::ConstantFoldLoadThroughGEPIndices(), ConstantFoldScalarCall(), EvaluateStoreInto(), FindScalarElement(), FoldBitCast(), llvm::InstCombiner::FoldCmpLoadFromIndexedGlobal(), getAggregateElement(), getArrayElements(), llvm::ShuffleVectorInst::getMaskValue(), llvm::ShuffleVectorInst::getShuffleMask(), getUniqueInteger(), isFiniteNonZeroFp(), isNormalFp(), isUndefShift(), isZero(), ReadDataFromGlobal(), llvm::InstCombiner::visitCallInst(), llvm::InstCombiner::visitExtractValueInst(), llvm::InstCombiner::visitSRem(), and llvm::WriteConstantInternal().
Constant * Constant::getAggregateElement | ( | Constant * | Elt | ) | const |
Definition at line 272 of file Constants.cpp.
References getAggregateElement(), and llvm::Value::getType().
Constant * Constant::getAllOnesValue | ( | Type * | Ty | ) | [static] |
Get the all ones value.
Definition at line 230 of file Constants.cpp.
References llvm::ConstantInt::get(), llvm::ConstantFP::get(), 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::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().
Constant * Constant::getIntegerValue | ( | Type * | Ty, |
const APInt & | V | ||
) | [static] |
getIntegerValue - Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value.
Definition at line 213 of file Constants.cpp.
References llvm::CallingConv::C, llvm::ConstantInt::get(), llvm::Type::getContext(), llvm::ConstantExpr::getIntToPtr(), llvm::Type::getScalarType(), and llvm::ConstantVector::getSplat().
Referenced by llvm::InstCombiner::visitReturnInst().
Constant * Constant::getNullValue | ( | Type * | Ty | ) | [static] |
Definition at line 178 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 appendToGlobalArray(), BitCastConstantVector(), BreakUpSubtract(), calculateVectorIndex(), llvm::cleanseInlinedVariable(), CleanupConstantGlobalUsers(), llvm::InstCombiner::commonIDivTransforms(), ConnectProlog(), llvm::ConstantFoldBinaryInstruction(), llvm::ConstantFoldCastInstruction(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldCompareInstruction(), llvm::ConstantFoldExtractElementInstruction(), llvm::ConstantFoldLoadFromConstPtr(), ConstantFoldScalarCall(), llvm::DIBuilder::createComplexVariable(), llvm::DIBuilder::createGlobalVariable(), llvm::IRBuilder< true, TargetFolder >::CreateIsNotNull(), llvm::IRBuilder< true, TargetFolder >::CreateIsNull(), llvm::DIBuilder::createLocalVariable(), llvm::DIBuilder::createMethod(), createStaticVariableHelper(), llvm::DIBuilder::createSubroutineType(), decomposeBitTestICmp(), llvm::EmitGEPOffset(), evaluateICmpRelation(), ExtractConstantBytes(), FoldBitCast(), llvm::InstCombiner::FoldGEPICmp(), llvm::InstCombiner::FoldICmpCstShrCst(), foldLogOpOfMaskedICmps(), llvm::InstCombiner::FoldShiftByConstant(), foldUDivNegCst(), llvm::ConstantExpr::getAlignOf(), llvm::ConstantExpr::getBinOpAbsorber(), llvm::ConstantExpr::getBinOpIdentity(), getFalse(), getFoldedSizeOf(), llvm::ConstantExpr::getOffsetOf(), GetSelectFoldableConstant(), llvm::ConstantAggregateZero::getSequentialElement(), GetShiftedValue(), llvm::ConstantExpr::getSizeOf(), getSplatValue(), llvm::ConstantAggregateZero::getStructElement(), llvm::ConstantFP::getZeroValueForNegation(), InstCombineLoadCast(), InstCombineStoreToCast(), llvm::isBytewiseValue(), LLVMConstNull(), llvm::NVPTXTargetLowering::LowerFormalArguments(), llvm::IntrinsicLowering::LowerIntrinsicCall(), LowerNegateToMultiply(), OptimizeAndOrXor(), OptimizeIntegerToVectorInsertions(), OptimizeVectorResize(), PerformHeapAllocSRoA(), RewriteHeapSROALoadUser(), SimplifyAndInst(), SimplifyAShrInst(), SimplifyDiv(), SimplifyFAddInst(), SimplifyFSubInst(), SimplifyGEPInst(), SimplifyICmpInst(), SimplifyLShrInst(), SimplifyMulInst(), SimplifyRem(), SimplifyShlInst(), SimplifySubInst(), SimplifyXorInst(), SRAGlobal(), upgradeGlobalArray(), 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().
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 418 of file Constants.cpp.
References llvm::WinEH::CE, 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.
Reimplemented in llvm::ConstantDataVector, and llvm::ConstantVector.
Definition at line 1375 of file Constants.cpp.
References getNullValue(), and llvm::Value::getType().
Referenced by computeKnownBits(), getUniqueInteger(), llvm::CompositeType::indexValid(), isAllOnesValue(), isMinSignedValue(), isNotMinSignedValue(), and isOneValue().
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 1400 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.
Return true if the constant has users other than constant exprs and other dangling things.
Definition at line 390 of file Constants.cpp.
References llvm::dyn_cast(), isConstantUsed(), and llvm::Value::users().
Referenced by isConstantUsed().
bool Constant::isDLLImportDependent | ( | ) | const |
Return true if the value is dependent on a dllimport variable.
Definition at line 381 of file Constants.cpp.
References ConstHasGlobalValuePredicate().
Referenced by ValidLookupTableConstant().
bool Constant::isMinSignedValue | ( | ) | const |
Return true if the value is the smallest signed value.
Definition at line 132 of file Constants.cpp.
References getSplatValue().
Referenced by SimplifyICmpInst().
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::isNotMinSignedValue | ( | ) | const |
Return true if the value is not the smallest signed value.
Definition at line 154 of file Constants.cpp.
References getSplatValue().
Referenced by llvm::InstCombiner::visitSub().
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(), canFoldZeroCheckIntoBranch(), computePointerICmp(), ConstantFold(), llvm::ConstantFoldCastInstruction(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldCompareInstruction(), llvm::ConstantFoldExtractElementInstruction(), ConstantFoldGetElementPtrImpl(), llvm::ConstantFoldSelectInstruction(), evaluateICmpRelation(), ExtractConstantBytes(), FindScalarElement(), FoldBitCast(), llvm::ConstantStruct::get(), llvm::getConstantStringInfo(), getPredicateResult(), isCatchAll(), isNegativeZeroValue(), IsOnlyUsedInZeroEqualityComparison(), isSuitableForBSS(), isZeroValue(), nvptx::LowerConstant(), lowerConstant(), OptimizeOnceStoredGlobal(), passingValueIsAlwaysUndefined(), llvm::ConstantArray::replaceUsesOfWithOnConstant(), llvm::ConstantStruct::replaceUsesOfWithOnConstant(), llvm::ExecutionEngine::runStaticConstructorsDestructors(), TryToShrinkGlobalToBoolean(), TurnSwitchRangeIntoICmp(), llvm::InstCombiner::visitICmpInstWithInstAndIntCst(), and WriteConstants().
bool Constant::isOneValue | ( | ) | const |
Returns true if the value is one.
Definition at line 110 of file Constants.cpp.
References getSplatValue().
Referenced by llvm::InstCombiner::visitSub().
bool Constant::isThreadDependent | ( | ) | const |
isThreadDependent - Return true if the value can vary between threads.
Return true if the value can vary between threads.
Definition at line 374 of file Constants.cpp.
References ConstHasGlobalValuePredicate().
Referenced by ValidLookupTableConstant().
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 computeKnownBits(), isZero(), and shouldConvert().
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 476 of file Constants.cpp.
References llvm::dyn_cast(), I, removeDeadUsersOfConstant(), llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by AddressIsTaken(), hasAddressTakenAndUsed(), llvm::Inliner::removeDeadFunctions(), and llvm::GlobalValue::~GlobalValue().
virtual void llvm::Constant::replaceUsesOfWithOnConstant | ( | Value * | , |
Value * | , | ||
Use * | |||
) | [inline, virtual] |
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 154 of file Constant.h.
References llvm::User::getNumOperands(), and llvm_unreachable.
void Constant::replaceUsesOfWithOnConstantImpl | ( | Constant * | Replacement | ) | [protected] |
replaceUsesOfWithOnConstant - Update this constant array to change uses of 'From' to be uses of 'To'. This must update the uniquing data structures etc.
Note that we intentionally replace all uses of From with To here. Consider a large array that uses 'From' 1000 times. By handling this case all here, ConstantArray::replaceUsesOfWithOnConstant is only invoked once, and that single invocation handles all 1000 uses. Handling them one at a time would work, but would be really slow because it would have to unique each updated array instance.
Definition at line 2743 of file Constants.cpp.
References destroyConstant(), and llvm::Value::replaceAllUsesWith().
Referenced by llvm::ConstantArray::replaceUsesOfWithOnConstant(), llvm::ConstantStruct::replaceUsesOfWithOnConstant(), llvm::ConstantVector::replaceUsesOfWithOnConstant(), llvm::BlockAddress::replaceUsesOfWithOnConstant(), and llvm::ConstantExpr::replaceUsesOfWithOnConstant().
Constant* llvm::Constant::stripPointerCasts | ( | ) | [inline] |
Strips off any unneeded pointer casts, all-zero GEPs and aliases from the specified value, returning the original uncasted value.
If this is called on a non-pointer value, it returns 'this'.
Reimplemented from llvm::Value.
Definition at line 181 of file Constant.h.
Referenced by llvm::EmitFPutS(), llvm::EmitFWrite(), llvm::EmitStrChr(), llvm::EmitStrLen(), llvm::EmitStrNLen(), llvm::ARMAsmPrinter::EmitXXStructor(), hasUsesToReplace(), stripPointerCasts(), StripPtrCastKeepAS(), and llvm::InstCombiner::visitLandingPadInst().
const Constant* llvm::Constant::stripPointerCasts | ( | ) | const [inline] |
Reimplemented from llvm::Value.
Definition at line 185 of file Constant.h.
References stripPointerCasts().