LLVM 20.0.0git
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
llvm::sandboxir::GlobalVariable Class Referencefinal

#include "llvm/SandboxIR/Constant.h"

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

Public Member Functions

bool hasInitializer () const
 Definitions have initializers, declarations don't.
 
bool hasDefinitiveInitializer () const
 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.
 
bool hasUniqueInitializer () const
 hasUniqueInitializer - Whether the global variable has an initializer, and any changes made to the initializer will turn up in the final executable.
 
ConstantgetInitializer () const
 getInitializer - Return the initializer for this global variable.
 
void setInitializer (Constant *InitVal)
 setInitializer - Sets the initializer for this global variable, removing any existing initializer if InitVal==NULL.
 
bool isConstant () const
 If the value is a global constant, its value is immutable throughout the runtime execution of the program.
 
void setConstant (bool V)
 
bool isExternallyInitialized () const
 
void setExternallyInitialized (bool Val)
 
bool hasAttribute (Attribute::AttrKind Kind) const
 Return true if the attribute exists.
 
bool hasAttribute (StringRef Kind) const
 Return true if the attribute exists.
 
bool hasAttributes () const
 Return true if any attributes exist.
 
Attribute getAttribute (Attribute::AttrKind Kind) const
 Return the attribute object.
 
Attribute getAttribute (StringRef Kind) const
 Return the attribute object.
 
AttributeSet getAttributes () const
 Return the attribute set for this global.
 
AttributeList getAttributesAsList (unsigned Index) const
 Return attribute set as list with index.
 
bool hasImplicitSection () const
 Check if section name is present.
 
unsigned getCodeModelRaw () const
 Get the custom code model raw value of this global.
 
std::optional< CodeModel::ModelgetCodeModel () const
 Get the custom code model of this global if it has one.
 
void verify () const override
 Should crash if there is something wrong with the instruction.
 
void dumpOS (raw_ostream &OS) const override
 
- Public Member Functions inherited from llvm::sandboxir::GlobalWithNodeAPI< GlobalVariable, llvm::GlobalVariable, GlobalObject, llvm::GlobalObject >
 GlobalWithNodeAPI (Value::ClassID ID, llvm::GlobalObject *C, Context &Ctx)
 
ModulegetParent () const
 
iterator getIterator () const
 
reverse_iterator getReverseIterator () const
 
- Public Member Functions inherited from llvm::sandboxir::GlobalObject
unsigned getUseOperandNo (const Use &Use) const final
 \Returns the operand index of Use.
 
uint64_t getAlignment () const
 FIXME: Remove this function once transition to Align is over.
 
MaybeAlign getAlign () const
 Returns the alignment of the given variable or function.
 
void setAlignment (MaybeAlign Align)
 Sets the alignment attribute of the GlobalObject.
 
unsigned getGlobalObjectSubClassData () const
 
void setGlobalObjectSubClassData (unsigned V)
 
bool hasSection () const
 Check if this global has a custom object file section.
 
StringRef getSection () const
 Get the custom section of this global if it has one.
 
void setSection (StringRef S)
 Change the section for this global.
 
bool hasComdat () const
 
VCallVisibility getVCallVisibility () const
 
bool canIncreaseAlignment () const
 Returns true if the alignment of the value can be unilaterally increased.
 
- Public Member Functions inherited from llvm::sandboxir::GlobalValue
unsigned getAddressSpace () const
 
bool hasGlobalUnnamedAddr () const
 
bool hasAtLeastLocalUnnamedAddr () const
 Returns true if this value's address is not significant in this module.
 
UnnamedAddr getUnnamedAddr () const
 
void setUnnamedAddr (UnnamedAddr V)
 
bool hasComdat () const
 
VisibilityTypes getVisibility () const
 
bool hasDefaultVisibility () const
 
bool hasHiddenVisibility () const
 
bool hasProtectedVisibility () const
 
void setVisibility (VisibilityTypes V)
 
- Public Member Functions inherited from llvm::sandboxir::Constant
sandboxir::ContextgetParent () const
 
unsigned getUseOperandNo (const Use &Use) const override
 \Returns the operand index of Use.
 
void verify () const override
 Should crash if there is something wrong with the instruction.
 
void dumpOS (raw_ostream &OS) const override
 
- Public Member Functions inherited from llvm::sandboxir::User
virtual op_iterator op_begin ()
 
virtual op_iterator op_end ()
 
virtual const_op_iterator op_begin () const
 
virtual const_op_iterator op_end () const
 
op_range operands ()
 
const_op_range operands () const
 
ValuegetOperand (unsigned OpIdx) const
 
Use getOperandUse (unsigned OpIdx) const
 \Returns the operand edge for OpIdx.
 
virtual unsigned getNumOperands () const
 
virtual void setOperand (unsigned OperandIdx, Value *Operand)
 
bool replaceUsesOfWith (Value *FromV, Value *ToV)
 Replaces any operands that match FromV with ToV.
 
void verify () const override
 Should crash if there is something wrong with the instruction.
 
void dumpCommonHeader (raw_ostream &OS) const final
 
void dumpOS (raw_ostream &OS) const override
 
- Public Member Functions inherited from llvm::sandboxir::Value
virtual ~Value ()=default
 
ClassID getSubclassID () const
 
use_iterator use_begin ()
 
const_use_iterator use_begin () const
 
use_iterator use_end ()
 
const_use_iterator use_end () const
 
iterator_range< use_iteratoruses ()
 
iterator_range< const_use_iteratoruses () const
 
user_iterator user_begin ()
 
user_iterator user_end ()
 
const_user_iterator user_begin () const
 
const_user_iterator user_end () const
 
iterator_range< user_iteratorusers ()
 
iterator_range< const_user_iteratorusers () const
 
unsigned getNumUses () const
 \Returns the number of user edges (not necessarily to unique users).
 
bool hasNUsesOrMore (unsigned Num) const
 Return true if this value has N uses or more.
 
bool hasNUses (unsigned Num) const
 Return true if this Value has exactly N uses.
 
TypegetType () const
 
ContextgetContext () const
 
void replaceUsesWithIf (Value *OtherV, llvm::function_ref< bool(const Use &)> ShouldReplace)
 
void replaceAllUsesWith (Value *Other)
 
StringRef getName () const
 \Returns the LLVM IR name of the bottom-most LLVM value.
 
virtual void verify () const =0
 Should crash if there is something wrong with the instruction.
 
std::string getUid () const
 Returns the unique id in the form 'SB<number>.' like 'SB1.'.
 
virtual void dumpCommonHeader (raw_ostream &OS) const
 
void dumpCommonFooter (raw_ostream &OS) const
 
void dumpCommonPrefix (raw_ostream &OS) const
 
void dumpCommonSuffix (raw_ostream &OS) const
 
void printAsOperandCommon (raw_ostream &OS) const
 
virtual void dumpOS (raw_ostream &OS) const =0
 
LLVM_DUMP_METHOD void dump () const
 

Static Public Member Functions

static bool classof (const sandboxir::Value *From)
 For isa/dyn_cast.
 
- Static Public Member Functions inherited from llvm::sandboxir::GlobalObject
static bool classof (const sandboxir::Value *From)
 For isa/dyn_cast.
 
- Static Public Member Functions inherited from llvm::sandboxir::GlobalValue
static bool classof (const sandboxir::Value *From)
 For isa/dyn_cast.
 
static UnnamedAddr getMinUnnamedAddr (UnnamedAddr A, UnnamedAddr B)
 
- Static Public Member Functions inherited from llvm::sandboxir::Constant
static bool classof (const sandboxir::Value *From)
 For isa/dyn_cast.
 
- Static Public Member Functions inherited from llvm::sandboxir::User
static bool classof (const Value *From)
 For isa/dyn_cast.
 

Friends

class Context
 

Additional Inherited Members

- Public Types inherited from llvm::sandboxir::GlobalWithNodeAPI< GlobalVariable, llvm::GlobalVariable, GlobalObject, llvm::GlobalObject >
using iterator = mapped_iterator< decltype(static_cast< llvm::GlobalVariable * >(nullptr) ->getIterator()), LLVMGVToGV >
 
using reverse_iterator = mapped_iterator< decltype(static_cast< llvm::GlobalVariable * >(nullptr) ->getReverseIterator()), LLVMGVToGV >
 
- Public Types inherited from llvm::sandboxir::GlobalObject
using VCallVisibility = llvm::GlobalObject::VCallVisibility
 
- Public Types inherited from llvm::sandboxir::GlobalValue
using LinkageTypes = llvm::GlobalValue::LinkageTypes
 
using UnnamedAddr = llvm::GlobalValue::UnnamedAddr
 
using VisibilityTypes = llvm::GlobalValue::VisibilityTypes
 
- Public Types inherited from llvm::sandboxir::User
using op_iterator = OperandUseIterator
 
using const_op_iterator = OperandUseIterator
 
using op_range = iterator_range< op_iterator >
 
using const_op_range = iterator_range< const_op_iterator >
 
- Public Types inherited from llvm::sandboxir::Value
enum class  ClassID : unsigned { DEF_VALUE , DEF_USER , DEF_CONST , DEF_INSTR }
 
using use_iterator = UserUseIterator
 
using const_use_iterator = UserUseIterator
 
using user_iterator = mapped_iterator< sandboxir::UserUseIterator, UseToUser >
 
using const_user_iterator = user_iterator
 
- Protected Member Functions inherited from llvm::sandboxir::GlobalObject
 GlobalObject (ClassID ID, llvm::GlobalObject *C, Context &Ctx)
 
Use getOperandUseInternal (unsigned OpIdx, bool Verify) const final
 \Returns the Use for the OpIdx'th operand.
 
- Protected Member Functions inherited from llvm::sandboxir::GlobalValue
 GlobalValue (ClassID ID, llvm::GlobalValue *C, Context &Ctx)
 
- Protected Member Functions inherited from llvm::sandboxir::Constant
 Constant (llvm::Constant *C, sandboxir::Context &SBCtx)
 
 Constant (ClassID ID, llvm::Constant *C, sandboxir::Context &SBCtx)
 
Use getOperandUseInternal (unsigned OpIdx, bool Verify) const override
 \Returns the Use for the OpIdx'th operand.
 
- Protected Member Functions inherited from llvm::sandboxir::User
 User (ClassID ID, llvm::Value *V, Context &Ctx)
 
Use getOperandUseDefault (unsigned OpIdx, bool Verify) const
 \Returns the Use edge that corresponds to OpIdx.
 
virtual Use getOperandUseInternal (unsigned OpIdx, bool Verify) const =0
 \Returns the Use for the OpIdx'th operand.
 
unsigned getUseOperandNoDefault (const Use &Use) const
 The default implementation works only for single-LLVMIR-instruction Users and only if they match exactly the LLVM instruction.
 
virtual unsigned getUseOperandNo (const Use &Use) const =0
 \Returns the operand index of Use.
 
void swapOperandsInternal (unsigned OpIdxA, unsigned OpIdxB)
 
void verifyUserOfLLVMUse (const llvm::Use &Use) const
 
- Protected Member Functions inherited from llvm::sandboxir::Value
void clearValue ()
 
 Value (ClassID SubclassID, llvm::Value *Val, Context &Ctx)
 
 Value (const Value &)=delete
 Disable copies.
 
Valueoperator= (const Value &)=delete
 
- Static Protected Member Functions inherited from llvm::sandboxir::Value
static const chargetSubclassIDStr (ClassID ID)
 
- Protected Attributes inherited from llvm::sandboxir::Value
ClassID SubclassID
 For isa/dyn_cast.
 
unsigned UID
 A unique ID used for forming the name (used for debugging).
 
llvm::ValueVal = nullptr
 The LLVM Value that corresponds to this SandboxIR Value.
 
ContextCtx
 All values point to the context.
 

Detailed Description

Definition at line 866 of file Constant.h.

Member Function Documentation

◆ classof()

static bool llvm::sandboxir::GlobalVariable::classof ( const sandboxir::Value From)
inlinestatic

For isa/dyn_cast.

Definition at line 882 of file Constant.h.

References From.

◆ dumpOS()

void llvm::sandboxir::GlobalVariable::dumpOS ( raw_ostream OS) const
inlineoverridevirtual

◆ getAttribute() [1/2]

Attribute llvm::sandboxir::GlobalVariable::getAttribute ( Attribute::AttrKind  Kind) const
inline

Return the attribute object.

Definition at line 969 of file Constant.h.

References llvm::sandboxir::Value::Val.

◆ getAttribute() [2/2]

Attribute llvm::sandboxir::GlobalVariable::getAttribute ( StringRef  Kind) const
inline

Return the attribute object.

Definition at line 974 of file Constant.h.

References llvm::sandboxir::Value::Val.

◆ getAttributes()

AttributeSet llvm::sandboxir::GlobalVariable::getAttributes ( ) const
inline

Return the attribute set for this global.

Definition at line 979 of file Constant.h.

References llvm::sandboxir::Value::Val.

◆ getAttributesAsList()

AttributeList llvm::sandboxir::GlobalVariable::getAttributesAsList ( unsigned  Index) const
inline

Return attribute set as list with index.

FIXME: This may not be required once ValueEnumerators in bitcode-writer can enumerate attribute-set.

Definition at line 986 of file Constant.h.

References Index, and llvm::sandboxir::Value::Val.

◆ getCodeModel()

std::optional< CodeModel::Model > llvm::sandboxir::GlobalVariable::getCodeModel ( ) const
inline

Get the custom code model of this global if it has one.

If this global does not have a custom code model, the empty instance will be returned.

Definition at line 1005 of file Constant.h.

References llvm::sandboxir::Value::Val.

◆ getCodeModelRaw()

unsigned llvm::sandboxir::GlobalVariable::getCodeModelRaw ( ) const
inline

Get the custom code model raw value of this global.

Definition at line 997 of file Constant.h.

References llvm::sandboxir::Value::Val.

◆ getInitializer()

Constant * llvm::sandboxir::GlobalVariable::getInitializer ( ) const

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!

Definition at line 349 of file Constant.cpp.

References llvm::sandboxir::Value::Ctx, getInitializer(), llvm::sandboxir::Context::getOrCreateConstant(), and llvm::sandboxir::Value::Val.

Referenced by getInitializer(), and setInitializer().

◆ hasAttribute() [1/2]

bool llvm::sandboxir::GlobalVariable::hasAttribute ( Attribute::AttrKind  Kind) const
inline

Return true if the attribute exists.

Definition at line 954 of file Constant.h.

References llvm::sandboxir::Value::Val.

◆ hasAttribute() [2/2]

bool llvm::sandboxir::GlobalVariable::hasAttribute ( StringRef  Kind) const
inline

Return true if the attribute exists.

Definition at line 959 of file Constant.h.

References llvm::sandboxir::Value::Val.

◆ hasAttributes()

bool llvm::sandboxir::GlobalVariable::hasAttributes ( ) const
inline

Return true if any attributes exist.

Definition at line 964 of file Constant.h.

References llvm::sandboxir::Value::Val.

◆ hasDefinitiveInitializer()

bool llvm::sandboxir::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 908 of file Constant.h.

References llvm::sandboxir::Value::Val.

◆ hasImplicitSection()

bool llvm::sandboxir::GlobalVariable::hasImplicitSection ( ) const
inline

Check if section name is present.

Definition at line 991 of file Constant.h.

References llvm::sandboxir::Value::Val.

◆ hasInitializer()

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

Definitions have initializers, declarations don't.

Definition at line 888 of file Constant.h.

References llvm::sandboxir::Value::Val.

◆ hasUniqueInitializer()

bool llvm::sandboxir::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 914 of file Constant.h.

References llvm::sandboxir::Value::Val.

◆ isConstant()

bool llvm::sandboxir::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 934 of file Constant.h.

References llvm::sandboxir::Value::Val.

Referenced by setConstant().

◆ isExternallyInitialized()

bool llvm::sandboxir::GlobalVariable::isExternallyInitialized ( ) const
inline

Definition at line 939 of file Constant.h.

References llvm::sandboxir::Value::Val.

Referenced by setExternallyInitialized().

◆ setConstant()

void llvm::sandboxir::GlobalVariable::setConstant ( bool  V)

◆ setExternallyInitialized()

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

◆ setInitializer()

void llvm::sandboxir::GlobalVariable::setInitializer ( Constant InitVal)

setInitializer - Sets the initializer for this global variable, removing any existing initializer if InitVal==NULL.

The initializer must have the type getValueType().

Definition at line 354 of file Constant.cpp.

References llvm::sandboxir::Value::Ctx, llvm::sandboxir::Tracker::emplaceIfTracking(), getInitializer(), llvm::sandboxir::Context::getTracker(), setInitializer(), and llvm::sandboxir::Value::Val.

Referenced by setInitializer().

◆ verify()

void llvm::sandboxir::GlobalVariable::verify ( ) const
inlineoverridevirtual

Should crash if there is something wrong with the instruction.

Reimplemented from llvm::sandboxir::Constant.

Definition at line 1012 of file Constant.h.

References assert(), and llvm::sandboxir::Value::Val.

Friends And Related Function Documentation

◆ Context

friend class Context
friend

Definition at line 871 of file Constant.h.


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