LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
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]

Public Types

enum  PossibleRelocationsTy { NoRelocation = 0, LocalRelocation = 1, GlobalRelocations = 2 }
 
- Public Types inherited from llvm::User
typedef Useop_iterator
 
typedef const Useconst_op_iterator
 
- Public Types inherited from llvm::Value
enum  ValueTy {
  ArgumentVal, BasicBlockVal, FunctionVal, GlobalAliasVal,
  GlobalVariableVal, UndefValueVal, BlockAddressVal, ConstantExprVal,
  ConstantAggregateZeroVal, ConstantDataArrayVal, ConstantDataVectorVal, ConstantIntVal,
  ConstantFPVal, ConstantArrayVal, ConstantStructVal, ConstantVectorVal,
  ConstantPointerNullVal, MDNodeVal, MDStringVal, InlineAsmVal,
  PseudoSourceValueVal, FixedStackPseudoSourceValueVal, InstructionVal, ConstantFirstVal = FunctionVal,
  ConstantLastVal = ConstantPointerNullVal
}
 
typedef value_use_iterator< Useruse_iterator
 
typedef value_use_iterator
< const User
const_use_iterator
 

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. More...
 
bool canTrap () const
 
bool isThreadDependent () const
 isThreadDependent - Return true if the value can vary between threads. More...
 
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
 
- Public Member Functions inherited from llvm::User
 ~User ()
 
void operator delete (void *Usr)
 operator delete - free memory allocated for User and Use objects More...
 
void operator delete (void *, unsigned)
 placement delete - required by std, but never called. More...
 
void operator delete (void *, unsigned, bool)
 placement delete - required by std, but never called. More...
 
ValuegetOperand (unsigned i) const
 
void setOperand (unsigned i, Value *Val)
 
const UsegetOperandUse (unsigned i) const
 
UsegetOperandUse (unsigned i)
 
unsigned getNumOperands () const
 
op_iterator op_begin ()
 
const_op_iterator op_begin () const
 
op_iterator op_end ()
 
const_op_iterator op_end () const
 
value_op_iterator value_op_begin ()
 
value_op_iterator value_op_end ()
 
void dropAllReferences ()
 
void replaceUsesOfWith (Value *From, Value *To)
 
- Public Member Functions inherited from llvm::Value
virtual ~Value ()
 
void dump () const
 dump - Support for debugging, callable in GDB: V->dump() More...
 
void print (raw_ostream &O, AssemblyAnnotationWriter *AAW=0) const
 
TypegetType () const
 
LLVMContextgetContext () const
 All values hold a context through their type. More...
 
bool hasName () const
 
ValueNamegetValueName () const
 
void setValueName (ValueName *VN)
 
StringRef getName () const
 
void setName (const Twine &Name)
 
void takeName (Value *V)
 
void replaceAllUsesWith (Value *V)
 
bool use_empty () const
 
use_iterator use_begin ()
 
const_use_iterator use_begin () const
 
use_iterator use_end ()
 
const_use_iterator use_end () const
 
Useruse_back ()
 
const Useruse_back () const
 
bool hasOneUse () const
 
bool hasNUses (unsigned N) const
 
bool hasNUsesOrMore (unsigned N) const
 
bool isUsedInBasicBlock (const BasicBlock *BB) const
 
unsigned getNumUses () const
 
void addUse (Use &U)
 
unsigned getValueID () const
 
unsigned getRawSubclassOptionalData () const
 
void clearSubclassOptionalData ()
 
bool hasSameSubclassOptionalData (const Value *V) const
 
void intersectOptionalDataWith (const Value *V)
 
bool hasValueHandle () const
 
ValuestripPointerCasts ()
 Strips off any unneeded pointer casts, all-zero GEPs and aliases from the specified value, returning the original uncasted value. More...
 
const ValuestripPointerCasts () const
 
ValuestripPointerCastsNoFollowAliases ()
 Strips off any unneeded pointer casts and all-zero GEPs from the specified value, returning the original uncasted value. More...
 
const ValuestripPointerCastsNoFollowAliases () const
 
ValuestripInBoundsConstantOffsets ()
 Strips off unneeded pointer casts and all-constant GEPs from the specified value, returning the original pointer value. More...
 
const ValuestripInBoundsConstantOffsets () const
 
ValuestripAndAccumulateInBoundsConstantOffsets (const DataLayout &DL, APInt &Offset)
 Strips like stripInBoundsConstantOffsets but also accumulates the constant offset stripped. More...
 
const ValuestripAndAccumulateInBoundsConstantOffsets (const DataLayout &DL, APInt &Offset) const
 
ValuestripInBoundsOffsets ()
 Strips off unneeded pointer casts and any in-bounds offsets from the specified value, returning the original pointer value. More...
 
const ValuestripInBoundsOffsets () const
 
bool isDereferenceablePointer () const
 
ValueDoPHITranslation (const BasicBlock *CurBB, const BasicBlock *PredBB)
 
const ValueDoPHITranslation (const BasicBlock *CurBB, const BasicBlock *PredBB) const
 
void mutateType (Type *Ty)
 

Static Public Member Functions

static bool classof (const Value *V)
 
static ConstantgetNullValue (Type *Ty)
 
static ConstantgetAllOnesValue (Type *Ty)
 Get the all ones value. More...
 
static ConstantgetIntegerValue (Type *Ty, const APInt &V)
 
- Static Public Member Functions inherited from llvm::User
static bool classof (const Value *V)
 

Protected Member Functions

 Constant (Type *ty, ValueTy vty, Use *Ops, unsigned NumOps)
 
void destroyConstantImpl ()
 
- Protected Member Functions inherited from llvm::User
void * operator new (size_t s, unsigned Us)
 
 User (Type *ty, unsigned vty, Use *OpList, unsigned NumOps)
 
UseallocHungoffUses (unsigned) const
 
void dropHungoffUses ()
 
template<int Idx>
UseOp ()
 
template<int Idx>
const UseOp () const
 
- Protected Member Functions inherited from llvm::Value
virtual void printCustom (raw_ostream &O) const
 
 Value (Type *Ty, unsigned scid)
 
unsigned short getSubclassDataFromValue () const
 
void setValueSubclassData (unsigned short D)
 

Additional Inherited Members

- Static Public Attributes inherited from llvm::Value
static const unsigned MaximumAlignment = 1u << 29
 
- Static Protected Member Functions inherited from llvm::User
template<int Idx, typename U >
static UseOpFrom (const U *that)
 
- Protected Attributes inherited from llvm::User
UseOperandList
 
unsigned NumOperands
 
- Protected Attributes inherited from llvm::Value
unsigned char SubclassOptionalData: 7
 

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

Definition at line 47 of file Constant.h.

Member Function Documentation

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

References canTrapImpl().

Referenced by SplitCriticalSideEffectEdges().

static bool llvm::Constant::classof ( const Value V)
inlinestatic
virtual void llvm::Constant::destroyConstant ( )
inlinevirtual

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
Constant * Constant::getAggregateElement ( unsigned  Elt) const
Constant * Constant::getAggregateElement ( Constant Elt) const

Definition at line 204 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::ConstantFoldCall(), llvm::ConstantFoldCastInstruction(), llvm::ConstantFoldCompareInstOperands(), llvm::ConstantFoldCompareInstruction(), llvm::ConstantFoldExtractElementInstruction(), llvm::ConstantFoldLoadFromConstPtr(), 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::X86InstrInfo::foldMemoryOperandImpl(), llvm::InstCombiner::FoldShiftByConstant(), foldUDivNegCst(), llvm::ConstantExpr::getAlignOf(), llvm::ConstantExpr::getBinOpAbsorber(), llvm::ConstantExpr::getBinOpIdentity(), getFalse(), getFoldedSizeOf(), llvm::ConstantFP::getNegativeZero(), llvm::ConstantExpr::getOffsetOf(), llvm::DIBuilder::getOrCreateArray(), 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(), LowerToTLSExecModel(), 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().

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

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

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.

Definition at line 1276 of file Constants.cpp.

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

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

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

Definition at line 309 of file Constants.cpp.

References llvm::dyn_cast(), isConstantUsed(), llvm::Value::use_begin(), and llvm::Value::use_end().

Referenced by isConstantUsed().

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::isNullValue ( ) const
bool Constant::isThreadDependent ( ) const
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 llvm::ComputeMaskedBits(), and isZero().

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

References llvm::dyn_cast(), I, removeDeadUsersOfConstant(), llvm::Value::use_begin(), and llvm::Value::use_end().

Referenced by AddressIsTaken(), hasAddressTakenAndUsed(), INITIALIZE_PASS(), llvm::Inliner::removeDeadFunctions(), and llvm::GlobalValue::~GlobalValue().

virtual void llvm::Constant::replaceUsesOfWithOnConstant ( Value ,
Value ,
Use  
)
inlinevirtual

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: