17 #ifndef LLVM_IR_GLOBALVALUE_H 18 #define LLVM_IR_GLOBALVALUE_H 63 DefaultVisibility = 0,
70 DefaultStorageClass = 0,
71 DLLImportStorageClass = 1,
72 DLLExportStorageClass = 2
79 ValueType(Ty), Visibility(DefaultVisibility),
81 DllStorageClass(DefaultStorageClass),
ThreadLocal(NotThreadLocal),
83 IntID((Intrinsic::
ID)0U), Parent(nullptr) {
90 static const unsigned GlobalValueSubClassDataBits = 16;
118 unsigned SubClassData : GlobalValueSubClassDataBits;
122 void destroyConstantImpl();
128 bool mayBeDerefined()
const {
129 switch (getLinkage()) {
131 case LinkOnceODRLinkage:
132 case AvailableExternallyLinkage:
136 case LinkOnceAnyLinkage:
138 case ExternalWeakLinkage:
139 case ExternalLinkage:
140 case AppendingLinkage:
141 case InternalLinkage:
143 return isInterposable();
149 void maybeSetDsoLocal() {
150 if (hasLocalLinkage() ||
151 (!hasDefaultVisibility() && !hasExternalWeakLinkage()))
168 assert(V < (1 << GlobalValueSubClassDataBits) &&
"It will not fit");
180 removeDeadConstantUsers();
195 unsigned getAddressSpace()
const;
204 return getUnnamedAddr() == UnnamedAddr::Global;
224 if (A == UnnamedAddr::Local || B == UnnamedAddr::Local)
225 return UnnamedAddr::Local;
226 return UnnamedAddr::Global;
229 bool hasComdat()
const {
return getComdat() !=
nullptr; }
230 const Comdat *getComdat()
const;
232 return const_cast<Comdat *
>(
233 static_cast<const GlobalValue *
>(
this)->getComdat());
240 return Visibility == ProtectedVisibility;
243 assert((!hasLocalLinkage() || V == DefaultVisibility) &&
244 "local linkage requires default visibility");
250 bool isThreadLocal()
const {
return getThreadLocalMode() != NotThreadLocal; }
252 setThreadLocalMode(Val ? GeneralDynamicTLSModel : NotThreadLocal);
255 assert(Val == NotThreadLocal || getValueID() != Value::FunctionVal);
266 return DllStorageClass == DLLImportStorageClass;
269 return DllStorageClass == DLLExportStorageClass;
294 return ODR ? LinkOnceODRLinkage : LinkOnceAnyLinkage;
297 return ODR ? WeakODRLinkage : WeakAnyLinkage;
301 return Linkage == ExternalLinkage;
304 return Linkage == AvailableExternallyLinkage;
307 return Linkage == LinkOnceODRLinkage;
310 return Linkage == LinkOnceAnyLinkage || Linkage == LinkOnceODRLinkage;
313 return Linkage == WeakAnyLinkage;
316 return Linkage == WeakODRLinkage;
319 return isWeakAnyLinkage(Linkage) || isWeakODRLinkage(Linkage);
322 return Linkage == AppendingLinkage;
325 return Linkage == InternalLinkage;
328 return Linkage == PrivateLinkage;
331 return isInternalLinkage(Linkage) || isPrivateLinkage(Linkage);
334 return Linkage == ExternalWeakLinkage;
337 return Linkage == CommonLinkage;
340 return isExternalWeakLinkage(Linkage) || isExternalLinkage(Linkage);
349 case LinkOnceAnyLinkage:
351 case ExternalWeakLinkage:
354 case AvailableExternallyLinkage:
355 case LinkOnceODRLinkage:
359 case ExternalLinkage:
360 case AppendingLinkage:
361 case InternalLinkage:
371 return isLinkOnceLinkage(Linkage) || isLocalLinkage(Linkage) ||
372 isAvailableExternallyLinkage(Linkage);
380 return Linkage == WeakAnyLinkage || Linkage == WeakODRLinkage ||
381 Linkage == LinkOnceAnyLinkage || Linkage == LinkOnceODRLinkage ||
382 Linkage == CommonLinkage || Linkage == ExternalWeakLinkage;
412 return !mayBeDerefined();
422 return !isDeclaration() && isDefinitionExact();
433 return isAvailableExternallyLinkage(getLinkage());
437 return isLinkOnceODRLinkage(getLinkage());
447 return isExternalWeakLinkage(getLinkage());
451 return isValidDeclarationLinkage(getLinkage());
455 if (isLocalLinkage(LT))
456 Visibility = DefaultVisibility;
463 return isDiscardableIfUnused(getLinkage());
482 if (!Name.
empty() && Name[0] ==
'\1')
497 std::string getGlobalIdentifier()
const;
522 bool isMaterializable()
const;
531 bool isDeclaration()
const;
534 if (hasAvailableExternallyLinkage())
537 return isDeclaration();
547 return !(isDeclarationForLinker() || isWeakForLinker());
552 bool canIncreaseAlignment()
const;
557 static_cast<const GlobalValue *
>(
this)->getBaseObject());
561 bool isAbsoluteSymbolRef()
const;
569 void removeFromParent();
572 void eraseFromParent();
580 return V->
getValueID() == Value::FunctionVal ||
581 V->
getValueID() == Value::GlobalVariableVal ||
591 bool canBeOmittedFromSymbolTable()
const;
596 #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.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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
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...
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
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.
static bool isAppendingLinkage(LinkageTypes Linkage)
LinkageTypes getLinkage() const
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)
unsigned HasPartition
True if this symbol has a partition name assigned (see https://lld.llvm.org/Partitions.html).
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.
bool hasPartition() const
void setUnnamedAddr(UnnamedAddr Val)
bool isStrongDefinitionForLinker() const
Returns true if this global's definition will be the one chosen by the linker.
Linkage
Describes symbol linkage.
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 or more pointer types, with the discriminator in the low bit of the poin...