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 isAllOnesValue () const
bool isNegativeZeroValue () const
bool isZeroValue () const
 Return true if the value is negative zero or null value.
bool canTrap () const
bool isThreadDependent () const
 isThreadDependent - Return true if the value can vary between threads.
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

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

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 78 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 276 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::ConstantAggregateZero, and llvm::GlobalValue.

Definition at line 122 of file Constant.h.

References llvm_unreachable.

Referenced by destroyConstantImpl(), RemoveDeadConstant(), and llvm::BitcodeReaderValueList::ResolveConstantForwardRefs().

void Constant::destroyConstantImpl ( ) [protected]

Definition at line 205 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 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().

Constant * Constant::getNullValue ( Type Ty) [static]

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::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(), llvm::DIBuilder::createStaticVariable(), llvm::DIBuilder::createSubroutineType(), decomposeBitTestICmp(), llvm::EmitGEPOffset(), evaluateICmpRelation(), ExtractConstantBytes(), FoldBitCast(), llvm::InstCombiner::FoldGEPICmp(), 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(), InstallGlobalCtors(), InstCombineLoadCast(), InstCombineStoreToCast(), llvm::isBytewiseValue(), LLVMConstNull(), llvm::NVPTXTargetLowering::LowerFormalArguments(), llvm::IntrinsicLowering::LowerIntrinsicCall(), LowerNegateToMultiply(), 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().

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

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

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

Referenced by llvm::ComputeMaskedBits(), getUniqueInteger(), llvm::CompositeType::indexValid(), and isAllOnesValue().

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 1304 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.

Definition at line 310 of file Constants.cpp.

References llvm::dyn_cast(), isConstantUsed(), and llvm::Value::users().

Referenced by isConstantUsed().

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 negative zero or null value.

Definition at line 66 of file Constants.cpp.

References isNullValue().

Referenced by llvm::ComputeMaskedBits(), 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 396 of file Constants.cpp.

References llvm::dyn_cast(), I, removeDeadUsersOfConstant(), llvm::Value::user_begin(), and llvm::Value::user_end().

Referenced by AddressIsTaken(), hasAddressTakenAndUsed(), INITIALIZE_PASS(), 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 140 of file Constant.h.

References llvm::User::getNumOperands(), and llvm_unreachable.


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