18 #ifndef LLVM_IR_GLOBALVALUE_H 19 #define LLVM_IR_GLOBALVALUE_H 64 DefaultVisibility = 0,
71 DefaultStorageClass = 0,
72 DLLImportStorageClass = 1,
73 DLLExportStorageClass = 2
82 DllStorageClass(DefaultStorageClass),
ThreadLocal(NotThreadLocal),
83 HasLLVMReservedName(
false), IsDSOLocal(
false), IntID((Intrinsic::
ID)0U),
91 static const unsigned GlobalValueSubClassDataBits = 17;
115 unsigned SubClassData : GlobalValueSubClassDataBits;
119 void destroyConstantImpl();
125 bool mayBeDerefined()
const {
126 switch (getLinkage()) {
128 case LinkOnceODRLinkage:
129 case AvailableExternallyLinkage:
133 case LinkOnceAnyLinkage:
135 case ExternalWeakLinkage:
136 case ExternalLinkage:
137 case AppendingLinkage:
138 case InternalLinkage:
140 return isInterposable();
146 void maybeSetDsoLocal() {
147 if (hasLocalLinkage() ||
148 (!hasDefaultVisibility() && !hasExternalWeakLinkage()))
165 assert(V < (1 << GlobalValueSubClassDataBits) &&
"It will not fit");
177 removeDeadConstantUsers();
220 if (A == UnnamedAddr::Local || B == UnnamedAddr::Local)
221 return UnnamedAddr::Local;
225 bool hasComdat()
const {
return getComdat() !=
nullptr; }
226 const Comdat *getComdat()
const;
228 return const_cast<Comdat *
>(
229 static_cast<const GlobalValue *
>(
this)->getComdat());
239 assert((!hasLocalLinkage() || V == DefaultVisibility) &&
240 "local linkage requires default visibility");
246 bool isThreadLocal()
const {
return getThreadLocalMode() != NotThreadLocal; }
248 setThreadLocalMode(Val ? GeneralDynamicTLSModel : NotThreadLocal);
251 assert(Val == NotThreadLocal || getValueID() != Value::FunctionVal);
262 return DllStorageClass == DLLImportStorageClass;
265 return DllStorageClass == DLLExportStorageClass;
284 return ODR ? LinkOnceODRLinkage : LinkOnceAnyLinkage;
287 return ODR ? WeakODRLinkage : WeakAnyLinkage;
291 return Linkage == ExternalLinkage;
294 return Linkage == AvailableExternallyLinkage;
297 return Linkage == LinkOnceODRLinkage;
300 return Linkage == LinkOnceAnyLinkage || Linkage == LinkOnceODRLinkage;
303 return Linkage == WeakAnyLinkage;
306 return Linkage == WeakODRLinkage;
309 return isWeakAnyLinkage(Linkage) || isWeakODRLinkage(Linkage);
312 return Linkage == AppendingLinkage;
315 return Linkage == InternalLinkage;
318 return Linkage == PrivateLinkage;
321 return isInternalLinkage(Linkage) || isPrivateLinkage(Linkage);
324 return Linkage == ExternalWeakLinkage;
327 return Linkage == CommonLinkage;
330 return isExternalWeakLinkage(Linkage) || isExternalLinkage(Linkage);
339 case LinkOnceAnyLinkage:
341 case ExternalWeakLinkage:
344 case AvailableExternallyLinkage:
345 case LinkOnceODRLinkage:
349 case ExternalLinkage:
350 case AppendingLinkage:
351 case InternalLinkage:
361 return isLinkOnceLinkage(Linkage) || isLocalLinkage(Linkage) ||
362 isAvailableExternallyLinkage(Linkage);
370 return Linkage == WeakAnyLinkage || Linkage == WeakODRLinkage ||
371 Linkage == LinkOnceAnyLinkage || Linkage == LinkOnceODRLinkage ||
372 Linkage == CommonLinkage || Linkage == ExternalWeakLinkage;
402 return !mayBeDerefined();
412 return !isDeclaration() && isDefinitionExact();
423 return isAvailableExternallyLinkage(getLinkage());
427 return isLinkOnceODRLinkage(getLinkage());
437 return isExternalWeakLinkage(getLinkage());
441 return isValidDeclarationLinkage(getLinkage());
445 if (isLocalLinkage(LT))
453 return isDiscardableIfUnused(getLinkage());
472 if (!Name.
empty() && Name[0] ==
'\1')
487 std::string getGlobalIdentifier()
const;
512 bool isMaterializable()
const;
521 bool isDeclaration()
const;
524 if (hasAvailableExternallyLinkage())
527 return isDeclaration();
537 return !(isDeclarationForLinker() || isWeakForLinker());
542 bool canIncreaseAlignment()
const;
547 static_cast<const GlobalValue *
>(
this)->getBaseObject());
551 bool isAbsoluteSymbolRef()
const;
559 void removeFromParent();
562 void eraseFromParent();
570 return V->
getValueID() == Value::FunctionVal ||
571 V->
getValueID() == Value::GlobalVariableVal ||
581 bool canBeOmittedFromSymbolTable()
const;
586 #endif // LLVM_IR_GLOBALVALUE_H void setVisibility(VisibilityTypes V)
static bool isInterposableLinkage(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time...
bool isDeclarationForLinker() const
ThreadLocalMode getThreadLocalMode() const
bool hasDLLExportStorageClass() const
bool hasLocalLinkage() const
Special purpose, only applies to global arrays.
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
unsigned getValueID() const
Return an ID for the concrete type of this object.
bool hasPrivateLinkage() const
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Compute iterated dominance frontiers using a linear time algorithm.
A Module instance is used to store all the information related to an LLVM module. ...
Same, but only replaced by something equivalent.
ThreadLocal - A class used to abstract thread-local storage.
static bool isExternalLinkage(LinkageTypes Linkage)
Available for inspection, not emission.
bool hasAvailableExternallyLinkage() const
uint64_t MD5Hash(StringRef Str)
Helper to compute and return lower 64 bits of the given string's MD5 hash.
Like Internal, but omit from symbol table.
static bool isWeakAnyLinkage(LinkageTypes Linkage)
static bool isCommonLinkage(LinkageTypes Linkage)
bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time...
bool hasDLLImportStorageClass() const
ELFYAML::ELF_STV Visibility
bool hasExternalWeakLinkage() const
bool hasWeakAnyLinkage() const
static bool isLocalLinkage(LinkageTypes Linkage)
static bool isLinkOnceLinkage(LinkageTypes Linkage)
void setParent(Module *parent)
static uint32_t getAlignment(const MCSectionCOFF &Sec)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A Use represents the edge between a Value definition and its users.
UnnamedAddr getUnnamedAddr() const
bool hasAtLeastLocalUnnamedAddr() const
Returns true if this value's address is not significant in this module.
void setThreadLocalMode(ThreadLocalMode Val)
unsigned IsDSOLocal
If true then there is a definition within the same linkage unit and that definition cannot be runtime...
void setDLLStorageClass(DLLStorageClassTypes C)
bool hasCommonLinkage() const
Expected< const typename ELFT::Shdr * > getSection(typename ELFT::ShdrRange Sections, uint32_t Index)
static bool isLinkOnceODRLinkage(LinkageTypes Linkage)
bool hasValidDeclarationLinkage() const
bool hasExternalLinkage() const
static bool isPrivateLinkage(LinkageTypes Linkage)
Type * getType() const
All values are typed, get the type of this value.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
static bool isAppendingLinkage(LinkageTypes Linkage)
LinkageTypes getLinkage() const
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).
bool hasLinkOnceLinkage() const
Class to represent pointers.
bool hasAppendingLinkage() const
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
ExternalWeak linkage description.
bool hasLinkOnceODRLinkage() const
Same, but only replaced by something equivalent.
static bool isInternalLinkage(LinkageTypes Linkage)
bool hasProtectedVisibility() const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
DLLStorageClassTypes getDLLStorageClass() const
VisibilityTypes getVisibility() const
The instances of the Type class are immutable: once they are created, they are never changed...
static bool isWeakODRLinkage(LinkageTypes Linkage)
static bool classof(const Value *V)
GlobalObject * getBaseObject()
This is an important base class in LLVM.
bool isWeakForLinker() const
bool hasInternalLinkage() const
static bool isDiscardableIfUnused(LinkageTypes Linkage)
Whether the definition of this global may be discarded if it is not used in its compilation unit...
DLLStorageClassTypes
Storage classes of global values for PE targets.
GlobalValue(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps, LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace)
Intrinsic::ID IntID
The intrinsic ID for this subclass (which must be a Function).
unsigned getGlobalValueSubClassData() const
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
bool hasWeakODRLinkage() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static LinkageTypes getWeakLinkage(bool ODR)
bool hasWeakLinkage() const
bool isDefinitionExact() const
Return true if the currently visible definition of this global (if any) is exactly the definition we ...
bool isDiscardableIfUnused() const
static bool isWeakLinkage(LinkageTypes Linkage)
Keep one copy of function when linking (inline)
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
bool hasGlobalUnnamedAddr() const
ValueTy
Concrete subclass of this.
void setLinkage(LinkageTypes LT)
static bool isExternalWeakLinkage(LinkageTypes Linkage)
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1', drop it.
LinkageTypes
An enumeration for the kinds of linkage for global values.
void setGlobalValueSubClassData(unsigned V)
unsigned HasLLVMReservedName
True if the function's name starts with "llvm.".
bool hasHiddenVisibility() const
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
void setUnnamedAddr(UnnamedAddr Val)
bool isStrongDefinitionForLinker() const
Returns true if this global's definition will be the one chosen by the linker.
bool hasExactDefinition() const
Return true if this global has an exact defintion.
Type * getValueType() const
Keep one copy of named function when linking (weak)
Rename collisions when linking (static functions).
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
static LinkageTypes getLinkOnceLinkage(bool ODR)
void setThreadLocal(bool Val)
Lightweight error class with error context and mandatory checking.
bool hasDefaultVisibility() const
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
StringRef - Represent a constant reference to a string, i.e.
static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B)
static bool isValidDeclarationLinkage(LinkageTypes Linkage)
void setDSOLocal(bool Local)
const Module * getParent() const
PointerType * getType() const
Global values are always pointers.
A discriminated union of two pointer types, with the discriminator in the low bit of the pointer...