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 | Friends | List of all members
llvm::GlobalVariable Class Reference

#include <GlobalVariable.h>

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

Public Types

enum  ThreadLocalMode {
  NotThreadLocal = 0, GeneralDynamicTLSModel, LocalDynamicTLSModel, InitialExecTLSModel,
  LocalExecTLSModel
}
 
- Public Types inherited from llvm::GlobalValue
enum  LinkageTypes {
  ExternalLinkage = 0, AvailableExternallyLinkage, LinkOnceAnyLinkage, LinkOnceODRLinkage,
  WeakAnyLinkage, WeakODRLinkage, AppendingLinkage, InternalLinkage,
  PrivateLinkage, LinkerPrivateLinkage, LinkerPrivateWeakLinkage, DLLImportLinkage,
  DLLExportLinkage, ExternalWeakLinkage, CommonLinkage
}
 An enumeration for the kinds of linkage for global values. More...
 
enum  VisibilityTypes { DefaultVisibility = 0, HiddenVisibility, ProtectedVisibility }
 An enumeration for the kinds of visibility of global values. More...
 
- Public Types inherited from llvm::Constant
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

void * operator new (size_t s)
 
 GlobalVariable (Type *Ty, bool isConstant, LinkageTypes Linkage, Constant *Initializer=0, const Twine &Name="", ThreadLocalMode=NotThreadLocal, unsigned AddressSpace=0, bool isExternallyInitialized=false)
 
 GlobalVariable (Module &M, Type *Ty, bool isConstant, LinkageTypes Linkage, Constant *Initializer, const Twine &Name="", GlobalVariable *InsertBefore=0, ThreadLocalMode=NotThreadLocal, unsigned AddressSpace=0, bool isExternallyInitialized=false)
 
 ~GlobalVariable ()
 
 DECLARE_TRANSPARENT_OPERAND_ACCESSORS (Value)
 Provide fast operand accessors. More...
 
bool hasInitializer () const
 
bool hasDefinitiveInitializer () const
 
bool hasUniqueInitializer () const
 
const ConstantgetInitializer () const
 
ConstantgetInitializer ()
 
void setInitializer (Constant *InitVal)
 
bool isConstant () const
 
void setConstant (bool Val)
 
bool isThreadLocal () const
 If the value is "Thread Local", its value isn't shared by the threads. More...
 
void setThreadLocal (bool Val)
 
void setThreadLocalMode (ThreadLocalMode Val)
 
ThreadLocalMode getThreadLocalMode () const
 
bool isExternallyInitialized () const
 
void setExternallyInitialized (bool Val)
 
void copyAttributesFrom (const GlobalValue *Src)
 
virtual void removeFromParent ()
 
virtual void eraseFromParent ()
 
virtual void replaceUsesOfWithOnConstant (Value *From, Value *To, Use *U)
 
- Public Member Functions inherited from llvm::GlobalValue
 ~GlobalValue ()
 
unsigned getAlignment () const
 
void setAlignment (unsigned Align)
 
bool hasUnnamedAddr () const
 
void setUnnamedAddr (bool Val)
 
VisibilityTypes getVisibility () const
 
bool hasDefaultVisibility () const
 
bool hasHiddenVisibility () const
 
bool hasProtectedVisibility () const
 
void setVisibility (VisibilityTypes V)
 
bool hasSection () const
 
const std::string & getSection () const
 
void setSection (StringRef S)
 
bool use_empty_except_constants ()
 Determine if the usage of this global value is empty except for transitively dead constants. More...
 
PointerTypegetType () const
 getType - Global values are always pointers. More...
 
bool hasExternalLinkage () const
 
bool hasAvailableExternallyLinkage () const
 
bool hasLinkOnceLinkage () const
 
bool hasWeakLinkage () const
 
bool hasAppendingLinkage () const
 
bool hasInternalLinkage () const
 
bool hasPrivateLinkage () const
 
bool hasLinkerPrivateLinkage () const
 
bool hasLinkerPrivateWeakLinkage () const
 
bool hasLocalLinkage () const
 
bool hasDLLImportLinkage () const
 
bool hasDLLExportLinkage () const
 
bool hasExternalWeakLinkage () const
 
bool hasCommonLinkage () const
 
void setLinkage (LinkageTypes LT)
 
LinkageTypes getLinkage () const
 
bool isDiscardableIfUnused () const
 
bool mayBeOverridden () const
 
bool isWeakForLinker () const
 
virtual void destroyConstant ()
 Override from Constant class. More...
 
bool isDeclaration () const
 
ModulegetParent ()
 
const ModulegetParent () const
 
bool isMaterializable () const
 
bool isDematerializable () const
 
bool Materialize (std::string *ErrInfo=0)
 
void Dematerialize ()
 
- Public Member Functions inherited from llvm::Constant
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
 
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)
 
- Public Member Functions inherited from llvm::ilist_node< GlobalVariable >
GlobalVariablegetPrevNode ()
 Get the previous node, or 0 for the list head. More...
 
const GlobalVariablegetPrevNode () const
 Get the previous node, or 0 for the list head. More...
 
GlobalVariablegetNextNode ()
 Get the next node, or 0 for the list tail. More...
 
const GlobalVariablegetNextNode () const
 Get the next node, or 0 for the list tail. More...
 

Static Public Member Functions

static bool classof (const Value *V)
 
- Static Public Member Functions inherited from llvm::GlobalValue
static LinkageTypes getLinkOnceLinkage (bool ODR)
 
static LinkageTypes getWeakLinkage (bool ODR)
 
static bool isExternalLinkage (LinkageTypes Linkage)
 
static bool isAvailableExternallyLinkage (LinkageTypes Linkage)
 
static bool isLinkOnceLinkage (LinkageTypes Linkage)
 
static bool isWeakLinkage (LinkageTypes Linkage)
 
static bool isAppendingLinkage (LinkageTypes Linkage)
 
static bool isInternalLinkage (LinkageTypes Linkage)
 
static bool isPrivateLinkage (LinkageTypes Linkage)
 
static bool isLinkerPrivateLinkage (LinkageTypes Linkage)
 
static bool isLinkerPrivateWeakLinkage (LinkageTypes Linkage)
 
static bool isLocalLinkage (LinkageTypes Linkage)
 
static bool isDLLImportLinkage (LinkageTypes Linkage)
 
static bool isDLLExportLinkage (LinkageTypes Linkage)
 
static bool isExternalWeakLinkage (LinkageTypes Linkage)
 
static bool isCommonLinkage (LinkageTypes Linkage)
 
static bool isDiscardableIfUnused (LinkageTypes Linkage)
 
static bool mayBeOverridden (LinkageTypes Linkage)
 
static bool isWeakForLinker (LinkageTypes Linkage)
 
static StringRef getRealLinkageName (StringRef Name)
 
static bool classof (const Value *V)
 
- Static Public Member Functions inherited from llvm::Constant
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)
 

Friends

class SymbolTableListTraits< GlobalVariable, Module >
 

Additional Inherited Members

- Static Public Attributes inherited from llvm::Value
static const unsigned MaximumAlignment = 1u << 29
 
- Protected Member Functions inherited from llvm::GlobalValue
 GlobalValue (Type *ty, ValueTy vty, Use *Ops, unsigned NumOps, LinkageTypes linkage, const Twine &Name)
 
- Protected Member Functions inherited from llvm::Constant
 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)
 
- Protected Member Functions inherited from llvm::ilist_node< GlobalVariable >
 ilist_node ()
 
- Static Protected Member Functions inherited from llvm::User
template<int Idx, typename U >
static UseOpFrom (const U *that)
 
- Protected Attributes inherited from llvm::GlobalValue
LinkageTypes Linkage: 5
 
unsigned Visibility: 2
 
unsigned Alignment: 16
 
unsigned UnnamedAddr: 1
 
ModuleParent
 
std::string Section
 
- Protected Attributes inherited from llvm::User
UseOperandList
 
unsigned NumOperands
 
- Protected Attributes inherited from llvm::Value
unsigned char SubclassOptionalData: 7
 

Detailed Description

Definition at line 35 of file GlobalVariable.h.

Member Enumeration Documentation

Enumerator
NotThreadLocal 
GeneralDynamicTLSModel 
LocalDynamicTLSModel 
InitialExecTLSModel 
LocalExecTLSModel 

Definition at line 58 of file GlobalVariable.h.

Constructor & Destructor Documentation

GlobalVariable::GlobalVariable ( Type Ty,
bool  isConstant,
LinkageTypes  Linkage,
Constant Initializer = 0,
const Twine Name = "",
ThreadLocalMode  TLMode = NotThreadLocal,
unsigned  AddressSpace = 0,
bool  isExternallyInitialized = false 
)

GlobalVariable ctor - If a parent module is specified, the global is automatically inserted into the end of the specified modules global list.

Definition at line 84 of file Globals.cpp.

References llvm::LeakDetector::addGarbageObject(), and llvm::Value::getType().

GlobalVariable::GlobalVariable ( Module M,
Type Ty,
bool  isConstant,
LinkageTypes  Linkage,
Constant Initializer,
const Twine Name = "",
GlobalVariable InsertBefore = 0,
ThreadLocalMode  TLMode = NotThreadLocal,
unsigned  AddressSpace = 0,
bool  isExternallyInitialized = false 
)
llvm::GlobalVariable::~GlobalVariable ( )
inline

Definition at line 80 of file GlobalVariable.h.

References llvm::User::NumOperands.

Member Function Documentation

static bool llvm::GlobalVariable::classof ( const Value V)
inlinestatic

Definition at line 194 of file GlobalVariable.h.

References llvm::Value::getValueID(), and llvm::Value::GlobalVariableVal.

void GlobalVariable::copyAttributesFrom ( const GlobalValue Src)
virtual

copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) from the GlobalVariable Src to this one.

Reimplemented from llvm::GlobalValue.

Definition at line 183 of file Globals.cpp.

References llvm::GlobalValue::copyAttributesFrom(), isThreadLocal(), and setThreadLocal().

Referenced by llvm::CloneModule(), and INITIALIZE_PASS().

llvm::GlobalVariable::DECLARE_TRANSPARENT_OPERAND_ACCESSORS ( Value  )

Provide fast operand accessors.

void GlobalVariable::eraseFromParent ( )
virtual
const Constant* llvm::GlobalVariable::getInitializer ( ) const
inline
Constant* llvm::GlobalVariable::getInitializer ( )
inline

Definition at line 142 of file GlobalVariable.h.

References hasInitializer().

ThreadLocalMode llvm::GlobalVariable::getThreadLocalMode ( ) const
inline
bool llvm::GlobalVariable::hasDefinitiveInitializer ( ) const
inline

hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of the global (this can happen due to weak linkage) are guaranteed to have the same initializer.

Note that if you want to transform a global, you must use hasUniqueInitializer() instead, because of the *_odr linkage type.

Example:

= global SomeType* null - Initializer is both definitive and unique.

= global weak SomeType* null - Initializer is neither definitive nor unique.

= global weak_odr SomeType* null - Initializer is definitive, but not unique.

Definition at line 107 of file GlobalVariable.h.

References hasInitializer(), isExternallyInitialized(), and llvm::GlobalValue::mayBeOverridden().

Referenced by FoldReinterpretLoadFromConstPtr(), llvm::getConstantStringInfo(), and llvm::ObjectSizeOffsetVisitor::visitGlobalVariable().

bool llvm::GlobalVariable::hasInitializer ( ) const
inline
bool llvm::GlobalVariable::hasUniqueInitializer ( ) const
inline

hasUniqueInitializer - Whether the global variable has an initializer, and any changes made to the initializer will turn up in the final executable.

Definition at line 119 of file GlobalVariable.h.

References hasInitializer(), isExternallyInitialized(), and llvm::GlobalValue::isWeakForLinker().

Referenced by isSimpleEnoughPointerToCommit().

bool llvm::GlobalVariable::isConstant ( ) const
inline

If the value is a global constant, its value is immutable throughout the runtime execution of the program. Assigning a value into the constant leads to undefined behavior.

Definition at line 155 of file GlobalVariable.h.

Referenced by AnalyzeLoadFromClobberingMemInst(), CleanupPointerRootUsers(), FoldReinterpretLoadFromConstPtr(), llvm::getConstantStringInfo(), llvm::TargetLoweringObjectFile::getKindForGlobal(), llvm::JIT::getMemoryForGV(), INITIALIZE_PASS(), InstallGlobalCtors(), isSuitableForBSS(), llvm::AssemblyWriter::printGlobal(), and SRAGlobal().

bool llvm::GlobalVariable::isExternallyInitialized ( ) const
inline
bool llvm::GlobalVariable::isThreadLocal ( ) const
inline
void* llvm::GlobalVariable::operator new ( size_t  s)
inline

Definition at line 54 of file GlobalVariable.h.

void GlobalVariable::removeFromParent ( )
virtual

removeFromParent - This method unlinks 'this' from the containing module, but does not delete it.

Implements llvm::GlobalValue.

Definition at line 138 of file Globals.cpp.

References llvm::Module::getGlobalList(), llvm::GlobalValue::getParent(), and llvm::iplist< NodeTy, Traits >::remove().

Referenced by setUsedInitializer().

void GlobalVariable::replaceUsesOfWithOnConstant ( Value From,
Value To,
Use U 
)
virtual

Override Constant's implementation of this method so we can replace constant initializers.

Reimplemented from llvm::Constant.

Definition at line 146 of file Globals.cpp.

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

void llvm::GlobalVariable::setConstant ( bool  Val)
inline

Definition at line 156 of file GlobalVariable.h.

void llvm::GlobalVariable::setExternallyInitialized ( bool  Val)
inline

Definition at line 171 of file GlobalVariable.h.

void GlobalVariable::setInitializer ( Constant InitVal)

setInitializer - Sets the initializer for this global variable, removing any existing initializer if InitVal==NULL. If this GV has type T*, the initializer must have type T.

Definition at line 166 of file Globals.cpp.

References llvm::SequentialType::getElementType(), llvm::GlobalValue::getType(), llvm::Value::getType(), hasInitializer(), and llvm::User::NumOperands.

Referenced by llvm::CloneModule(), CommitValueTo(), and InstallGlobalCtors().

void llvm::GlobalVariable::setThreadLocal ( bool  Val)
inline

Definition at line 160 of file GlobalVariable.h.

References GeneralDynamicTLSModel, and NotThreadLocal.

Referenced by copyAttributesFrom().

void llvm::GlobalVariable::setThreadLocalMode ( ThreadLocalMode  Val)
inline

Definition at line 163 of file GlobalVariable.h.

Referenced by LLVMSetThreadLocalMode().

Friends And Related Function Documentation

friend class SymbolTableListTraits< GlobalVariable, Module >
friend

Definition at line 36 of file GlobalVariable.h.


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