LLVM API Documentation

llvm::Constant Class Reference

LLVM Constant Representation. More...

#include <Constant.h>

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

List of all members.

Public Types

enum  PossibleRelocationsTy { NoRelocation = 0, LocalRelocation = 1, GlobalRelocations = 2 }

Public Member Functions

virtual bool isNullValue () const =0
virtual bool isNegativeZeroValue () const
bool canTrap () const
PossibleRelocationsTy getRelocationInfo () const
Constant * getOperand (unsigned i)
const Constant * getOperand (unsigned i) const
void setOperand (unsigned i, Constant *C)
void getVectorElements (LLVMContext &Context, SmallVectorImpl< Constant * > &Elts) const
virtual void destroyConstant ()
virtual void replaceUsesOfWithOnConstant (Value *, Value *, Use *)

Static Public Member Functions

static bool classof (const Constant *)
static bool classof (const GlobalValue *)
static bool classof (const Value *V)
static Constant * getNullValue (const Type *Ty)
static Constant * getAllOnesValue (const Type *Ty)
 Get the all ones value.
static Constant * getIntegerValue (const Type *Ty, const APInt &V)

Protected Member Functions

 Constant (const 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 42 of file Constant.h.


Member Enumeration Documentation

Enumerator:
NoRelocation 
LocalRelocation 
GlobalRelocations 

Definition at line 64 of file Constant.h.


Constructor & Destructor Documentation

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

Definition at line 47 of file Constant.h.


Member Function Documentation

void Constant::destroyConstantImpl (  )  [protected]

virtual bool llvm::Constant::isNullValue (  )  const [pure virtual]

virtual bool llvm::Constant::isNegativeZeroValue (  )  const [inline, virtual]

isNegativeZeroValue - Return true if the value is what would be returned by getZeroValueForNegation.

Reimplemented in llvm::ConstantFP.

Definition at line 58 of file Constant.h.

References isNullValue().

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.

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

References canTrap(), llvm::dyn_cast(), llvm::User::getNumOperands(), llvm::ConstantExpr::getOpcode(), getOperand(), llvm::Value::getType(), and isNullValue().

Referenced by canTrap().

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

Definition at line 175 of file Constants.cpp.

References llvm::User::getNumOperands(), getOperand(), getRelocationInfo(), GlobalRelocations, GV, llvm::GlobalValue::hasHiddenVisibility(), llvm::GlobalValue::hasLocalLinkage(), LocalRelocation, and NoRelocation.

Referenced by llvm::TargetLoweringObjectFile::getKindForGlobal(), and getRelocationInfo().

Constant* llvm::Constant::getOperand ( unsigned  i  )  [inline]

Definition at line 88 of file Constant.h.

References llvm::User::getOperand().

Referenced by llvm::AddCatchInfo(), AnalyzeGlobal(), llvm::MachineModuleInfo::AnalyzeModule(), BitCastConstantVector(), canTrap(), CheapToScalarize(), CommitValueTo(), llvm::ConstantFoldBinaryInstruction(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldExtractElementInstruction(), llvm::ConstantFoldExtractValueInstruction(), llvm::ConstantFoldInsertValueInstruction(), llvm::ConstantFoldLoadThroughGEPConstantExpr(), llvm::ConvertConstant< ConstantStruct, StructType >::convert(), llvm::ConvertConstant< ConstantArray, ArrayType >::convert(), llvm::ConvertConstant< ConstantVector, VectorType >::convert(), llvm::ConvertConstant< ConstantExpr, Type >::convert(), llvm::X86IntelAsmPrinter::EmitString(), llvm::AsmPrinter::EmitString(), evaluateICmpRelation(), EvaluateStoreInto(), FindScalarElement(), FindStaticTors(), findUsedValues(), foldConstantCastPair(), getAggregateConstantElement(), llvm::GlobalAlias::getAliasedGlobal(), llvm::GlobalAlias::getAliasee(), llvm::ConstantArray::getAsString(), getCommonReturnValue(), llvm::GetConstantStringInfo(), llvm::DIDescriptor::getDescriptorField(), llvm::DbgStopPointInst::getDirectory(), llvm::DbgStopPointInst::getFileName(), llvm::DIDescriptor::getGlobalVariableField(), llvm::ShuffleVectorInst::getMaskValue(), getRelocationInfo(), llvm::ConstantVector::getSplatValue(), llvm::DIDescriptor::getStringField(), GetStringLengthH(), llvm::DIDescriptor::getUInt64Field(), getValType(), llvm::SelectionDAGLowering::getValue(), GetVectorElement(), llvm::ConstantExpr::getWithOperandReplaced(), llvm::ConstantExpr::getWithOperands(), llvm::ExecutionEngine::InitializeMemory(), llvm::MachOWriter::InitMem(), InstCombineLoadCast(), llvm::ConstantVector::isAllOnesValue(), IsConstantOffsetFromGlobal(), llvm::ConstantArray::isCString(), llvm::ConstantArray::isString(), ParseGlobalCtors(), printAsCString(), llvm::MSILWriter::printConstantExpr(), llvm::MSILWriter::printStaticConstant(), RemapOperand(), RemoveDeadConstant(), llvm::GlobalVariable::replaceUsesOfWithOnConstant(), llvm::ConstantExpr::replaceUsesOfWithOnConstant(), llvm::ConstantVector::replaceUsesOfWithOnConstant(), llvm::ConstantStruct::replaceUsesOfWithOnConstant(), llvm::ConstantArray::replaceUsesOfWithOnConstant(), llvm::ExecutionEngine::runStaticConstructorsDestructors(), WriteConstantInt(), and WriteConstants().

const Constant* llvm::Constant::getOperand ( unsigned  i  )  const [inline]

Reimplemented from llvm::User.

Definition at line 91 of file Constant.h.

References llvm::User::getOperand().

void llvm::Constant::setOperand ( unsigned  i,
Constant *  C 
) [inline]

void Constant::getVectorElements ( LLVMContext &  Context,
SmallVectorImpl< Constant * > &  Elts 
) const

getVectorElements - This method, which is only valid on constant of vector type, returns the elements of the vector in the specified smallvector. This handles breaking down a vector undef into undef elements, etc. For constant exprs and other cases we can't handle, we return an empty vector.

getVectorElements - This method, which is only valid on constant of vector type, returns the elements of the vector in the specified smallvector. This handles breaking down a vector undef into undef elements, etc. For constant exprs and other cases we can't handle, we return an empty vector.

Definition at line 194 of file Constants.cpp.

References llvm::SmallVectorImpl< T >::assign(), llvm::UndefValue::get(), llvm::SequentialType::getElementType(), getNullValue(), llvm::VectorType::getNumElements(), llvm::Value::getType(), llvm::SmallVectorImpl< T >::push_back(), and VT.

Referenced by llvm::ConstantFoldCompareInstruction().

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::ConstantAggregateZero, llvm::ConstantArray, llvm::ConstantStruct, llvm::ConstantVector, llvm::ConstantPointerNull, llvm::ConstantExpr, llvm::UndefValue, and llvm::GlobalValue.

Definition at line 112 of file Constant.h.

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

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

Definition at line 115 of file Constant.h.

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

Reimplemented in llvm::GlobalValue.

Definition at line 116 of file Constant.h.

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

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::ConstantArray, llvm::ConstantStruct, llvm::ConstantVector, llvm::ConstantExpr, and llvm::GlobalVariable.

Definition at line 132 of file Constant.h.

References llvm::User::getNumOperands().

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

Definition at line 45 of file Constants.cpp.

References llvm::lltok::APFloat, llvm::Type::ArrayTyID, llvm::Type::DoubleTyID, llvm::Type::FloatTyID, llvm::Type::FP128TyID, llvm::ConstantAggregateZero::get(), llvm::ConstantPointerNull::get(), llvm::ConstantFP::get(), llvm::ConstantInt::get(), llvm::Type::getContext(), llvm::Type::getTypeID(), llvm::Type::IntegerTyID, llvm::Type::PointerTyID, llvm::Type::PPC_FP128TyID, llvm::Type::StructTyID, llvm::Type::VectorTyID, llvm::Type::X86_FP80TyID, and zero.

Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::ConstantFoldCall(), llvm::ConstantFoldCastInstruction(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldCompareInstruction(), llvm::ConstantFoldExtractElementInstruction(), llvm::ConstantFoldExtractValueInstruction(), llvm::ConstantFoldInsertElementInstruction(), llvm::ConstantFoldInsertValueInstruction(), llvm::ConstantFoldInstOperands(), llvm::ConstantFoldLoadThroughGEPConstantExpr(), llvm::DIFactory::CreateCompileUnit(), llvm::DIFactory::CreateGlobalVariable(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateIsNotNull(), llvm::IRBuilder< true, llvm::TargetFolder >::CreateIsNull(), llvm::DIFactory::CreateSubprogram(), evaluateICmpRelation(), llvm::FindInsertedValue(), llvm::X86InstrInfo::foldMemoryOperandImpl(), GetAddressedElementFromGlobal(), getAggregateConstantElement(), llvm::ConstantExpr::getAlignOf(), llvm::ConstantFP::getNegativeZero(), llvm::ConstantExpr::getOffsetOf(), llvm::FastISel::getRegForValue(), llvm::ConstantExpr::getSizeOf(), GetVectorElement(), getVectorElements(), llvm::ConstantFP::getZeroValueForNegation(), llvm::RSProfilers_std::IncrementCounterInBlock(), llvm::IncrementCounterInBlock(), llvm::InsertProfilingInitCall(), llvm::IntrinsicLowering::LowerIntrinsicCall(), OptimizeGlobalAddressOfMalloc(), PerformHeapAllocSRoA(), llvm::RemoveSuccessor(), RewriteHeapSROALoadUser(), and SRAGlobal().

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

Constant * Constant::getIntegerValue ( const 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 73 of file Constants.cpp.

References llvm::CallingConv::C, llvm::ConstantInt::get(), llvm::ConstantVector::get(), llvm::Type::getContext(), llvm::ConstantExpr::getIntToPtr(), and llvm::Type::getScalarType().


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