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();
192 unsigned getAddressSpace()
const;
201 return getUnnamedAddr() == UnnamedAddr::Global;
221 if (A == UnnamedAddr::Local || B == UnnamedAddr::Local)
222 return UnnamedAddr::Local;
223 return UnnamedAddr::Global;
226 bool hasComdat()
const {
return getComdat() !=
nullptr; }
227 const Comdat *getComdat()
const;
229 return const_cast<Comdat *
>(
230 static_cast<const GlobalValue *
>(
this)->getComdat());
240 assert((!hasLocalLinkage() || V == DefaultVisibility) &&
241 "local linkage requires default visibility");
247 bool isThreadLocal()
const {
return getThreadLocalMode() != NotThreadLocal; }
249 setThreadLocalMode(Val ? GeneralDynamicTLSModel : NotThreadLocal);
252 assert(Val == NotThreadLocal || getValueID() != Value::FunctionVal);
263 return DllStorageClass == DLLImportStorageClass;
266 return DllStorageClass == DLLExportStorageClass;
285 return ODR ? LinkOnceODRLinkage : LinkOnceAnyLinkage;
288 return ODR ? WeakODRLinkage : WeakAnyLinkage;
292 return Linkage == ExternalLinkage;
295 return Linkage == AvailableExternallyLinkage;
298 return Linkage == LinkOnceODRLinkage;
301 return Linkage == LinkOnceAnyLinkage || Linkage == LinkOnceODRLinkage;
304 return Linkage == WeakAnyLinkage;
307 return Linkage == WeakODRLinkage;
310 return isWeakAnyLinkage(Linkage) || isWeakODRLinkage(Linkage);
313 return Linkage == AppendingLinkage;
316 return Linkage == InternalLinkage;
319 return Linkage == PrivateLinkage;
322 return isInternalLinkage(Linkage) || isPrivateLinkage(Linkage);
325 return Linkage == ExternalWeakLinkage;
328 return Linkage == CommonLinkage;
331 return isExternalWeakLinkage(Linkage) || isExternalLinkage(Linkage);
340 case LinkOnceAnyLinkage:
342 case ExternalWeakLinkage:
345 case AvailableExternallyLinkage:
346 case LinkOnceODRLinkage:
350 case ExternalLinkage:
351 case AppendingLinkage:
352 case InternalLinkage:
362 return isLinkOnceLinkage(Linkage) || isLocalLinkage(Linkage) ||
363 isAvailableExternallyLinkage(Linkage);
371 return Linkage == WeakAnyLinkage || Linkage == WeakODRLinkage ||
372 Linkage == LinkOnceAnyLinkage || Linkage == LinkOnceODRLinkage ||
373 Linkage == CommonLinkage || Linkage == ExternalWeakLinkage;
403 return !mayBeDerefined();
413 return !isDeclaration() && isDefinitionExact();
424 return isAvailableExternallyLinkage(getLinkage());
428 return isLinkOnceODRLinkage(getLinkage());
438 return isExternalWeakLinkage(getLinkage());
442 return isValidDeclarationLinkage(getLinkage());
446 if (isLocalLinkage(LT))
454 return isDiscardableIfUnused(getLinkage());
473 if (!Name.
empty() && Name[0] ==
'\1')
488 std::string getGlobalIdentifier()
const;
513 bool isMaterializable()
const;
522 bool isDeclaration()
const;
525 if (hasAvailableExternallyLinkage())
528 return isDeclaration();
538 return !(isDeclarationForLinker() || isWeakForLinker());
543 bool canIncreaseAlignment()
const;
548 static_cast<const GlobalValue *
>(
this)->getBaseObject());
552 bool isAbsoluteSymbolRef()
const;
560 void removeFromParent();
563 void eraseFromParent();
571 return V->
getValueID() == Value::FunctionVal ||
572 V->
getValueID() == Value::GlobalVariableVal ||
582 bool canBeOmittedFromSymbolTable()
const;
587 #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.
This class represents lattice values for constants.
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)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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
BlockVerifier::State From
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...