LLVM 21.0.0git
Globals.cpp
Go to the documentation of this file.
1//===-- Globals.cpp - Implement the GlobalValue & GlobalVariable class ----===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the GlobalValue & GlobalVariable classes for the IR
10// library.
11//
12//===----------------------------------------------------------------------===//
13
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/MDBuilder.h"
22#include "llvm/IR/Module.h"
23#include "llvm/Support/Error.h"
25#include "llvm/Support/MD5.h"
27using namespace llvm;
28
29//===----------------------------------------------------------------------===//
30// GlobalValue Class
31//===----------------------------------------------------------------------===//
32
33// GlobalValue should be a Constant, plus a type, a module, some flags, and an
34// intrinsic ID. Add an assert to prevent people from accidentally growing
35// GlobalValue while adding flags.
36static_assert(sizeof(GlobalValue) ==
37 sizeof(Constant) + 2 * sizeof(void *) + 2 * sizeof(unsigned),
38 "unexpected GlobalValue size growth");
39
40// GlobalObject adds a comdat.
41static_assert(sizeof(GlobalObject) == sizeof(GlobalValue) + sizeof(void *),
42 "unexpected GlobalObject size growth");
43
45 if (const Function *F = dyn_cast<Function>(this))
46 return F->isMaterializable();
47 return false;
48}
50
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()!");
55}
56
57Value *GlobalValue::handleOperandChangeImpl(Value *From, Value *To) {
58 llvm_unreachable("Unsupported class for handleOperandChange()!");
59}
60
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
74}
75
77 return MD5Hash(GlobalName);
78}
79
81 switch (getValueID()) {
82#define HANDLE_GLOBAL_VALUE(NAME) \
83 case Value::NAME##Val: \
84 return static_cast<NAME *>(this)->removeFromParent();
85#include "llvm/IR/Value.def"
86 default:
87 break;
88 }
89 llvm_unreachable("not a global");
90}
91
93 switch (getValueID()) {
94#define HANDLE_GLOBAL_VALUE(NAME) \
95 case Value::NAME##Val: \
96 return static_cast<NAME *>(this)->eraseFromParent();
97#include "llvm/IR/Value.def"
98 default:
99 break;
100 }
101 llvm_unreachable("not a global");
102}
103
105
108 return true;
110 !isDSOLocal();
111}
112
114 if (isTagged()) {
115 // Cannot create local aliases to MTE tagged globals. The address of a
116 // tagged global includes a tag that is assigned by the loader in the
117 // GOT.
118 return false;
119 }
120 // See AsmPrinter::getSymbolPreferLocal(). For a deduplicate comdat kind,
121 // references to a discarded local symbol from outside the group are not
122 // allowed, so avoid the local alias.
123 auto isDeduplicateComdat = [](const Comdat *C) {
124 return C && C->getSelectionKind() != Comdat::NoDeduplicate;
125 };
126 return hasDefaultVisibility() &&
128 !isa<GlobalIFunc>(this) && !isDeduplicateComdat(getComdat());
129}
130
132 return getParent()->getDataLayout();
133}
134
137 "Alignment is greater than MaximumAlignment!");
138 unsigned AlignmentData = encode(Align);
139 unsigned OldData = getGlobalValueSubClassData();
140 setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
141 assert(getAlign() == Align && "Alignment representation error!");
142}
143
146 "Alignment is greater than MaximumAlignment!");
147 unsigned AlignmentData = encode(Align);
148 unsigned OldData = getGlobalValueSubClassData();
149 setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
150 assert(getAlign() && *getAlign() == Align &&
151 "Alignment representation error!");
152}
153
156 setAlignment(Src->getAlign());
157 setSection(Src->getSection());
158}
159
162 StringRef FileName) {
163 // Value names may be prefixed with a binary '1' to indicate
164 // that the backend should not modify the symbols due to any platform
165 // naming convention. Do not include that '1' in the PGO profile name.
166 Name.consume_front("\1");
167
168 std::string GlobalName;
170 // For local symbols, prepend the main file name to distinguish them.
171 // Do not include the full path in the file name since there's no guarantee
172 // that it will stay the same, e.g., if the files are checked out from
173 // version control in different locations.
174 if (FileName.empty())
175 GlobalName += "<unknown>";
176 else
177 GlobalName += FileName;
178
179 GlobalName += GlobalIdentifierDelimiter;
180 }
181 GlobalName += Name;
182 return GlobalName;
183}
184
187 getParent()->getSourceFileName());
188}
189
191 if (auto *GA = dyn_cast<GlobalAlias>(this)) {
192 // In general we cannot compute this at the IR level, but we try.
193 if (const GlobalObject *GO = GA->getAliaseeObject())
194 return GO->getSection();
195 return "";
196 }
197 return cast<GlobalObject>(this)->getSection();
198}
199
201 if (auto *GA = dyn_cast<GlobalAlias>(this)) {
202 // In general we cannot compute this at the IR level, but we try.
203 if (const GlobalObject *GO = GA->getAliaseeObject())
204 return const_cast<GlobalObject *>(GO)->getComdat();
205 return nullptr;
206 }
207 // ifunc and its resolver are separate things so don't use resolver comdat.
208 if (isa<GlobalIFunc>(this))
209 return nullptr;
210 return cast<GlobalObject>(this)->getComdat();
211}
212
214 if (ObjComdat)
215 ObjComdat->removeUser(this);
216 ObjComdat = C;
217 if (C)
218 C->addUser(this);
219}
220
222 if (!hasPartition())
223 return "";
224 return getContext().pImpl->GlobalValuePartitions[this];
225}
226
228 // Do nothing if we're clearing the partition and it is already empty.
229 if (!hasPartition() && S.empty())
230 return;
231
232 // Get or create a stable partition name string and put it in the table in the
233 // context.
234 if (!S.empty())
235 S = getContext().pImpl->Saver.save(S);
237
238 // Update the HasPartition field. Setting the partition to the empty string
239 // means this global no longer has a partition.
240 HasPartition = !S.empty();
241}
242
246 assert(getContext().pImpl->GlobalValueSanitizerMetadata.count(this));
248}
249
253}
254
258 MetadataMap.erase(this);
259 HasSanitizerMetadata = false;
260}
261
264 Meta.NoAddress = true;
265 Meta.NoHWAddress = true;
267}
268
269StringRef GlobalObject::getSectionImpl() const {
271 return getContext().pImpl->GlobalObjectSections[this];
272}
273
275 // Do nothing if we're clearing the section and it is already empty.
276 if (!hasSection() && S.empty())
277 return;
278
279 // Get or create a stable section name string and put it in the table in the
280 // context.
281 if (!S.empty())
282 S = getContext().pImpl->Saver.save(S);
284
285 // Update the HasSectionHashEntryBit. Setting the section to the empty string
286 // means this global no longer has a section.
287 setGlobalObjectFlag(HasSectionHashEntryBit, !S.empty());
288}
289
291 MDBuilder MDB(getContext());
292 setMetadata(LLVMContext::MD_section_prefix,
294}
295
296std::optional<StringRef> GlobalObject::getSectionPrefix() const {
297 if (MDNode *MD = getMetadata(LLVMContext::MD_section_prefix)) {
298 [[maybe_unused]] StringRef MDName =
299 cast<MDString>(MD->getOperand(0))->getString();
300 assert((MDName == "section_prefix" ||
301 (isa<Function>(this) && MDName == "function_section_prefix")) &&
302 "Metadata not match");
303 return cast<MDString>(MD->getOperand(1))->getString();
304 }
305 return std::nullopt;
306}
307
308bool GlobalValue::isNobuiltinFnDef() const {
309 const Function *F = dyn_cast<Function>(this);
310 if (!F || F->empty())
311 return false;
312 return F->hasFnAttribute(Attribute::NoBuiltin);
313}
314
316 // Globals are definitions if they have an initializer.
317 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
318 return GV->getNumOperands() == 0;
319
320 // Functions are definitions if they have a body.
321 if (const Function *F = dyn_cast<Function>(this))
322 return F->empty() && !F->isMaterializable();
323
324 // Aliases and ifuncs are always definitions.
325 assert(isa<GlobalAlias>(this) || isa<GlobalIFunc>(this));
326 return false;
327}
328
330 // Firstly, can only increase the alignment of a global if it
331 // is a strong definition.
333 return false;
334
335 // It also has to either not have a section defined, or, not have
336 // alignment specified. (If it is assigned a section, the global
337 // could be densely packed with other objects in the section, and
338 // increasing the alignment could cause padding issues.)
339 if (hasSection() && getAlign())
340 return false;
341
342 // On ELF platforms, we're further restricted in that we can't
343 // increase the alignment of any variable which might be emitted
344 // into a shared library, and which is exported. If the main
345 // executable accesses a variable found in a shared-lib, the main
346 // exe actually allocates memory for and exports the symbol ITSELF,
347 // overriding the symbol found in the library. That is, at link
348 // time, the observed alignment of the variable is copied into the
349 // executable binary. (A COPY relocation is also generated, to copy
350 // the initial data from the shadowed variable in the shared-lib
351 // into the location in the main binary, before running code.)
352 //
353 // And thus, even though you might think you are defining the
354 // global, and allocating the memory for the global in your object
355 // file, and thus should be able to set the alignment arbitrarily,
356 // that's not actually true. Doing so can cause an ABI breakage; an
357 // executable might have already been built with the previous
358 // alignment of the variable, and then assuming an increased
359 // alignment will be incorrect.
360
361 // Conservatively assume ELF if there's no parent pointer.
362 bool isELF =
364 if (isELF && !isDSOLocal())
365 return false;
366
367 // GV with toc-data attribute is defined in a TOC entry. To mitigate TOC
368 // overflow, the alignment of such symbol should not be increased. Otherwise,
369 // padding is needed thus more TOC entries are wasted.
370 bool isXCOFF =
372 if (isXCOFF)
373 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
374 if (GV->hasAttribute("toc-data"))
375 return false;
376
377 return true;
378}
379
380template <typename Operation>
381static const GlobalObject *
383 const Operation &Op) {
384 if (auto *GO = dyn_cast<GlobalObject>(C)) {
385 Op(*GO);
386 return GO;
387 }
388 if (auto *GA = dyn_cast<GlobalAlias>(C)) {
389 Op(*GA);
390 if (Aliases.insert(GA).second)
391 return findBaseObject(GA->getOperand(0), Aliases, Op);
392 }
393 if (auto *CE = dyn_cast<ConstantExpr>(C)) {
394 switch (CE->getOpcode()) {
395 case Instruction::Add: {
396 auto *LHS = findBaseObject(CE->getOperand(0), Aliases, Op);
397 auto *RHS = findBaseObject(CE->getOperand(1), Aliases, Op);
398 if (LHS && RHS)
399 return nullptr;
400 return LHS ? LHS : RHS;
401 }
402 case Instruction::Sub: {
403 if (findBaseObject(CE->getOperand(1), Aliases, Op))
404 return nullptr;
405 return findBaseObject(CE->getOperand(0), Aliases, Op);
406 }
407 case Instruction::IntToPtr:
408 case Instruction::PtrToInt:
409 case Instruction::BitCast:
410 case Instruction::GetElementPtr:
411 return findBaseObject(CE->getOperand(0), Aliases, Op);
412 default:
413 break;
414 }
415 }
416 return nullptr;
417}
418
421 return findBaseObject(this, Aliases, [](const GlobalValue &) {});
422}
423
425 auto *GO = dyn_cast<GlobalObject>(this);
426 if (!GO)
427 return false;
428
429 return GO->getMetadata(LLVMContext::MD_absolute_symbol);
430}
431
432std::optional<ConstantRange> GlobalValue::getAbsoluteSymbolRange() const {
433 auto *GO = dyn_cast<GlobalObject>(this);
434 if (!GO)
435 return std::nullopt;
436
437 MDNode *MD = GO->getMetadata(LLVMContext::MD_absolute_symbol);
438 if (!MD)
439 return std::nullopt;
440
442}
443
446 return false;
447
448 // We assume that anyone who sets global unnamed_addr on a non-constant
449 // knows what they're doing.
451 return true;
452
453 // If it is a non constant variable, it needs to be uniqued across shared
454 // objects.
455 if (auto *Var = dyn_cast<GlobalVariable>(this))
456 if (!Var->isConstant())
457 return false;
458
460}
461
462//===----------------------------------------------------------------------===//
463// GlobalVariable Implementation
464//===----------------------------------------------------------------------===//
465
467 Constant *InitVal, const Twine &Name,
468 ThreadLocalMode TLMode, unsigned AddressSpace,
469 bool isExternallyInitialized)
470 : GlobalObject(Ty, Value::GlobalVariableVal, AllocMarker, Link, Name,
472 isConstantGlobal(constant),
473 isExternallyInitializedConstant(isExternallyInitialized) {
475 "invalid type for global variable");
476 setThreadLocalMode(TLMode);
477 if (InitVal) {
478 assert(InitVal->getType() == Ty &&
479 "Initializer should be the same type as the GlobalVariable!");
480 Op<0>() = InitVal;
481 } else {
482 setGlobalVariableNumOperands(0);
483 }
484}
485
487 LinkageTypes Link, Constant *InitVal,
489 ThreadLocalMode TLMode,
490 std::optional<unsigned> AddressSpace,
491 bool isExternallyInitialized)
492 : GlobalVariable(Ty, constant, Link, InitVal, Name, TLMode,
494 ? *AddressSpace
495 : M.getDataLayout().getDefaultGlobalsAddressSpace(),
496 isExternallyInitialized) {
497 if (Before)
498 Before->getParent()->insertGlobalVariable(Before->getIterator(), this);
499 else
500 M.insertGlobalVariable(this);
501}
502
505}
506
509}
510
512 if (!InitVal) {
513 if (hasInitializer()) {
514 // Note, the num operands is used to compute the offset of the operand, so
515 // the order here matters. Clearing the operand then clearing the num
516 // operands ensures we have the correct offset to the operand.
517 Op<0>().set(nullptr);
518 setGlobalVariableNumOperands(0);
519 }
520 } else {
521 assert(InitVal->getType() == getValueType() &&
522 "Initializer type must match GlobalVariable type");
523 // Note, the num operands is used to compute the offset of the operand, so
524 // the order here matters. We need to set num operands to 1 first so that
525 // we get the correct offset to the first operand when we set it.
526 if (!hasInitializer())
527 setGlobalVariableNumOperands(1);
528 Op<0>().set(InitVal);
529 }
530}
531
533 assert(InitVal && "Can't compute type of null initializer");
534 ValueType = InitVal->getType();
535 setInitializer(InitVal);
536}
537
538/// Copy all additional attributes (those not needed to create a GlobalVariable)
539/// from the GlobalVariable Src to this one.
542 setExternallyInitialized(Src->isExternallyInitialized());
543 setAttributes(Src->getAttributes());
544 if (auto CM = Src->getCodeModel())
545 setCodeModel(*CM);
546}
547
551}
552
554 unsigned CodeModelData = static_cast<unsigned>(CM) + 1;
555 unsigned OldData = getGlobalValueSubClassData();
556 unsigned NewData = (OldData & ~(CodeModelMask << CodeModelShift)) |
557 (CodeModelData << CodeModelShift);
559 assert(getCodeModel() == CM && "Code model representation error!");
560}
561
562//===----------------------------------------------------------------------===//
563// GlobalAlias Implementation
564//===----------------------------------------------------------------------===//
565
566GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
567 const Twine &Name, Constant *Aliasee,
568 Module *ParentModule)
569 : GlobalValue(Ty, Value::GlobalAliasVal, AllocMarker, Link, Name,
570 AddressSpace) {
571 setAliasee(Aliasee);
572 if (ParentModule)
573 ParentModule->insertAlias(this);
574}
575
577 LinkageTypes Link, const Twine &Name,
578 Constant *Aliasee, Module *ParentModule) {
579 return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
580}
581
583 LinkageTypes Linkage, const Twine &Name,
584 Module *Parent) {
585 return create(Ty, AddressSpace, Linkage, Name, nullptr, Parent);
586}
587
589 LinkageTypes Linkage, const Twine &Name,
590 GlobalValue *Aliasee) {
591 return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->getParent());
592}
593
595 GlobalValue *Aliasee) {
596 return create(Aliasee->getValueType(), Aliasee->getAddressSpace(), Link, Name,
597 Aliasee);
598}
599
601 return create(Aliasee->getLinkage(), Name, Aliasee);
602}
603
605
607
609 assert((!Aliasee || Aliasee->getType() == getType()) &&
610 "Alias and aliasee types should match!");
611 Op<0>().set(Aliasee);
612}
613
616 return findBaseObject(getOperand(0), Aliases, [](const GlobalValue &) {});
617}
618
619//===----------------------------------------------------------------------===//
620// GlobalIFunc Implementation
621//===----------------------------------------------------------------------===//
622
623GlobalIFunc::GlobalIFunc(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
624 const Twine &Name, Constant *Resolver,
625 Module *ParentModule)
626 : GlobalObject(Ty, Value::GlobalIFuncVal, AllocMarker, Link, Name,
627 AddressSpace) {
628 setResolver(Resolver);
629 if (ParentModule)
630 ParentModule->insertIFunc(this);
631}
632
634 LinkageTypes Link, const Twine &Name,
635 Constant *Resolver, Module *ParentModule) {
636 return new GlobalIFunc(Ty, AddressSpace, Link, Name, Resolver, ParentModule);
637}
638
640
642
644 return dyn_cast<Function>(getResolver()->stripPointerCastsAndAliases());
645}
646
648 function_ref<void(const GlobalValue &)> Op) const {
650 findBaseObject(getResolver(), Aliases, Op);
651}
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:382
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition: MD5.cpp:55
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:42
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
bool erase(const KeyT &Val)
Definition: DenseMap.h:321
Implements a dense probed hash-table based set.
Definition: DenseSet.h:278
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:606
const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:614
void setAliasee(Constant *Aliasee)
These methods retrieve and set alias target.
Definition: Globals.cpp:608
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:576
void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:604
void applyAlongResolverPath(function_ref< void(const GlobalValue &)> Op) const
Definition: Globals.cpp:647
const Function * getResolverFunction() const
Definition: Globals.cpp:643
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:639
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:633
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:641
const Constant * getResolver() const
Definition: GlobalIFunc.h:72
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
Definition: GlobalObject.h:79
void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
Definition: Metadata.cpp:1531
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
Definition: Globals.cpp:144
void setComdat(Comdat *C)
Definition: Globals.cpp:213
void copyAttributesFrom(const GlobalObject *Src)
Definition: Globals.cpp:154
void setSection(StringRef S)
Change the section for this global.
Definition: Globals.cpp:274
void setSectionPrefix(StringRef Prefix)
Set the section prefix for this global object.
Definition: Globals.cpp:290
std::optional< StringRef > getSectionPrefix() const
Get the section prefix for this global object.
Definition: Globals.cpp:296
void clearMetadata()
Erase all metadata attached to this Value.
Definition: Metadata.cpp:1603
bool hasSection() const
Check if this global has a custom object file section.
Definition: GlobalObject.h:109
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Value.h:565
bool canIncreaseAlignment() const
Returns true if the alignment of the value can be unilaterally increased.
Definition: Globals.cpp:329
unsigned HasSanitizerMetadata
True if this symbol has sanitizer metadata available.
Definition: GlobalValue.h:123
bool hasPartition() const
Definition: GlobalValue.h:310
const SanitizerMetadata & getSanitizerMetadata() const
Definition: Globals.cpp:244
bool isDSOLocal() const
Definition: GlobalValue.h:306
unsigned HasPartition
True if this symbol has a partition name assigned (see https://lld.llvm.org/Partitions....
Definition: GlobalValue.h:118
void removeSanitizerMetadata()
Definition: Globals.cpp:255
static bool isLocalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:410
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:315
LinkageTypes getLinkage() const
Definition: GlobalValue.h:547
void setUnnamedAddr(UnnamedAddr Val)
Definition: GlobalValue.h:232
bool hasDefaultVisibility() const
Definition: GlobalValue.h:250
bool isAbsoluteSymbolRef() const
Returns whether this is a reference to an absolute symbol.
Definition: Globals.cpp:424
bool isTagged() const
Definition: GlobalValue.h:366
void setDLLStorageClass(DLLStorageClassTypes C)
Definition: GlobalValue.h:285
const Comdat * getComdat() const
Definition: Globals.cpp:200
void setThreadLocalMode(ThreadLocalMode Val)
Definition: GlobalValue.h:268
bool hasSanitizerMetadata() const
Definition: GlobalValue.h:356
unsigned getAddressSpace() const
Definition: GlobalValue.h:206
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:596
StringRef getSection() const
Definition: Globals.cpp:190
StringRef getPartition() const
Definition: Globals.cpp:221
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:657
const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:419
void setDSOLocal(bool Local)
Definition: GlobalValue.h:304
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:432
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:92
static bool isExternalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:377
bool isStrongDefinitionForLinker() const
Returns true if this global's definition will be the one chosen by the linker.
Definition: GlobalValue.h:632
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:295
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
void setNoSanitizeMetadata()
Definition: Globals.cpp:262
bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
Definition: Globals.cpp:106
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:255
const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Definition: Globals.cpp:131
bool canBenefitFromLocalAlias() const
Definition: Globals.cpp:113
static bool isInterposableLinkage(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time.
Definition: GlobalValue.h:426
bool hasAtLeastLocalUnnamedAddr() const
Returns true if this value's address is not significant in this module.
Definition: GlobalValue.h:225
unsigned getGlobalValueSubClassData() const
Definition: GlobalValue.h:176
void setGlobalValueSubClassData(unsigned V)
Definition: GlobalValue.h:179
bool isMaterializable() const
If this function's Module is being lazily streamed in functions from disk or some other source,...
Definition: Globals.cpp:44
bool hasGlobalUnnamedAddr() const
Definition: GlobalValue.h:216
Error materialize()
Make sure this GlobalValue is fully read.
Definition: Globals.cpp:49
unsigned Linkage
Definition: GlobalValue.h:99
void setSanitizerMetadata(SanitizerMetadata Meta)
Definition: Globals.cpp:250
bool hasLinkOnceODRLinkage() const
Definition: GlobalValue.h:520
bool canBeOmittedFromSymbolTable() const
True if GV can be left out of the object symbol table.
Definition: Globals.cpp:444
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:80
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:185
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:51
Type * getValueType() const
Definition: GlobalValue.h:297
void setPartition(StringRef Part)
Definition: Globals.cpp:227
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
Definition: Globals.cpp:511
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:503
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.
void replaceInitializer(Constant *InitVal)
replaceInitializer - Sets the initializer for this global variable, and sets the value type of the gl...
Definition: Globals.cpp:532
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
Definition: Globals.cpp:540
void setCodeModel(CodeModel::Model CM)
Change the code model for this global.
Definition: Globals.cpp:553
void setExternallyInitialized(bool Val)
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:507
void dropAllReferences()
Drop all references in preparation to destroy the GlobalVariable.
Definition: Globals.cpp:548
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:466
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
MDNode * createGlobalObjectSectionPrefix(StringRef Prefix)
Return metadata containing the section prefix for a global object.
Definition: MDBuilder.cpp:90
Metadata node.
Definition: Metadata.h:1073
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:631
void insertIFunc(GlobalIFunc *IFunc)
Insert IFunc at the end of the alias list and take ownership.
Definition: Module.h:635
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
Definition: Module.cpp:468
bool getSemanticInterposition() const
Returns whether semantic interposition is to be respected.
Definition: Module.cpp:694
void removeAlias(GlobalAlias *Alias)
Detach Alias from the list but don't delete it.
Definition: Module.h:622
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition: Module.h:298
void eraseIFunc(GlobalIFunc *IFunc)
Remove IFunc from the list and delete it.
Definition: Module.h:633
void eraseAlias(GlobalAlias *Alias)
Remove Alias from the list and delete it.
Definition: Module.h:624
void eraseGlobalVariable(GlobalVariable *GV)
Remove global variable GV from the list and delete it.
Definition: Module.h:583
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.h:294
void insertAlias(GlobalAlias *Alias)
Insert Alias at the end of the alias list and take ownership.
Definition: Module.h:626
void removeGlobalVariable(GlobalVariable *GV)
Detach global variable GV from the list but don't delete it.
Definition: Module.h:581
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:863
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:51
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool isOSBinFormatXCOFF() const
Tests whether the OS uses the XCOFF binary format.
Definition: Triple.h:776
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:753
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:255
StringRef save(const char *S)
Definition: StringSaver.h:52
void dropAllReferences()
Drop all references to operands.
Definition: User.h:345
Value * getOperand(unsigned i) const
Definition: User.h:228
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:817
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
Definition: Value.cpp:698
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:1094
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:309
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:213
An efficient, type-erasing, non-owning reference to a callable.
#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
uint64_t MD5Hash(const FunctionId &Obj)
Definition: FunctionId.h:167
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
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
DWARFExpression::Operation Op
constexpr char GlobalIdentifierDelimiter
Definition: GlobalValue.h:46
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