LLVM API Documentation

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
llvm::Constant Class Reference

LLVM Constant Representation. More...

#include <Constant.h>

Inheritance diagram for llvm::Constant:
Inheritance graph
[legend]
Collaboration diagram for llvm::Constant:
Collaboration graph
[legend]

List of all members.

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
ConstantgetAggregateElement (unsigned Elt) const
ConstantgetAggregateElement (Constant *Elt) const
ConstantgetSplatValue () const
const APIntgetUniqueInteger () const
virtual void destroyConstant ()
virtual void replaceUsesOfWithOnConstant (Value *, Value *, Use *)
void removeDeadConstantUsers () const
ConstantstripPointerCasts ()
 Strips off any unneeded pointer casts, all-zero GEPs and aliases from the specified value, returning the original uncasted value.
const ConstantstripPointerCasts () const

Static Public Member Functions

static bool classof (const Value *V)
static ConstantgetNullValue (Type *Ty)
static ConstantgetAllOnesValue (Type *Ty)
 Get the all ones value.
static ConstantgetIntegerValue (Type *Ty, const APInt &V)

Protected Member Functions

 Constant (Type *ty, ValueTy vty, Use *Ops, unsigned NumOps)
void destroyConstantImpl ()
void replaceUsesOfWithOnConstantImpl (Constant *Replacement)

Detailed Description

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.


Member Enumeration Documentation

Enumerator:
NoRelocation 
LocalRelocation 
GlobalRelocations 

Definition at line 92 of file Constant.h.


Constructor & Destructor Documentation

llvm::Constant::Constant ( Type ty,
ValueTy  vty,
Use Ops,
unsigned  NumOps 
) [inline, protected]

Definition at line 47 of file Constant.h.


Member Function Documentation

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

References getAggregateElement(), and llvm::Value::getType().

Constant * Constant::getAllOnesValue ( Type Ty) [static]
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().

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().

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().

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().

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().

Return true if the value is dependent on a dllimport variable.

Definition at line 381 of file Constants.cpp.

References ConstHasGlobalValuePredicate().

Referenced by ValidLookupTableConstant().

Return true if the value is the smallest signed value.

Definition at line 132 of file Constants.cpp.

References getSplatValue().

Referenced by SimplifyICmpInst().

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().

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().

Returns true if the value is one.

Definition at line 110 of file Constants.cpp.

References getSplatValue().

Referenced by llvm::InstCombiner::visitSub().

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().

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().

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().

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().

Reimplemented from llvm::Value.

Definition at line 185 of file Constant.h.

References stripPointerCasts().


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