38 sizeof(
Constant) + 2 *
sizeof(
void *) + 2 *
sizeof(
unsigned),
39 "unexpected GlobalValue size growth");
43 "unexpected GlobalObject size growth");
46 if (
const Function *
F = dyn_cast<Function>(
this))
47 return F->isMaterializable();
56 void GlobalValue::destroyConstantImpl() {
74 #define HANDLE_GLOBAL_VALUE(NAME) \
75 case Value::NAME##Val: \
76 return static_cast<NAME *>(this)->removeFromParent();
77 #include "llvm/IR/Value.def"
86 #define HANDLE_GLOBAL_VALUE(NAME) \
87 case Value::NAME##Val: \
88 return static_cast<NAME *>(this)->eraseFromParent();
89 #include "llvm/IR/Value.def"
97 if (
auto *GA = dyn_cast<GlobalAlias>(
this)) {
100 return GO->getAlignment();
111 assert((Align & (Align-1)) == 0 &&
"Alignment is not a power of 2!");
113 "Alignment is greater than MaximumAlignment!");
114 unsigned AlignmentData =
Log2_32(Align) + 1;
136 std::string NewName =
Name;
142 if (FileName.
empty())
143 NewName = NewName.insert(0,
"<unknown>:");
145 NewName = NewName.insert(0, FileName.
str() +
":");
156 if (
auto *GA = dyn_cast<GlobalAlias>(
this)) {
159 return GO->getSection();
162 return cast<GlobalObject>(
this)->
getSection();
166 if (
auto *GA = dyn_cast<GlobalAlias>(
this)) {
169 return const_cast<GlobalObject *>(GO)->getComdat();
173 if (isa<GlobalIFunc>(
this))
175 return cast<GlobalObject>(
this)->
getComdat();
178 StringRef GlobalObject::getSectionImpl()
const {
203 return GV->getNumOperands() == 0;
206 if (
const Function *
F = dyn_cast<Function>(
this))
207 return F->empty() && !
F->isMaterializable();
210 assert(isa<GlobalIndirectSymbol>(
this));
256 if (
auto *GO = dyn_cast<GlobalObject>(
this))
258 if (
auto *GA = dyn_cast<GlobalIndirectSymbol>(
this))
290 bool isExternallyInitialized)
293 InitVal != nullptr, Link, Name, AddressSpace),
294 isConstantGlobal(constant),
295 isExternallyInitializedConstant(isExternallyInitialized) {
297 "invalid type for global variable");
301 "Initializer should be the same type as the GlobalVariable!");
310 bool isExternallyInitialized)
313 InitVal != nullptr, Link, Name, AddressSpace),
314 isConstantGlobal(constant),
315 isExternallyInitializedConstant(isExternallyInitialized) {
317 "invalid type for global variable");
321 "Initializer should be the same type as the GlobalVariable!");
345 Op<0>().set(
nullptr);
350 "Initializer type must match GlobalVariable type");
356 Op<0>().set(InitVal);
381 :
GlobalValue(Ty, VTy, &
Op<0>(), 1, Linkage, Name, AddressSpace) {
402 return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
408 return create(Ty, AddressSpace, Linkage, Name,
nullptr, Parent);
414 return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->
getParent());
438 "Alias and aliasee types should match!");
446 GlobalIFunc::GlobalIFunc(
Type *Ty,
unsigned AddressSpace, LinkageTypes Link,
458 return new GlobalIFunc(Ty, AddressSpace, Link, Name, Resolver, ParentModule);
void setVisibility(VisibilityTypes V)
LinkageTypes getLinkage() const
VisibilityTypes getVisibility() const
void copyAttributesFrom(const GlobalValue *Src)
Copy all additional attributes (those not needed to create a GlobalValue) from the GlobalValue Src to...
void dropAllReferences()
Drop all references to operands.
iterator erase(iterator where)
A Module instance is used to store all the information related to an LLVM module. ...
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
UnnamedAddr getUnnamedAddr() const
Type * getValueType() const
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Type * getElementType() const
void setAlignment(unsigned Align)
const AliasListType & getAliasList() const
Get the Module's list of aliases (constant).
const Comdat * getComdat() const
bool canIncreaseAlignment() const
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
const IFuncListType & getIFuncList() const
Get the Module's list of ifuncs (constant).
static bool isLocalLinkage(LinkageTypes Linkage)
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
StringRef getName() const
Return a constant reference to the value's name.
void setIndirectSymbol(Constant *Symbol)
These methods set and retrieve indirect symbol.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
bool hasDefaultVisibility() const
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
void setThreadLocalMode(ThreadLocalMode Val)
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...
const GlobalObject * getBaseObject() const
bool isStrongDefinitionForLinker() const
Returns true if this global's definition will be the one chosen by the linker.
static const unsigned MaximumAlignment
void setDLLStorageClass(DLLStorageClassTypes C)
unsigned getAlignment() const
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
bool isMaterializable() const
If this function's Module is being lazily streamed in functions from disk or some other source...
StringRef getSection() const
Get the custom section of this global if it has one.
AttributeSet getAttributes() const
Return the attribute set for this global.
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 ...
Class to represent pointers.
bool hasSection() const
Check if this global has a custom object file section.
bool isExternallyInitialized() 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...
void setExternallyInitialized(bool Val)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
unsigned getValueID() const
Return an ID for the concrete type of this object.
self_iterator getIterator()
void setGlobalVariableNumOperands(unsigned NumOps)
Set the number of operands on a GlobalVariable.
Error materialize()
Make sure this GlobalValue is fully read.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
DenseMap< const GlobalObject *, StringRef > GlobalObjectSections
Collection of per-GlobalObject sections used in this context.
LLVMContext & getContext() const
All values hold a context through their type.
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it...
std::pair< typename base::iterator, bool > insert(StringRef Key)
LLVMContextImpl *const pImpl
Triple - Helper class for working with autoconf configuration names.
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
bool isFunctionTy() const
True if this is an instance of FunctionType.
Optional< ConstantRange > getAbsoluteSymbolRange() const
If this is an absolute symbol reference, returns the range of the symbol, otherwise returns None...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e...
ValueTy
Concrete subclass of this.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
bool hasInitializer() const
Definitions have initializers, declarations don't.
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
llvm_unreachable("Unknown RegBank!")
ThreadLocalMode getThreadLocalMode() const
void dropAllReferences()
Drop all references in preparation to destroy the GlobalVariable.
unsigned getGlobalValueSubClassData() const
pointer remove(iterator &IT)
PointerType * getType() const
Global values are always pointers.
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
iterator insert(iterator where, pointer New)
void setUnnamedAddr(UnnamedAddr Val)
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it...
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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)
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
bool hasLocalLinkage() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getAlignment() const
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.
GlobalIndirectSymbol(Type *Ty, ValueTy VTy, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Symbol)
DLLStorageClassTypes getDLLStorageClass() const
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.
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.
StringSet SectionStrings
Stable collection of section strings.
bool isAbsoluteSymbolRef() const
Returns whether this is a reference to an absolute symbol.
StringRef getSection() const