LLVM 17.0.0git
Go to the documentation of this file.
1//===-- Globals.cpp - Implement the GlobalValue & GlobalVariable class ----===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9// This file implements the GlobalValue & GlobalVariable classes for the IR
10// library.
14#include "LLVMContextImpl.h"
16#include "llvm/IR/Constants.h"
18#include "llvm/IR/GlobalAlias.h"
19#include "llvm/IR/GlobalValue.h"
21#include "llvm/IR/Module.h"
22#include "llvm/Support/Error.h"
25using namespace llvm;
28// GlobalValue Class
31// GlobalValue should be a Constant, plus a type, a module, some flags, and an
32// intrinsic ID. Add an assert to prevent people from accidentally growing
33// GlobalValue while adding flags.
34static_assert(sizeof(GlobalValue) ==
35 sizeof(Constant) + 2 * sizeof(void *) + 2 * sizeof(unsigned),
36 "unexpected GlobalValue size growth");
38// GlobalObject adds a comdat.
39static_assert(sizeof(GlobalObject) == sizeof(GlobalValue) + sizeof(void *),
40 "unexpected GlobalObject size growth");
43 if (const Function *F = dyn_cast<Function>(this))
44 return F->isMaterializable();
45 return false;
48 return getParent()->materialize(this);
51/// Override destroyConstantImpl to make sure it doesn't get called on
52/// GlobalValue's because they shouldn't be treated like other constants.
53void GlobalValue::destroyConstantImpl() {
54 llvm_unreachable("You can't GV->destroyConstantImpl()!");
57Value *GlobalValue::handleOperandChangeImpl(Value *From, Value *To) {
58 llvm_unreachable("Unsupported class for handleOperandChange()!");
61/// copyAttributesFrom - copy all additional attributes (those not needed to
62/// create a GlobalValue) from the GlobalValue Src to this one.
64 setVisibility(Src->getVisibility());
65 setUnnamedAddr(Src->getUnnamedAddr());
66 setThreadLocalMode(Src->getThreadLocalMode());
67 setDLLStorageClass(Src->getDLLStorageClass());
68 setDSOLocal(Src->isDSOLocal());
69 setPartition(Src->getPartition());
70 if (Src->hasSanitizerMetadata())
71 setSanitizerMetadata(Src->getSanitizerMetadata());
72 else
77 switch (getValueID()) {
79 case Value::NAME##Val: \
80 return static_cast<NAME *>(this)->removeFromParent();
81#include "llvm/IR/Value.def"
82 default:
83 break;
84 }
85 llvm_unreachable("not a global");
89 switch (getValueID()) {
91 case Value::NAME##Val: \
92 return static_cast<NAME *>(this)->eraseFromParent();
93#include "llvm/IR/Value.def"
94 default:
95 break;
96 }
97 llvm_unreachable("not a global");
104 return true;
106 !isDSOLocal();
110 // See AsmPrinter::getSymbolPreferLocal(). For a deduplicate comdat kind,
111 // references to a discarded local symbol from outside the group are not
112 // allowed, so avoid the local alias.
113 auto isDeduplicateComdat = [](const Comdat *C) {
114 return C && C->getSelectionKind() != Comdat::NoDeduplicate;
115 };
116 return hasDefaultVisibility() &&
118 !isa<GlobalIFunc>(this) && !isDeduplicateComdat(getComdat());
123 "Alignment is greater than MaximumAlignment!");
124 unsigned AlignmentData = encode(Align);
125 unsigned OldData = getGlobalValueSubClassData();
126 setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
127 assert(getAlign() == Align && "Alignment representation error!");
132 "Alignment is greater than MaximumAlignment!");
133 unsigned AlignmentData = encode(Align);
134 unsigned OldData = getGlobalValueSubClassData();
135 setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
136 assert(getAlign() && *getAlign() == Align &&
137 "Alignment representation error!");
142 setAlignment(Src->getAlign());
143 setSection(Src->getSection());
148 StringRef FileName) {
150 // Value names may be prefixed with a binary '1' to indicate
151 // that the backend should not modify the symbols due to any platform
152 // naming convention. Do not include that '1' in the PGO profile name.
153 if (Name[0] == '\1')
154 Name = Name.substr(1);
156 std::string NewName = std::string(Name);
158 // For local symbols, prepend the main file name to distinguish them.
159 // Do not include the full path in the file name since there's no guarantee
160 // that it will stay the same, e.g., if the files are checked out from
161 // version control in different locations.
162 if (FileName.empty())
163 NewName = NewName.insert(0, "<unknown>:");
164 else
165 NewName = NewName.insert(0, FileName.str() + ":");
166 }
167 return NewName;
172 getParent()->getSourceFileName());
176 if (auto *GA = dyn_cast<GlobalAlias>(this)) {
177 // In general we cannot compute this at the IR level, but we try.
178 if (const GlobalObject *GO = GA->getAliaseeObject())
179 return GO->getSection();
180 return "";
181 }
182 return cast<GlobalObject>(this)->getSection();
186 if (auto *GA = dyn_cast<GlobalAlias>(this)) {
187 // In general we cannot compute this at the IR level, but we try.
188 if (const GlobalObject *GO = GA->getAliaseeObject())
189 return const_cast<GlobalObject *>(GO)->getComdat();
190 return nullptr;
191 }
192 // ifunc and its resolver are separate things so don't use resolver comdat.
193 if (isa<GlobalIFunc>(this))
194 return nullptr;
195 return cast<GlobalObject>(this)->getComdat();
199 if (ObjComdat)
200 ObjComdat->removeUser(this);
201 ObjComdat = C;
202 if (C)
203 C->addUser(this);
207 if (!hasPartition())
208 return "";
209 return getContext().pImpl->GlobalValuePartitions[this];
213 // Do nothing if we're clearing the partition and it is already empty.
214 if (!hasPartition() && S.empty())
215 return;
217 // Get or create a stable partition name string and put it in the table in the
218 // context.
219 if (!S.empty())
220 S = getContext().pImpl->Saver.save(S);
223 // Update the HasPartition field. Setting the partition to the empty string
224 // means this global no longer has a partition.
225 HasPartition = !S.empty();
231 assert(getContext().pImpl->GlobalValueSanitizerMetadata.count(this));
243 MetadataMap.erase(this);
244 HasSanitizerMetadata = false;
247StringRef GlobalObject::getSectionImpl() const {
249 return getContext().pImpl->GlobalObjectSections[this];
253 // Do nothing if we're clearing the section and it is already empty.
254 if (!hasSection() && S.empty())
255 return;
257 // Get or create a stable section name string and put it in the table in the
258 // context.
259 if (!S.empty())
260 S = getContext().pImpl->Saver.save(S);
263 // Update the HasSectionHashEntryBit. Setting the section to the empty string
264 // means this global no longer has a section.
265 setGlobalObjectFlag(HasSectionHashEntryBit, !S.empty());
268bool GlobalValue::isNobuiltinFnDef() const {
269 const Function *F = dyn_cast<Function>(this);
270 if (!F || F->empty())
271 return false;
272 return F->hasFnAttribute(Attribute::NoBuiltin);
276 // Globals are definitions if they have an initializer.
277 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
278 return GV->getNumOperands() == 0;
280 // Functions are definitions if they have a body.
281 if (const Function *F = dyn_cast<Function>(this))
282 return F->empty() && !F->isMaterializable();
284 // Aliases and ifuncs are always definitions.
285 assert(isa<GlobalAlias>(this) || isa<GlobalIFunc>(this));
286 return false;
290 // Firstly, can only increase the alignment of a global if it
291 // is a strong definition.
293 return false;
295 // It also has to either not have a section defined, or, not have
296 // alignment specified. (If it is assigned a section, the global
297 // could be densely packed with other objects in the section, and
298 // increasing the alignment could cause padding issues.)
299 if (hasSection() && getAlign())
300 return false;
302 // On ELF platforms, we're further restricted in that we can't
303 // increase the alignment of any variable which might be emitted
304 // into a shared library, and which is exported. If the main
305 // executable accesses a variable found in a shared-lib, the main
306 // exe actually allocates memory for and exports the symbol ITSELF,
307 // overriding the symbol found in the library. That is, at link
308 // time, the observed alignment of the variable is copied into the
309 // executable binary. (A COPY relocation is also generated, to copy
310 // the initial data from the shadowed variable in the shared-lib
311 // into the location in the main binary, before running code.)
312 //
313 // And thus, even though you might think you are defining the
314 // global, and allocating the memory for the global in your object
315 // file, and thus should be able to set the alignment arbitrarily,
316 // that's not actually true. Doing so can cause an ABI breakage; an
317 // executable might have already been built with the previous
318 // alignment of the variable, and then assuming an increased
319 // alignment will be incorrect.
321 // Conservatively assume ELF if there's no parent pointer.
322 bool isELF =
324 if (isELF && !isDSOLocal())
325 return false;
327 return true;
330template <typename Operation>
331static const GlobalObject *
333 const Operation &Op) {
334 if (auto *GO = dyn_cast<GlobalObject>(C)) {
335 Op(*GO);
336 return GO;
337 }
338 if (auto *GA = dyn_cast<GlobalAlias>(C)) {
339 Op(*GA);
340 if (Aliases.insert(GA).second)
341 return findBaseObject(GA->getOperand(0), Aliases, Op);
342 }
343 if (auto *CE = dyn_cast<ConstantExpr>(C)) {
344 switch (CE->getOpcode()) {
345 case Instruction::Add: {
346 auto *LHS = findBaseObject(CE->getOperand(0), Aliases, Op);
347 auto *RHS = findBaseObject(CE->getOperand(1), Aliases, Op);
348 if (LHS && RHS)
349 return nullptr;
350 return LHS ? LHS : RHS;
351 }
352 case Instruction::Sub: {
353 if (findBaseObject(CE->getOperand(1), Aliases, Op))
354 return nullptr;
355 return findBaseObject(CE->getOperand(0), Aliases, Op);
356 }
357 case Instruction::IntToPtr:
358 case Instruction::PtrToInt:
359 case Instruction::BitCast:
360 case Instruction::GetElementPtr:
361 return findBaseObject(CE->getOperand(0), Aliases, Op);
362 default:
363 break;
364 }
365 }
366 return nullptr;
371 return findBaseObject(this, Aliases, [](const GlobalValue &) {});
375 auto *GO = dyn_cast<GlobalObject>(this);
376 if (!GO)
377 return false;
379 return GO->getMetadata(LLVMContext::MD_absolute_symbol);
382std::optional<ConstantRange> GlobalValue::getAbsoluteSymbolRange() const {
383 auto *GO = dyn_cast<GlobalObject>(this);
384 if (!GO)
385 return std::nullopt;
387 MDNode *MD = GO->getMetadata(LLVMContext::MD_absolute_symbol);
388 if (!MD)
389 return std::nullopt;
396 return false;
398 // We assume that anyone who sets global unnamed_addr on a non-constant
399 // knows what they're doing.
401 return true;
403 // If it is a non constant variable, it needs to be uniqued across shared
404 // objects.
405 if (auto *Var = dyn_cast<GlobalVariable>(this))
406 if (!Var->isConstant())
407 return false;
413// GlobalVariable Implementation
417 Constant *InitVal, const Twine &Name,
418 ThreadLocalMode TLMode, unsigned AddressSpace,
419 bool isExternallyInitialized)
420 : GlobalObject(Ty, Value::GlobalVariableVal,
421 OperandTraits<GlobalVariable>::op_begin(this),
422 InitVal != nullptr, Link, Name, AddressSpace),
423 isConstantGlobal(constant),
424 isExternallyInitializedConstant(isExternallyInitialized) {
426 "invalid type for global variable");
427 setThreadLocalMode(TLMode);
428 if (InitVal) {
429 assert(InitVal->getType() == Ty &&
430 "Initializer should be the same type as the GlobalVariable!");
431 Op<0>() = InitVal;
432 }
436 LinkageTypes Link, Constant *InitVal,
437 const Twine &Name, GlobalVariable *Before,
438 ThreadLocalMode TLMode,
439 std::optional<unsigned> AddressSpace,
440 bool isExternallyInitialized)
441 : GlobalObject(Ty, Value::GlobalVariableVal,
442 OperandTraits<GlobalVariable>::op_begin(this),
443 InitVal != nullptr, Link, Name,
445 ? *AddressSpace
446 : M.getDataLayout().getDefaultGlobalsAddressSpace()),
447 isConstantGlobal(constant),
448 isExternallyInitializedConstant(isExternallyInitialized) {
450 "invalid type for global variable");
451 setThreadLocalMode(TLMode);
452 if (InitVal) {
453 assert(InitVal->getType() == Ty &&
454 "Initializer should be the same type as the GlobalVariable!");
455 Op<0>() = InitVal;
456 }
458 if (Before)
459 Before->getParent()->insertGlobalVariable(Before->getIterator(), this);
460 else
461 M.insertGlobalVariable(this);
473 if (!InitVal) {
474 if (hasInitializer()) {
475 // Note, the num operands is used to compute the offset of the operand, so
476 // the order here matters. Clearing the operand then clearing the num
477 // operands ensures we have the correct offset to the operand.
478 Op<0>().set(nullptr);
480 }
481 } else {
482 assert(InitVal->getType() == getValueType() &&
483 "Initializer type must match GlobalVariable type");
484 // Note, the num operands is used to compute the offset of the operand, so
485 // the order here matters. We need to set num operands to 1 first so that
486 // we get the correct offset to the first operand when we set it.
487 if (!hasInitializer())
489 Op<0>().set(InitVal);
490 }
493/// Copy all additional attributes (those not needed to create a GlobalVariable)
494/// from the GlobalVariable Src to this one.
497 setExternallyInitialized(Src->isExternallyInitialized());
498 setAttributes(Src->getAttributes());
507// GlobalAlias Implementation
510GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
511 const Twine &Name, Constant *Aliasee,
512 Module *ParentModule)
513 : GlobalValue(Ty, Value::GlobalAliasVal, &Op<0>(), 1, Link, Name,
514 AddressSpace) {
515 setAliasee(Aliasee);
516 if (ParentModule)
517 ParentModule->insertAlias(this);
521 LinkageTypes Link, const Twine &Name,
522 Constant *Aliasee, Module *ParentModule) {
523 return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
527 LinkageTypes Linkage, const Twine &Name,
528 Module *Parent) {
529 return create(Ty, AddressSpace, Linkage, Name, nullptr, Parent);
533 LinkageTypes Linkage, const Twine &Name,
534 GlobalValue *Aliasee) {
535 return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->getParent());
539 GlobalValue *Aliasee) {
540 return create(Aliasee->getValueType(), Aliasee->getAddressSpace(), Link, Name,
541 Aliasee);
545 return create(Aliasee->getLinkage(), Name, Aliasee);
549 getParent()->removeAlias(this);
553 getParent()->eraseAlias(this);
557 assert((!Aliasee || Aliasee->getType() == getType()) &&
558 "Alias and aliasee types should match!");
559 Op<0>().set(Aliasee);
564 return findBaseObject(getOperand(0), Aliases, [](const GlobalValue &) {});
568// GlobalIFunc Implementation
571GlobalIFunc::GlobalIFunc(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
572 const Twine &Name, Constant *Resolver,
573 Module *ParentModule)
574 : GlobalObject(Ty, Value::GlobalIFuncVal, &Op<0>(), 1, Link, Name,
575 AddressSpace) {
576 setResolver(Resolver);
577 if (ParentModule)
578 ParentModule->insertIFunc(this);
582 LinkageTypes Link, const Twine &Name,
583 Constant *Resolver, Module *ParentModule) {
584 return new GlobalIFunc(Ty, AddressSpace, Link, Name, Resolver, ParentModule);
592 return dyn_cast<Function>(getResolver()->stripPointerCastsAndAliases());
596 function_ref<void(const GlobalValue &)> Op) const {
598 findBaseObject(getResolver(), Aliases, Op);
BlockVerifier::State From
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::string Name
static const GlobalObject * findBaseObject(const Constant *C, DenseSet< const GlobalAlias * > &Aliases, const Operation &Op)
Definition: Globals.cpp:332
#define F(x, y, z)
Definition: MD5.cpp:55
Module.h This file contains the declarations for the Module class.
PowerPC Reduce CR logical Operation
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * RHS
Value * LHS
@ NoDeduplicate
No deduplication is performed.
Definition: Comdat.h:39
This is an important base class in LLVM.
Definition: Constant.h:41
bool erase(const KeyT &Val)
Definition: DenseMap.h:315
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:552
const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:562
void setAliasee(Constant *Aliasee)
These methods retrieve and set alias target.
Definition: Globals.cpp:556
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...
Definition: Globals.cpp:520
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:548
void applyAlongResolverPath(function_ref< void(const GlobalValue &)> Op) const
Definition: Globals.cpp:595
const Function * getResolverFunction() const
Definition: Globals.cpp:591
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:587
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...
Definition: Globals.cpp:581
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:589
const Constant * getResolver() const
Definition: GlobalIFunc.h:70
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
Definition: GlobalObject.h:79
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
Definition: Globals.cpp:130
void setComdat(Comdat *C)
Definition: Globals.cpp:198
void copyAttributesFrom(const GlobalObject *Src)
Definition: Globals.cpp:140
void setSection(StringRef S)
Change the section for this global.
Definition: Globals.cpp:252
void clearMetadata()
Erase all metadata attached to this Value.
Definition: Metadata.cpp:1382
bool hasSection() const
Check if this global has a custom object file section.
Definition: GlobalObject.h:109
bool canIncreaseAlignment() const
Returns true if the alignment of the value can be unilaterally increased.
Definition: Globals.cpp:289
unsigned HasSanitizerMetadata
True if this symbol has sanitizer metadata available.
Definition: GlobalValue.h:118
bool hasPartition() const
Definition: GlobalValue.h:305
const SanitizerMetadata & getSanitizerMetadata() const
Definition: Globals.cpp:229
bool isDSOLocal() const
Definition: GlobalValue.h:301
unsigned HasPartition
True if this symbol has a partition name assigned (see https://lld.llvm.org/Partitions....
Definition: GlobalValue.h:113
void removeSanitizerMetadata()
Definition: Globals.cpp:240
static bool isLocalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:404
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:275
LinkageTypes getLinkage() const
Definition: GlobalValue.h:541
void setUnnamedAddr(UnnamedAddr Val)
Definition: GlobalValue.h:227
bool hasDefaultVisibility() const
Definition: GlobalValue.h:245
bool isAbsoluteSymbolRef() const
Returns whether this is a reference to an absolute symbol.
Definition: Globals.cpp:374
void setDLLStorageClass(DLLStorageClassTypes C)
Definition: GlobalValue.h:280
const Comdat * getComdat() const
Definition: Globals.cpp:185
void setThreadLocalMode(ThreadLocalMode Val)
Definition: GlobalValue.h:263
bool hasSanitizerMetadata() const
Definition: GlobalValue.h:351
unsigned getAddressSpace() const
Definition: GlobalValue.h:201
StringRef getSection() const
Definition: Globals.cpp:175
StringRef getPartition() const
Definition: Globals.cpp:206
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:652
const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:369
void setDSOLocal(bool Local)
Definition: GlobalValue.h:299
std::optional< ConstantRange > getAbsoluteSymbolRange() const
If this is an absolute symbol reference, returns the range of the symbol, otherwise returns std::null...
Definition: Globals.cpp:382
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:88
static bool isExternalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:371
bool isStrongDefinitionForLinker() const
Returns true if this global's definition will be the one chosen by the linker.
Definition: GlobalValue.h:627
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:290
void copyAttributesFrom(const GlobalValue *Src)
Copy all additional attributes (those not needed to create a GlobalValue) from the GlobalValue Src to...
Definition: Globals.cpp:63
bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
Definition: Globals.cpp:102
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:250
bool canBenefitFromLocalAlias() const
Definition: Globals.cpp:109
static bool isInterposableLinkage(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time.
Definition: GlobalValue.h:420
bool hasAtLeastLocalUnnamedAddr() const
Returns true if this value's address is not significant in this module.
Definition: GlobalValue.h:220
unsigned getGlobalValueSubClassData() const
Definition: GlobalValue.h:171
void setGlobalValueSubClassData(unsigned V)
Definition: GlobalValue.h:174
bool isMaterializable() const
If this function's Module is being lazily streamed in functions from disk or some other source,...
Definition: Globals.cpp:42
bool hasGlobalUnnamedAddr() const
Definition: GlobalValue.h:211
Error materialize()
Make sure this GlobalValue is fully read.
Definition: Globals.cpp:47
unsigned Linkage
Definition: GlobalValue.h:94
void setSanitizerMetadata(SanitizerMetadata Meta)
Definition: Globals.cpp:235
bool hasLinkOnceODRLinkage() const
Definition: GlobalValue.h:514
bool canBeOmittedFromSymbolTable() const
True if GV can be left out of the object symbol table.
Definition: Globals.cpp:394
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:76
std::string getGlobalIdentifier() const
Return the modified name for this global value suitable to be used as the key for a global lookup (e....
Definition: Globals.cpp:170
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
Type * getValueType() const
Definition: GlobalValue.h:292
void setPartition(StringRef Part)
Definition: Globals.cpp:212
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
Definition: Globals.cpp:472
bool hasInitializer() const
Definitions have initializers, declarations don't.
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:464
void setAttributes(AttributeSet A)
Set attribute list for this global.
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
Definition: Globals.cpp:495
void setExternallyInitialized(bool Val)
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:468
void dropAllReferences()
Drop all references in preparation to destroy the GlobalVariable.
Definition: Globals.cpp:501
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 ...
Definition: Globals.cpp:416
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.
UniqueStringSaver Saver
LLVMContextImpl *const pImpl
Definition: LLVMContext.h:69
Metadata node.
Definition: Metadata.h:943
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
void removeIFunc(GlobalIFunc *IFunc)
Detach IFunc from the list but don't delete it.
Definition: Module.h:596
void insertIFunc(GlobalIFunc *IFunc)
Insert IFunc at the end of the alias list and take ownership.
Definition: Module.h:600
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
Definition: Module.cpp:439
bool getSemanticInterposition() const
Returns whether semantic interposition is to be respected.
Definition: Module.cpp:648
void removeAlias(GlobalAlias *Alias)
Detach Alias from the list but don't delete it.
Definition: Module.h:587
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition: Module.h:258
void eraseIFunc(GlobalIFunc *IFunc)
Remove IFunc from the list and delete it.
Definition: Module.h:598
void eraseAlias(GlobalAlias *Alias)
Remove Alias from the list and delete it.
Definition: Module.h:589
void eraseGlobalVariable(GlobalVariable *GV)
Remove global variable GV from the list and delete it.
Definition: Module.h:548
void insertGlobalVariable(GlobalVariable *GV)
Insert global variable GV at the end of the global variable list and take ownership.
Definition: Module.h:551
void insertAlias(GlobalAlias *Alias)
Insert Alias at the end of the alias list and take ownership.
Definition: Module.h:591
void removeGlobalVariable(GlobalVariable *GV)
Detach global variable GV from the list but don't delete it.
Definition: Module.h:546
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:795
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:2148
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:222
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:675
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isFunctionTy() const
True if this is an instance of FunctionType.
Definition: Type.h:249
StringRef save(const char *S)
Definition: StringSaver.h:52
void dropAllReferences()
Drop all references to operands.
Definition: User.h:299
Use & Op()
Definition: User.h:133
void setGlobalVariableNumOperands(unsigned NumOps)
Set the number of operands on a GlobalVariable.
Definition: User.h:207
Value * getOperand(unsigned i) const
Definition: User.h:169
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
static constexpr uint64_t MaximumAlignment
Definition: Value.h:790
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
Definition: Value.cpp:689
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:532
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:994
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:308
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
An efficient, type-erasing, non-owning reference to a callable.
self_iterator getIterator()
Definition: ilist_node.h:82
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
Definition: Alignment.h:217
Definition: NVPTXBaseInfo.h:21
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
Compile-time customization of User operands.
Definition: User.h:42