class GlobalVariable

Declaration

class GlobalVariable : public GlobalObject, public ilist_node { /* full declaration omitted */ };

Description

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. LLVM Constant Representation

Declared at: llvm/include/llvm/IR/GlobalVariable.h:39

Inherits from: GlobalObject, ilist_node

Member Variables

private llvm::AttributeSet Attrs
private bool isConstantGlobal
private bool isExternallyInitializedConstant

Inherited from GlobalObject:

protected ObjComdat = nullptr
protected static GlobalObjectSubClassDataBits = GlobalValueSubClassDataBits - GlobalObjectBits

Inherited from GlobalValue:

protected ValueType
protected Linkage
protected Visibility
protected UnnamedAddrVal
protected DllStorageClass
protected ThreadLocal
protected HasLLVMReservedName
protected IsDSOLocal
protected HasPartition
protected HasSanitizerMetadata
protected IntID = (unsigned int)0U
protected Parent = nullptr
protected static GlobalValueSubClassDataBits = 15

Inherited from Value:

protected SubclassOptionalData
protected NumUserOperands
protected IsUsedByMD
protected HasName
protected HasMetadata
protected HasHungOffUses
protected HasDescriptor
public static MaxAlignmentExponent = 32
public static MaximumAlignment = 1ULL << MaxAlignmentExponent

Method Overview

Inherited from GlobalObject:

Inherited from GlobalValue:

Inherited from Constant:

Inherited from User:

Inherited from Value:

Methods

GlobalVariable(
    llvm::Module& M,
    llvm::Type* Ty,
    bool isConstant,
    llvm::GlobalValue::LinkageTypes Linkage,
    llvm::Constant* Initializer,
    const llvm::Twine& Name = "",
    llvm::GlobalVariable* InsertBefore = nullptr,
    llvm::GlobalValue::ThreadLocalMode =
        NotThreadLocal,
    Optional<unsigned int> AddressSpace = None,
    bool isExternallyInitialized = false)

Description

GlobalVariable ctor - This creates a global and inserts it before the specified other global.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:58

Parameters

llvm::Module& M
llvm::Type* Ty
bool isConstant
llvm::GlobalValue::LinkageTypes Linkage
llvm::Constant* Initializer
const llvm::Twine& Name = ""
llvm::GlobalVariable* InsertBefore = nullptr
llvm::GlobalValue::ThreadLocalMode = NotThreadLocal
Optional<unsigned int> AddressSpace = None
bool isExternallyInitialized = false

GlobalVariable(const llvm::GlobalVariable&)

Declared at: llvm/include/llvm/IR/GlobalVariable.h:64

Parameters

const llvm::GlobalVariable&

GlobalVariable(
    llvm::Type* Ty,
    bool isConstant,
    llvm::GlobalValue::LinkageTypes Linkage,
    llvm::Constant* Initializer = nullptr,
    const llvm::Twine& Name = "",
    llvm::GlobalValue::ThreadLocalMode =
        NotThreadLocal,
    unsigned int AddressSpace = 0,
    bool isExternallyInitialized = false)

Description

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

Declared at: llvm/include/llvm/IR/GlobalVariable.h:52

Parameters

llvm::Type* Ty
bool isConstant
llvm::GlobalValue::LinkageTypes Linkage
llvm::Constant* Initializer = nullptr
const llvm::Twine& Name = ""
llvm::GlobalValue::ThreadLocalMode = NotThreadLocal
unsigned int AddressSpace = 0
bool isExternallyInitialized = false

void addAttribute(
    llvm::StringRef Kind,
    llvm::StringRef Val = llvm::StringRef())

Description

Add attribute to this global.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:192

Parameters

llvm::StringRef Kind
llvm::StringRef Val = llvm::StringRef()

void addAttribute(Attribute::AttrKind Kind)

Description

Add attribute to this global.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:187

Parameters

Attribute::AttrKind Kind

void addDebugInfo(
    llvm::DIGlobalVariableExpression* GV)

Description

Attach a DIGlobalVariableExpression.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:181

Parameters

llvm::DIGlobalVariableExpression* GV

static bool classof(const llvm::Value* V)

Declared at: llvm/include/llvm/IR/GlobalVariable.h:250

Parameters

const llvm::Value* V

void copyAttributesFrom(
    const llvm::GlobalVariable* Src)

Description

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

Declared at: llvm/include/llvm/IR/GlobalVariable.h:164

Parameters

const llvm::GlobalVariable* Src

void dropAllReferences()

Description

Drop all references in preparation to destroy the GlobalVariable. This drops not only the reference to the initializer but also to any metadata.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:178

void eraseFromParent()

Description

eraseFromParent - This method unlinks 'this' from the containing module and deletes it.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:174

llvm::Attribute getAttribute(
    llvm::StringRef Kind) const

Description

Return the attribute object.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:217

Parameters

llvm::StringRef Kind

llvm::Attribute getAttribute(
    Attribute::AttrKind Kind) const

Description

Return the attribute object.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:212

Parameters

Attribute::AttrKind Kind

llvm::AttributeSet getAttributes() const

Description

Return the attribute set for this global

Declared at: llvm/include/llvm/IR/GlobalVariable.h:222

llvm::AttributeList getAttributesAsList(
    unsigned int index) const

Description

Return attribute set as list with index. FIXME: This may not be required once ValueEnumerators in bitcode-writer can enumerate attribute-set.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:229

Parameters

unsigned int index

void getDebugInfo(
    SmallVectorImpl<
        llvm::DIGlobalVariableExpression*>& GVs)
    const

Description

Fill the vector with all debug info attachements.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:184

Parameters

SmallVectorImpl< llvm::DIGlobalVariableExpression*>& GVs

inline llvm::Constant* getInitializer()

Declared at: llvm/include/llvm/IR/GlobalVariable.h:139

inline const llvm::Constant* getInitializer()
    const

Description

getInitializer - Return the initializer for this global variable. It is illegal to call this method if the global is external, because we cannot tell what the value is initialized to!

Declared at: llvm/include/llvm/IR/GlobalVariable.h:135

bool hasAttribute(Attribute::AttrKind Kind) const

Description

Return true if the attribute exists.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:197

Parameters

Attribute::AttrKind Kind

bool hasAttribute(llvm::StringRef Kind) const

Description

Return true if the attribute exists.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:202

Parameters

llvm::StringRef Kind

bool hasAttributes() const

Description

Return true if any attributes exist.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:207

inline bool hasDefinitiveInitializer() const

Description

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: @a = global SomeType* null - Initializer is both definitive and unique. @b = global weak SomeType* null - Initializer is neither definitive nor unique. @c = global weak_odr SomeType* null - Initializer is definitive, but not unique.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:109

bool hasImplicitSection() const

Description

Check if section name is present

Declared at: llvm/include/llvm/IR/GlobalVariable.h:242

inline bool hasInitializer() const

Description

Definitions have initializers, declarations don't.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:91

inline bool hasUniqueInitializer() const

Description

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

Declared at: llvm/include/llvm/IR/GlobalVariable.h:121

bool isConstant() const

Description

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.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:152

bool isExternallyInitialized() const

Declared at: llvm/include/llvm/IR/GlobalVariable.h:155

void removeFromParent()

Description

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

Declared at: llvm/include/llvm/IR/GlobalVariable.h:169

void setAttributes(llvm::AttributeSet A)

Description

Set attribute list for this global

Declared at: llvm/include/llvm/IR/GlobalVariable.h:237

Parameters

llvm::AttributeSet A

void setConstant(bool Val)

Declared at: llvm/include/llvm/IR/GlobalVariable.h:153

Parameters

bool Val

void setExternallyInitialized(bool Val)

Declared at: llvm/include/llvm/IR/GlobalVariable.h:158

Parameters

bool Val

void setInitializer(llvm::Constant* InitVal)

Description

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.

Declared at: llvm/include/llvm/IR/GlobalVariable.h:146

Parameters

llvm::Constant* InitVal

~GlobalVariable()

Declared at: llvm/include/llvm/IR/GlobalVariable.h:67