37 sizeof(
Constant) + 2 *
sizeof(
void *) + 2 *
sizeof(
unsigned),
38 "unexpected GlobalValue size growth");
42 "unexpected GlobalObject size growth");
45 if (
const Function *
F = dyn_cast<Function>(
this))
46 return F->isMaterializable();
55 void GlobalValue::destroyConstantImpl() {
75 #define HANDLE_GLOBAL_VALUE(NAME) \ 76 case Value::NAME##Val: \ 77 return static_cast<NAME *>(this)->removeFromParent(); 78 #include "llvm/IR/Value.def" 87 #define HANDLE_GLOBAL_VALUE(NAME) \ 88 case Value::NAME##Val: \ 89 return static_cast<NAME *>(this)->eraseFromParent(); 90 #include "llvm/IR/Value.def" 98 if (
auto *GA = dyn_cast<GlobalAlias>(
this)) {
101 return GO->getAlignment();
122 "Alignment is greater than MaximumAlignment!");
123 unsigned AlignmentData =
encode(Align);
127 "Alignment representation error!");
146 std::string NewName =
Name;
152 if (FileName.
empty())
153 NewName = NewName.insert(0,
"<unknown>:");
155 NewName = NewName.insert(0, FileName.
str() +
":");
166 if (
auto *GA = dyn_cast<GlobalAlias>(
this)) {
169 return GO->getSection();
172 return cast<GlobalObject>(
this)->
getSection();
176 if (
auto *GA = dyn_cast<GlobalAlias>(
this)) {
179 return const_cast<GlobalObject *>(GO)->getComdat();
183 if (isa<GlobalIFunc>(
this))
185 return cast<GlobalObject>(
this)->
getComdat();
210 StringRef GlobalObject::getSectionImpl()
const {
228 setGlobalObjectFlag(HasSectionHashEntryBit, !S.
empty());
234 return GV->getNumOperands() == 0;
237 if (
const Function *
F = dyn_cast<Function>(
this))
238 return F->empty() && !
F->isMaterializable();
241 assert(isa<GlobalIndirectSymbol>(
this));
287 if (
auto *GO = dyn_cast<GlobalObject>(
this))
289 if (
auto *GA = dyn_cast<GlobalIndirectSymbol>(
this))
299 return GO->
getMetadata(LLVMContext::MD_absolute_symbol);
307 MDNode *MD = GO->getMetadata(LLVMContext::MD_absolute_symbol);
325 if (
auto *Var = dyn_cast<GlobalVariable>(
this))
326 if (!Var->isConstant())
339 bool isExternallyInitialized)
342 InitVal != nullptr, Link, Name, AddressSpace),
343 isConstantGlobal(constant),
344 isExternallyInitializedConstant(isExternallyInitialized) {
346 "invalid type for global variable");
350 "Initializer should be the same type as the GlobalVariable!");
362 InitVal != nullptr, Link, Name, AddressSpace),
363 isConstantGlobal(constant),
364 isExternallyInitializedConstant(isExternallyInitialized) {
366 "invalid type for global variable");
370 "Initializer should be the same type as the GlobalVariable!");
394 Op<0>().
set(
nullptr);
399 "Initializer type must match GlobalVariable type");
405 Op<0>().
set(InitVal);
430 :
GlobalValue(Ty, VTy, &
Op<0>(), 1, Linkage, Name, AddressSpace) {
436 if (
auto *GO = dyn_cast<GlobalObject>(C))
438 if (
auto *GA = dyn_cast<GlobalAlias>(C))
439 if (Aliases.
insert(GA).second)
441 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
442 switch (CE->getOpcode()) {
448 return LHS ? LHS : RHS;
450 case Instruction::Sub: {
455 case Instruction::IntToPtr:
456 case Instruction::PtrToInt:
457 case Instruction::BitCast:
458 case Instruction::GetElementPtr:
488 return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
494 return create(Ty, AddressSpace, Linkage, Name,
nullptr, Parent);
500 return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->
getParent());
524 "Alias and aliasee types should match!");
532 GlobalIFunc::GlobalIFunc(
Type *Ty,
unsigned AddressSpace,
LinkageTypes Link,
544 return new GlobalIFunc(Ty, AddressSpace, Link, Name, Resolver, ParentModule);
void setVisibility(VisibilityTypes V)
AttributeSet getAttributes() const
Return the attribute set for this global.
StringRef getSection() const
Get the custom section of this global if it has one.
unsigned getAlignment() const
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
ThreadLocalMode getThreadLocalMode() const
void copyAttributesFrom(const GlobalValue *Src)
Copy all additional attributes (those not needed to create a GlobalValue) from the GlobalValue Src to...
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
unsigned getValueID() const
Return an ID for the concrete type of this object.
void dropAllReferences()
Drop all references to operands.
iterator erase(iterator where)
This class represents lattice values for constants.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
A Module instance is used to store all the information related to an LLVM module. ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
bool isMaterializable() const
If this function's Module is being lazily streamed in functions from disk or some other source...
Implements a dense probed hash-table based set.
LLVMContext & getContext() const
All values hold a context through their type.
Optional< ConstantRange > getAbsoluteSymbolRange() const
If this is an absolute symbol reference, returns the range of the symbol, otherwise returns None...
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e...
bool canBeOmittedFromSymbolTable() const
True if GV can be left out of the object symbol table.
static bool isLocalLinkage(LinkageTypes Linkage)
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
DenseMap< const GlobalValue *, StringRef > GlobalValuePartitions
Collection of per-GlobalValue partitions used in this context.
const AliasListType & getAliasList() const
Get the Module's list of aliases (constant).
void setIndirectSymbol(Constant *Symbol)
These methods set and retrieve indirect symbol.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
UnnamedAddr getUnnamedAddr() const
bool hasAtLeastLocalUnnamedAddr() const
Returns true if this value's address is not significant in this module.
void setThreadLocalMode(ThreadLocalMode Val)
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
static GlobalIFunc * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Resolver, Module *Parent)
If a parent module is specified, the ifunc is automatically inserted into the end of the specified mo...
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
static const unsigned MaximumAlignment
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
void setDLLStorageClass(DLLStorageClassTypes C)
void setPartition(StringRef Part)
Type * getType() const
All values are typed, get the type of this value.
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
const GlobalObject * getBaseObject() const
StringRef save(const char *S)
LinkageTypes getLinkage() const
unsigned getAlignment() const
GlobalVariable(Type *Ty, bool isConstant, LinkageTypes Linkage, Constant *Initializer=nullptr, const Twine &Name="", ThreadLocalMode=NotThreadLocal, unsigned AddressSpace=0, bool isExternallyInitialized=false)
GlobalVariable ctor - If a parent module is specified, the global is automatically inserted into the ...
Value * getOperand(unsigned i) const
Class to represent pointers.
bool hasLinkOnceODRLinkage() const
bool canIncreaseAlignment() const
DLLStorageClassTypes getDLLStorageClass() const
VisibilityTypes getVisibility() const
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
void setExternallyInitialized(bool Val)
std::pair< iterator, bool > insert(const ValueT &V)
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
unsigned getAddressSpace() const
unsigned getAddressSpace() const
Return the address space of the Pointer type.
self_iterator getIterator()
void setGlobalVariableNumOperands(unsigned NumOps)
Set the number of operands on a GlobalVariable.
unsigned getGlobalValueSubClassData() const
Error materialize()
Make sure this GlobalValue is fully read.
DenseMap< const GlobalObject *, StringRef > GlobalObjectSections
Collection of per-GlobalObject sections used in this context.
StringRef getSection() const
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
LLVMContextImpl *const pImpl
const IFuncListType & getIFuncList() const
Get the Module's list of ifuncs (constant).
Triple - Helper class for working with autoconf configuration names.
StringRef getPartition() const
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
BlockVerifier::State From
static const GlobalObject * findBaseObject(const Constant *C, DenseSet< const GlobalAlias *> &Aliases)
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
Module.h This file contains the declarations for the Module class.
bool hasGlobalUnnamedAddr() const
ValueTy
Concrete subclass of this.
unsigned HasPartition
True if this symbol has a partition name assigned (see https://lld.llvm.org/Partitions.html).
const Comdat * getComdat() const
void push_back(pointer val)
LinkageTypes
An enumeration for the kinds of linkage for global values.
void setGlobalValueSubClassData(unsigned V)
void setAttributes(AttributeSet A)
Set attribute list for this global.
void dropAllReferences()
Drop all references in preparation to destroy the GlobalVariable.
pointer remove(iterator &IT)
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
bool hasPartition() const
iterator insert(iterator where, pointer New)
bool isFunctionTy() const
True if this is an instance of FunctionType.
void setAlignment(MaybeAlign Align)
bool isAbsoluteSymbolRef() const
Returns whether this is a reference to an absolute symbol.
void setUnnamedAddr(UnnamedAddr Val)
bool isStrongDefinitionForLinker() const
Returns true if this global's definition will be the one chosen by the linker.
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it...
StringRef getName() const
Return a constant reference to the value's name.
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
Compile-time customization of User operands.
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Type * getValueType() const
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
const GlobalObject * getBaseObject() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
bool hasInitializer() const
Definitions have initializers, declarations don't.
Lightweight error class with error context and mandatory checking.
GlobalIndirectSymbol(Type *Ty, ValueTy VTy, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Symbol)
StringRef - Represent a constant reference to a string, i.e.
void copyAttributesFrom(const GlobalObject *Src)
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
bool isExternallyInitialized() const
void setSection(StringRef S)
Change the section for this global.
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
void setAliasee(Constant *Aliasee)
These methods retrieve and set alias target.
Type * getElementType() const
void setDSOLocal(bool Local)
PointerType * getType() const
Global values are always pointers.