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();
53void GlobalValue::destroyConstantImpl() {
70 if (Src->hasSanitizerMetadata())
78 return MD5Hash(GlobalIdentifier);
83#define HANDLE_GLOBAL_VALUE(NAME) \
84 case Value::NAME##Val: \
85 return static_cast<NAME *>(this)->removeFromParent();
86#include "llvm/IR/Value.def"
95#define HANDLE_GLOBAL_VALUE(NAME) \
96 case Value::NAME##Val: \
97 return static_cast<NAME *>(this)->eraseFromParent();
98#include "llvm/IR/Value.def"
124 auto isDeduplicateComdat = [](
const Comdat *
C) {
129 !isa<GlobalIFunc>(
this) && !isDeduplicateComdat(
getComdat());
138 "Alignment is greater than MaximumAlignment!");
147 "Alignment is greater than MaximumAlignment!");
152 "Alignment representation error!");
167 Name.consume_front(
"\1");
169 std::string GlobalName;
175 if (FileName.
empty())
176 GlobalName +=
"<unknown>";
178 GlobalName += FileName;
186std::string GlobalValue::getGlobalIdentifier()
const {
192 if (
auto *GA = dyn_cast<GlobalAlias>(
this)) {
195 return GO->getSection();
198 return cast<GlobalObject>(
this)->getSection();
202 if (
auto *GA = dyn_cast<GlobalAlias>(
this)) {
209 if (isa<GlobalIFunc>(
this))
211 return cast<GlobalObject>(
this)->getComdat();
259 MetadataMap.
erase(
this);
265 Meta.NoAddress =
true;
266 Meta.NoHWAddress =
true;
270StringRef GlobalObject::getSectionImpl()
const {
300 cast<MDString>(MD->getOperand(0))->getString();
301 assert((MDName ==
"section_prefix" ||
302 (isa<Function>(
this) && MDName ==
"function_section_prefix")) &&
303 "Metadata not match");
304 return cast<MDString>(MD->getOperand(1))->getString();
309bool GlobalValue::isNobuiltinFnDef()
const {
310 const Function *
F = dyn_cast<Function>(
this);
311 if (!
F ||
F->empty())
313 return F->hasFnAttribute(Attribute::NoBuiltin);
319 return GV->getNumOperands() == 0;
322 if (
const Function *
F = dyn_cast<Function>(
this))
323 return F->empty() && !
F->isMaterializable();
326 assert(isa<GlobalAlias>(
this) || isa<GlobalIFunc>(
this));
373 if (GV->hasAttribute(
"toc-data"))
379template <
typename Operation>
383 if (
auto *GO = dyn_cast<GlobalObject>(
C)) {
387 if (
auto *GA = dyn_cast<GlobalAlias>(
C)) {
389 if (Aliases.
insert(GA).second)
392 if (
auto *CE = dyn_cast<ConstantExpr>(
C)) {
393 switch (CE->getOpcode()) {
394 case Instruction::Add: {
401 case Instruction::Sub: {
406 case Instruction::IntToPtr:
407 case Instruction::PtrToAddr:
408 case Instruction::PtrToInt:
409 case Instruction::BitCast:
410 case Instruction::GetElementPtr:
425 auto *GO = dyn_cast<GlobalObject>(
this);
429 return GO->getMetadata(LLVMContext::MD_absolute_symbol);
433 auto *GO = dyn_cast<GlobalObject>(
this);
437 MDNode *MD = GO->getMetadata(LLVMContext::MD_absolute_symbol);
455 if (
auto *Var = dyn_cast<GlobalVariable>(
this))
456 if (!Var->isConstant())
469 bool isExternallyInitialized)
472 isConstantGlobal(constant),
473 isExternallyInitializedConstant(isExternallyInitialized) {
475 "invalid type for global variable");
479 "Initializer should be the same type as the GlobalVariable!");
482 setGlobalVariableNumOperands(0);
491 bool isExternallyInitialized)
495 : M.getDataLayout().getDefaultGlobalsAddressSpace(),
496 isExternallyInitialized) {
500 M.insertGlobalVariable(
this);
517 Op<0>().set(
nullptr);
518 setGlobalVariableNumOperands(0);
522 "Initializer type must match GlobalVariable type");
527 setGlobalVariableNumOperands(1);
528 Op<0>().set(InitVal);
533 assert(InitVal &&
"Can't compute type of null initializer");
544 if (
auto CM = Src->getCodeModel())
554 unsigned CodeModelData =
static_cast<unsigned>(CM) + 1;
556 unsigned NewData = (OldData & ~(CodeModelMask << CodeModelShift)) |
557 (CodeModelData << CodeModelShift);
563 unsigned CodeModelData = 0;
565 unsigned NewData = (OldData & ~(CodeModelMask << CodeModelShift)) |
566 (CodeModelData << CodeModelShift);
619 "Alias and aliasee types should match!");
620 Op<0>().set(Aliasee);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
BlockVerifier::State From
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static const GlobalObject * findBaseObject(const Constant *C, DenseSet< const GlobalAlias * > &Aliases, const Operation &Op)
Module.h This file contains the declarations for the Module class.
PowerPC Reduce CR logical Operation
@ NoDeduplicate
No deduplication is performed.
This is an important base class in LLVM.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
bool erase(const KeyT &Val)
Implements a dense probed hash-table based set.
Lightweight error class with error context and mandatory checking.
LLVM_ABI void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
LLVM_ABI const GlobalObject * getAliaseeObject() const
LLVM_ABI void setAliasee(Constant *Aliasee)
These methods retrieve and set alias target.
static LLVM_ABI 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...
LLVM_ABI void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it.
LLVM_ABI void applyAlongResolverPath(function_ref< void(const GlobalValue &)> Op) const
LLVM_ABI const Function * getResolverFunction() const
LLVM_ABI void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
static LLVM_ABI 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_ABI void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
const Constant * getResolver() const
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
LLVM_ABI void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
LLVM_ABI void setComdat(Comdat *C)
LLVM_ABI void copyAttributesFrom(const GlobalObject *Src)
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
LLVM_ABI void setSectionPrefix(StringRef Prefix)
Set the section prefix for this global object.
LLVM_ABI std::optional< StringRef > getSectionPrefix() const
Get the section prefix for this global object.
LLVM_ABI void clearMetadata()
Erase all metadata attached to this Value.
bool hasSection() const
Check if this global has a custom object file section.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
LLVM_ABI bool canIncreaseAlignment() const
Returns true if the alignment of the value can be unilaterally increased.
unsigned HasSanitizerMetadata
True if this symbol has sanitizer metadata available.
bool hasPartition() const
static LLVM_ABI GUID getGUIDAssumingExternalLinkage(StringRef GlobalName)
Return a 64-bit global unique ID constructed from the name of a global symbol.
LLVM_ABI const SanitizerMetadata & getSanitizerMetadata() const
unsigned HasPartition
True if this symbol has a partition name assigned (see https://lld.llvm.org/Partitions....
LLVM_ABI void removeSanitizerMetadata()
static bool isLocalLinkage(LinkageTypes Linkage)
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
LinkageTypes getLinkage() const
void setUnnamedAddr(UnnamedAddr Val)
bool hasDefaultVisibility() const
LLVM_ABI bool isAbsoluteSymbolRef() const
Returns whether this is a reference to an absolute symbol.
void setDLLStorageClass(DLLStorageClassTypes C)
LLVM_ABI const Comdat * getComdat() const
void setThreadLocalMode(ThreadLocalMode Val)
bool hasSanitizerMetadata() const
unsigned getAddressSpace() const
LLVM_ABI StringRef getSection() const
LLVM_ABI StringRef getPartition() const
Module * getParent()
Get the module that this global value is contained inside of...
LLVM_ABI const GlobalObject * getAliaseeObject() const
void setDSOLocal(bool Local)
LLVM_ABI std::optional< ConstantRange > getAbsoluteSymbolRange() const
If this is an absolute symbol reference, returns the range of the symbol, otherwise returns std::null...
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
static bool isExternalLinkage(LinkageTypes Linkage)
bool isStrongDefinitionForLinker() const
Returns true if this global's definition will be the one chosen by the linker.
PointerType * getType() const
Global values are always pointers.
LLVM_ABI void copyAttributesFrom(const GlobalValue *Src)
Copy all additional attributes (those not needed to create a GlobalValue) from the GlobalValue Src to...
LLVM_ABI void setNoSanitizeMetadata()
LLVM_ABI bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
void setVisibility(VisibilityTypes V)
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
LLVM_ABI bool canBenefitFromLocalAlias() const
static bool isInterposableLinkage(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time.
bool hasAtLeastLocalUnnamedAddr() const
Returns true if this value's address is not significant in this module.
unsigned getGlobalValueSubClassData() const
void setGlobalValueSubClassData(unsigned V)
LLVM_ABI bool isMaterializable() const
If this function's Module is being lazily streamed in functions from disk or some other source,...
bool hasGlobalUnnamedAddr() const
LLVM_ABI Error materialize()
Make sure this GlobalValue is fully read.
LLVM_ABI void setSanitizerMetadata(SanitizerMetadata Meta)
bool hasLinkOnceODRLinkage() const
LLVM_ABI bool canBeOmittedFromSymbolTable() const
True if GV can be left out of the object symbol table.
LLVM_ABI void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
LinkageTypes
An enumeration for the kinds of linkage for global values.
Type * getValueType() const
LLVM_ABI void setPartition(StringRef Part)
LLVM_ABI void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
bool hasInitializer() const
Definitions have initializers, declarations don't.
LLVM_ABI void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it.
std::optional< CodeModel::Model > getCodeModel() const
Get the custom code model of this global if it has one.
void setAttributes(AttributeSet A)
Set attribute list for this global.
LLVM_ABI void replaceInitializer(Constant *InitVal)
replaceInitializer - Sets the initializer for this global variable, and sets the value type of the gl...
LLVM_ABI void clearCodeModel()
Remove the code model for this global.
LLVM_ABI void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
LLVM_ABI void setCodeModel(CodeModel::Model CM)
Change the code model for this global.
void setExternallyInitialized(bool Val)
LLVM_ABI void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
LLVM_ABI void dropAllReferences()
Drop all references in preparation to destroy the GlobalVariable.
LLVM_ABI 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 ...
DenseMap< const GlobalValue *, StringRef > GlobalValuePartitions
Collection of per-GlobalValue partitions used in this context.
DenseMap< const GlobalValue *, GlobalValue::SanitizerMetadata > GlobalValueSanitizerMetadata
DenseMap< const GlobalObject *, StringRef > GlobalObjectSections
Collection of per-GlobalObject sections used in this context.
LLVMContextImpl *const pImpl
LLVM_ABI MDNode * createGlobalObjectSectionPrefix(StringRef Prefix)
Return metadata containing the section prefix for a global object.
A Module instance is used to store all the information related to an LLVM module.
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
void removeIFunc(GlobalIFunc *IFunc)
Detach IFunc from the list but don't delete it.
void insertIFunc(GlobalIFunc *IFunc)
Insert IFunc at the end of the alias list and take ownership.
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
bool getSemanticInterposition() const
Returns whether semantic interposition is to be respected.
void removeAlias(GlobalAlias *Alias)
Detach Alias from the list but don't delete it.
void eraseIFunc(GlobalIFunc *IFunc)
Remove IFunc from the list and delete it.
void eraseAlias(GlobalAlias *Alias)
Remove Alias from the list and delete it.
void eraseGlobalVariable(GlobalVariable *GV)
Remove global variable GV from the list and delete it.
void insertGlobalVariable(GlobalVariable *GV)
Insert global variable GV at the end of the global variable list and take ownership.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void insertAlias(GlobalAlias *Alias)
Insert Alias at the end of the alias list and take ownership.
void removeGlobalVariable(GlobalVariable *GV)
Detach global variable GV from the list but don't delete it.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
bool isOSBinFormatXCOFF() const
Tests whether the OS uses the XCOFF binary format.
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
bool isFunctionTy() const
True if this is an instance of FunctionType.
StringRef save(const char *S)
void dropAllReferences()
Drop all references to operands.
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
static constexpr uint64_t MaximumAlignment
LLVM_ABI const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
unsigned getValueID() const
Return an ID for the concrete type of this object.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
std::pair< iterator, bool > insert(const ValueT &V)
An efficient, type-erasing, non-owning reference to a callable.
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
uint64_t MD5Hash(const FunctionId &Obj)
This is an optimization pass for GlobalISel generic memory operations.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
LLVM_ABI ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
DWARFExpression::Operation Op
constexpr char GlobalIdentifierDelimiter
This struct is a compact representation of a valid (non-zero power of two) alignment.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.