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 Member Functions

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

Static Public Member Functions

static Constant * getNullValue (const Type *Ty)
static Constant * getAllOnesValue (const Type *Ty)
static bool classof (const Constant *)
static bool classof (const GlobalValue *)
static bool classof (const Value *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 39 of file Constant.h.


Constructor & Destructor Documentation

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

Definition at line 43 of file Constant.h.


Member Function Documentation

void Constant::destroyConstantImpl (  )  [protected]

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

Static constructor to get a '0' constant of arbitrary type...

Definition at line 105 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::getTypeID(), llvm::Type::IntegerTyID, llvm::Type::PointerTyID, llvm::Type::PPC_FP128TyID, llvm::Type::StructTyID, llvm::Type::VectorTyID, and llvm::Type::X86_FP80TyID.

Referenced by llvm::ConstantFoldBinaryInstruction(), llvm::ConstantFoldCall(), llvm::ConstantFoldCastInstruction(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldCompareInstruction(), llvm::ConstantFoldExtractElementInstruction(), llvm::ConstantFoldExtractValueInstruction(), llvm::ConstantFoldInsertElementInstruction(), llvm::ConstantFoldInsertValueInstruction(), llvm::ConstantFoldLoadThroughGEPConstantExpr(), llvm::IRBuilder< preserveNames, T >::CreateIsNotNull(), llvm::IRBuilder< preserveNames, T >::CreateIsNull(), evaluateICmpRelation(), EvalVectorOp(), llvm::FindInsertedValue(), llvm::X86InstrInfo::foldMemoryOperandImpl(), getAggregateConstantElement(), llvm::ScalarEvolution::getIntegerSCEV(), llvm::ConstantFP::getNegativeZero(), llvm::FastISel::getRegForValue(), llvm::ConstantExpr::getSizeOf(), GetVectorElement(), getVectorElements(), llvm::ConstantExpr::getZeroValueForNegationExpr(), llvm::RSProfilers_std::IncrementCounterInBlock(), llvm::IncrementCounterInBlock(), llvm::InsertProfilingInitCall(), llvm::ConstantArray::isCString(), llvm::IntrinsicLowering::LowerIntrinsicCall(), OptimizeGlobalAddressOfMalloc(), PerformHeapAllocSRoA(), llvm::RemoveSuccessor(), RewriteHeapSROALoadUser(), SRAGlobal(), llvm::SCEVExpander::visitAddRecExpr(), and llvm::SCEVExpander::visitMulExpr().

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

Static constructor to get a '-1' constant. This supports integers and vectors.

Reimplemented in llvm::ConstantInt.

Definition at line 133 of file Constants.cpp.

References llvm::ConstantInt::get(), llvm::ConstantVector::getAllOnesValue(), and llvm::APInt::getAllOnesValue().

Referenced by llvm::ConstantFoldCompareInstruction(), and llvm::ConstantExpr::getNot().

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

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

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

Referenced by canTrap().

bool Constant::ContainsRelocations (  )  const

ContaintsRelocations - Return true if the constant value contains relocations which cannot be resolved at compile time.

ContaintsRelocations - Return true if the constant value contains relocations which cannot be resolved at compile time.

Definition at line 95 of file Constants.cpp.

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

Referenced by llvm::TargetAsmInfo::SectionKindForGlobal().

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

Definition at line 71 of file Constant.h.

References llvm::User::getOperand().

Referenced by llvm::AddCatchInfo(), AnalyzeGlobal(), llvm::MachineModuleInfo::AnalyzeModule(), BitCastConstantVector(), canTrap(), CheapToScalarize(), CommitValueTo(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldExtractElementInstruction(), llvm::ConstantFoldExtractValueInstruction(), llvm::ConstantFoldInsertValueInstruction(), llvm::ConstantFoldLoadThroughGEPConstantExpr(), ContainsRelocations(), llvm::ConvertConstantType< ConstantExpr, Type >::convert(), llvm::ConvertConstantType< ConstantVector, VectorType >::convert(), llvm::ConvertConstantType< ConstantStruct, StructType >::convert(), llvm::ConvertConstantType< ConstantArray, ArrayType >::convert(), llvm::AsmPrinter::EmitConstantValueOnly(), llvm::X86IntelAsmPrinter::EmitString(), llvm::AsmPrinter::EmitString(), evaluateICmpRelation(), EvaluateStoreInto(), EvalVectorOp(), FindScalarElement(), FindStaticTors(), foldConstantCastPair(), getAggregateConstantElement(), llvm::GlobalAlias::getAliasedGlobal(), llvm::GlobalAlias::getAliasee(), llvm::ConstantArray::getAsString(), llvm::LoopBase< BlockT >::getCanonicalInductionVariable(), getCommonReturnValue(), llvm::GetConstantStringInfo(), llvm::DIDescriptor::getDescriptorField(), llvm::DbgStopPointInst::getDirectory(), llvm::DbgStopPointInst::getFileName(), llvm::DIDescriptor::getGlobalVariableField(), llvm::ShuffleVectorInst::getMaskValue(), llvm::ScalarEvolution::getMulExpr(), 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(), 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 74 of file Constant.h.

References llvm::User::getOperand().

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

void Constant::getVectorElements ( 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 162 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(), llvm::ConstantExpr::getVFCmp(), and llvm::ConstantExpr::getVICmp().

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 94 of file Constant.h.

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

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

Definition at line 97 of file Constant.h.

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

Reimplemented in llvm::GlobalValue.

Definition at line 98 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 114 of file Constant.h.

References llvm::User::getNumOperands().


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