LLVM 22.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
78 return MD5Hash(GlobalIdentifier);
79}
80
82 switch (getValueID()) {
83#define HANDLE_GLOBAL_VALUE(NAME) \
84 case Value::NAME##Val: \
85 return static_cast<NAME *>(this)->removeFromParent();
86#include "llvm/IR/Value.def"
87 default:
88 break;
89 }
90 llvm_unreachable("not a global");
91}
92
94 switch (getValueID()) {
95#define HANDLE_GLOBAL_VALUE(NAME) \
96 case Value::NAME##Val: \
97 return static_cast<NAME *>(this)->eraseFromParent();
98#include "llvm/IR/Value.def"
99 default:
100 break;
101 }
102 llvm_unreachable("not a global");
103}
104
106
109 return true;
111 !isDSOLocal();
112}
113
115 if (isTagged()) {
116 // Cannot create local aliases to MTE tagged globals. The address of a
117 // tagged global includes a tag that is assigned by the loader in the
118 // GOT.
119 return false;
120 }
121 // See AsmPrinter::getSymbolPreferLocal(). For a deduplicate comdat kind,
122 // references to a discarded local symbol from outside the group are not
123 // allowed, so avoid the local alias.
124 auto isDeduplicateComdat = [](const Comdat *C) {
125 return C && C->getSelectionKind() != Comdat::NoDeduplicate;
126 };
127 return hasDefaultVisibility() &&
129 !isa<GlobalIFunc>(this) && !isDeduplicateComdat(getComdat());
130}
131
133 return getParent()->getDataLayout();
134}
135
138 "Alignment is greater than MaximumAlignment!");
139 unsigned AlignmentData = encode(Align);
140 unsigned OldData = getGlobalValueSubClassData();
141 setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
142 assert(getAlign() == Align && "Alignment representation error!");
143}
144
147 "Alignment is greater than MaximumAlignment!");
148 unsigned AlignmentData = encode(Align);
149 unsigned OldData = getGlobalValueSubClassData();
150 setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
151 assert(getAlign() && *getAlign() == Align &&
152 "Alignment representation error!");
153}
154
157 setAlignment(Src->getAlign());
158 setSection(Src->getSection());
159}
160
161std::string GlobalValue::getGlobalIdentifier(StringRef Name,
163 StringRef FileName) {
164 // Value names may be prefixed with a binary '1' to indicate
165 // that the backend should not modify the symbols due to any platform
166 // naming convention. Do not include that '1' in the PGO profile name.
167 Name.consume_front("\1");
168
169 std::string GlobalName;
171 // For local symbols, prepend the main file name to distinguish them.
172 // Do not include the full path in the file name since there's no guarantee
173 // that it will stay the same, e.g., if the files are checked out from
174 // version control in different locations.
175 if (FileName.empty())
176 GlobalName += "<unknown>";
177 else
178 GlobalName += FileName;
179
180 GlobalName += GlobalIdentifierDelimiter;
181 }
182 GlobalName += Name;
183 return GlobalName;
184}
185
186std::string GlobalValue::getGlobalIdentifier() const {
187 return getGlobalIdentifier(getName(), getLinkage(),
188 getParent()->getSourceFileName());
189}
190
192 if (auto *GA = dyn_cast<GlobalAlias>(this)) {
193 // In general we cannot compute this at the IR level, but we try.
194 if (const GlobalObject *GO = GA->getAliaseeObject())
195 return GO->getSection();
196 return "";
197 }
198 return cast<GlobalObject>(this)->getSection();
199}
200
202 if (auto *GA = dyn_cast<GlobalAlias>(this)) {
203 // In general we cannot compute this at the IR level, but we try.
204 if (const GlobalObject *GO = GA->getAliaseeObject())
205 return const_cast<GlobalObject *>(GO)->getComdat();
206 return nullptr;
207 }
208 // ifunc and its resolver are separate things so don't use resolver comdat.
209 if (isa<GlobalIFunc>(this))
210 return nullptr;
211 return cast<GlobalObject>(this)->getComdat();
212}
213
215 if (ObjComdat)
216 ObjComdat->removeUser(this);
217 ObjComdat = C;
218 if (C)
219 C->addUser(this);
220}
221
223 if (!hasPartition())
224 return "";
225 return getContext().pImpl->GlobalValuePartitions[this];
226}
227
229 // Do nothing if we're clearing the partition and it is already empty.
230 if (!hasPartition() && S.empty())
231 return;
232
233 // Get or create a stable partition name string and put it in the table in the
234 // context.
235 if (!S.empty())
236 S = getContext().pImpl->Saver.save(S);
238
239 // Update the HasPartition field. Setting the partition to the empty string
240 // means this global no longer has a partition.
241 HasPartition = !S.empty();
242}
243
247 assert(getContext().pImpl->GlobalValueSanitizerMetadata.count(this));
249}
250
254}
255
259 MetadataMap.erase(this);
260 HasSanitizerMetadata = false;
261}
262
265 Meta.NoAddress = true;
266 Meta.NoHWAddress = true;
268}
269
270StringRef GlobalObject::getSectionImpl() const {
272 return getContext().pImpl->GlobalObjectSections[this];
273}
274
276 // Do nothing if we're clearing the section and it is already empty.
277 if (!hasSection() && S.empty())
278 return;
279
280 // Get or create a stable section name string and put it in the table in the
281 // context.
282 if (!S.empty())
283 S = getContext().pImpl->Saver.save(S);
285
286 // Update the HasSectionHashEntryBit. Setting the section to the empty string
287 // means this global no longer has a section.
288 setGlobalObjectFlag(HasSectionHashEntryBit, !S.empty());
289}
290
292 MDBuilder MDB(getContext());
293 setMetadata(LLVMContext::MD_section_prefix,
295}
296
297std::optional<StringRef> GlobalObject::getSectionPrefix() const {
298 if (MDNode *MD = getMetadata(LLVMContext::MD_section_prefix)) {
299 [[maybe_unused]] StringRef MDName =
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();
305 }
306 return std::nullopt;
307}
308
309bool GlobalValue::isNobuiltinFnDef() const {
310 const Function *F = dyn_cast<Function>(this);
311 if (!F || F->empty())
312 return false;
313 return F->hasFnAttribute(Attribute::NoBuiltin);
314}
315
317 // Globals are definitions if they have an initializer.
318 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
319 return GV->getNumOperands() == 0;
320
321 // Functions are definitions if they have a body.
322 if (const Function *F = dyn_cast<Function>(this))
323 return F->empty() && !F->isMaterializable();
324
325 // Aliases and ifuncs are always definitions.
326 assert(isa<GlobalAlias>(this) || isa<GlobalIFunc>(this));
327 return false;
328}
329
331 // Firstly, can only increase the alignment of a global if it
332 // is a strong definition.
334 return false;
335
336 // It also has to either not have a section defined, or, not have
337 // alignment specified. (If it is assigned a section, the global
338 // could be densely packed with other objects in the section, and
339 // increasing the alignment could cause padding issues.)
340 if (hasSection() && getAlign())
341 return false;
342
343 // On ELF platforms, we're further restricted in that we can't
344 // increase the alignment of any variable which might be emitted
345 // into a shared library, and which is exported. If the main
346 // executable accesses a variable found in a shared-lib, the main
347 // exe actually allocates memory for and exports the symbol ITSELF,
348 // overriding the symbol found in the library. That is, at link
349 // time, the observed alignment of the variable is copied into the
350 // executable binary. (A COPY relocation is also generated, to copy
351 // the initial data from the shadowed variable in the shared-lib
352 // into the location in the main binary, before running code.)
353 //
354 // And thus, even though you might think you are defining the
355 // global, and allocating the memory for the global in your object
356 // file, and thus should be able to set the alignment arbitrarily,
357 // that's not actually true. Doing so can cause an ABI breakage; an
358 // executable might have already been built with the previous
359 // alignment of the variable, and then assuming an increased
360 // alignment will be incorrect.
361
362 // Conservatively assume ELF if there's no parent pointer.
363 bool isELF = (!Parent || Parent->getTargetTriple().isOSBinFormatELF());
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 = (!Parent || Parent->getTargetTriple().isOSBinFormatXCOFF());
371 if (isXCOFF)
372 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
373 if (GV->hasAttribute("toc-data"))
374 return false;
375
376 return true;
377}
378
379template <typename Operation>
380static const GlobalObject *
382 const Operation &Op) {
383 if (auto *GO = dyn_cast<GlobalObject>(C)) {
384 Op(*GO);
385 return GO;
386 }
387 if (auto *GA = dyn_cast<GlobalAlias>(C)) {
388 Op(*GA);
389 if (Aliases.insert(GA).second)
390 return findBaseObject(GA->getOperand(0), Aliases, Op);
391 }
392 if (auto *CE = dyn_cast<ConstantExpr>(C)) {
393 switch (CE->getOpcode()) {
394 case Instruction::Add: {
395 auto *LHS = findBaseObject(CE->getOperand(0), Aliases, Op);
396 auto *RHS = findBaseObject(CE->getOperand(1), Aliases, Op);
397 if (LHS && RHS)
398 return nullptr;
399 return LHS ? LHS : RHS;
400 }
401 case Instruction::Sub: {
402 if (findBaseObject(CE->getOperand(1), Aliases, Op))
403 return nullptr;
404 return findBaseObject(CE->getOperand(0), Aliases, Op);
405 }
406 case Instruction::IntToPtr:
407 case Instruction::PtrToAddr:
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,
488 const Twine &Name, GlobalVariable *Before,
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
563 unsigned CodeModelData = 0;
564 unsigned OldData = getGlobalValueSubClassData();
565 unsigned NewData = (OldData & ~(CodeModelMask << CodeModelShift)) |
566 (CodeModelData << CodeModelShift);
568 assert(getCodeModel() == std::nullopt && "Code model representation error!");
569}
570
571//===----------------------------------------------------------------------===//
572// GlobalAlias Implementation
573//===----------------------------------------------------------------------===//
574
575GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
576 const Twine &Name, Constant *Aliasee,
577 Module *ParentModule)
578 : GlobalValue(Ty, Value::GlobalAliasVal, AllocMarker, Link, Name,
579 AddressSpace) {
580 setAliasee(Aliasee);
581 if (ParentModule)
582 ParentModule->insertAlias(this);
583}
584
586 LinkageTypes Link, const Twine &Name,
587 Constant *Aliasee, Module *ParentModule) {
588 return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
589}
590
592 LinkageTypes Linkage, const Twine &Name,
593 Module *Parent) {
594 return create(Ty, AddressSpace, Linkage, Name, nullptr, Parent);
595}
596
598 LinkageTypes Linkage, const Twine &Name,
599 GlobalValue *Aliasee) {
600 return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->getParent());
601}
602
604 GlobalValue *Aliasee) {
605 return create(Aliasee->getValueType(), Aliasee->getAddressSpace(), Link, Name,
606 Aliasee);
607}
608
610 return create(Aliasee->getLinkage(), Name, Aliasee);
611}
612
614
616
618 assert((!Aliasee || Aliasee->getType() == getType()) &&
619 "Alias and aliasee types should match!");
620 Op<0>().set(Aliasee);
621}
622
625 return findBaseObject(getOperand(0), Aliases, [](const GlobalValue &) {});
626}
627
628//===----------------------------------------------------------------------===//
629// GlobalIFunc Implementation
630//===----------------------------------------------------------------------===//
631
632GlobalIFunc::GlobalIFunc(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
633 const Twine &Name, Constant *Resolver,
634 Module *ParentModule)
635 : GlobalObject(Ty, Value::GlobalIFuncVal, AllocMarker, Link, Name,
636 AddressSpace) {
637 setResolver(Resolver);
638 if (ParentModule)
639 ParentModule->insertIFunc(this);
640}
641
643 LinkageTypes Link, const Twine &Name,
644 Constant *Resolver, Module *ParentModule) {
645 return new GlobalIFunc(Ty, AddressSpace, Link, Name, Resolver, ParentModule);
646}
647
649
651
653 return dyn_cast<Function>(getResolver()->stripPointerCastsAndAliases());
654}
655
657 function_ref<void(const GlobalValue &)> Op) const {
659 findBaseObject(getResolver(), Aliases, Op);
660}
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...
std::string Name
static const GlobalObject * findBaseObject(const Constant *C, DenseSet< const GlobalAlias * > &Aliases, const Operation &Op)
Definition: Globals.cpp:381
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
Value * RHS
Value * LHS
@ NoDeduplicate
No deduplication is performed.
Definition: Comdat.h:40
This is an important base class in LLVM.
Definition: Constant.h:43
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:319
Implements a dense probed hash-table based set.
Definition: DenseSet.h:263
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
LLVM_ABI void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:615
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:623
LLVM_ABI void setAliasee(Constant *Aliasee)
These methods retrieve and set alias target.
Definition: Globals.cpp:617
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...
Definition: Globals.cpp:585
LLVM_ABI void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:613
LLVM_ABI void applyAlongResolverPath(function_ref< void(const GlobalValue &)> Op) const
Definition: Globals.cpp:656
LLVM_ABI const Function * getResolverFunction() const
Definition: Globals.cpp:652
LLVM_ABI void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:648
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...
Definition: Globals.cpp:642
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:650
const Constant * getResolver() const
Definition: GlobalIFunc.h:73
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
Definition: GlobalObject.h:75
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
Definition: Metadata.cpp:1571
LLVM_ABI void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
Definition: Globals.cpp:145
LLVM_ABI void setComdat(Comdat *C)
Definition: Globals.cpp:214
LLVM_ABI void copyAttributesFrom(const GlobalObject *Src)
Definition: Globals.cpp:155
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
Definition: Globals.cpp:275
LLVM_ABI void setSectionPrefix(StringRef Prefix)
Set the section prefix for this global object.
Definition: Globals.cpp:291
LLVM_ABI ~GlobalObject()
Definition: Globals.cpp:105
LLVM_ABI std::optional< StringRef > getSectionPrefix() const
Get the section prefix for this global object.
Definition: Globals.cpp:297
LLVM_ABI void clearMetadata()
Erase all metadata attached to this Value.
Definition: Metadata.cpp:1643
bool hasSection() const
Check if this global has a custom object file section.
Definition: GlobalObject.h:106
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Value.h:576
LLVM_ABI bool canIncreaseAlignment() const
Returns true if the alignment of the value can be unilaterally increased.
Definition: Globals.cpp:330
unsigned HasSanitizerMetadata
True if this symbol has sanitizer metadata available.
Definition: GlobalValue.h:124
bool hasPartition() const
Definition: GlobalValue.h:311
static LLVM_ABI GUID getGUIDAssumingExternalLinkage(StringRef GlobalName)
Return a 64-bit global unique ID constructed from the name of a global symbol.
Definition: Globals.cpp:77
LLVM_ABI const SanitizerMetadata & getSanitizerMetadata() const
Definition: Globals.cpp:245
bool isDSOLocal() const
Definition: GlobalValue.h:307
unsigned HasPartition
True if this symbol has a partition name assigned (see https://lld.llvm.org/Partitions....
Definition: GlobalValue.h:119
LLVM_ABI void removeSanitizerMetadata()
Definition: Globals.cpp:256
static bool isLocalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:411
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:316
LinkageTypes getLinkage() const
Definition: GlobalValue.h:548
void setUnnamedAddr(UnnamedAddr Val)
Definition: GlobalValue.h:233
bool hasDefaultVisibility() const
Definition: GlobalValue.h:251
LLVM_ABI bool isAbsoluteSymbolRef() const
Returns whether this is a reference to an absolute symbol.
Definition: Globals.cpp:424
bool isTagged() const
Definition: GlobalValue.h:367
void setDLLStorageClass(DLLStorageClassTypes C)
Definition: GlobalValue.h:286
LLVM_ABI const Comdat * getComdat() const
Definition: Globals.cpp:201
void setThreadLocalMode(ThreadLocalMode Val)
Definition: GlobalValue.h:269
bool hasSanitizerMetadata() const
Definition: GlobalValue.h:357
unsigned getAddressSpace() const
Definition: GlobalValue.h:207
LLVM_ABI StringRef getSection() const
Definition: Globals.cpp:191
LLVM_ABI StringRef getPartition() const
Definition: Globals.cpp:222
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:663
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:419
void setDSOLocal(bool Local)
Definition: GlobalValue.h:305
LLVM_ABI 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
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:93
static bool isExternalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:378
bool isStrongDefinitionForLinker() const
Returns true if this global's definition will be the one chosen by the linker.
Definition: GlobalValue.h:638
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:296
LLVM_ABI 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
LLVM_ABI void setNoSanitizeMetadata()
Definition: Globals.cpp:263
LLVM_ABI bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
Definition: Globals.cpp:107
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:256
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Definition: Globals.cpp:132
LLVM_ABI bool canBenefitFromLocalAlias() const
Definition: Globals.cpp:114
static bool isInterposableLinkage(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time.
Definition: GlobalValue.h:427
bool hasAtLeastLocalUnnamedAddr() const
Returns true if this value's address is not significant in this module.
Definition: GlobalValue.h:226
unsigned getGlobalValueSubClassData() const
Definition: GlobalValue.h:177
void setGlobalValueSubClassData(unsigned V)
Definition: GlobalValue.h:180
LLVM_ABI 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:217
LLVM_ABI Error materialize()
Make sure this GlobalValue is fully read.
Definition: Globals.cpp:49
LLVM_ABI void setSanitizerMetadata(SanitizerMetadata Meta)
Definition: Globals.cpp:251
bool hasLinkOnceODRLinkage() const
Definition: GlobalValue.h:521
LLVM_ABI bool canBeOmittedFromSymbolTable() const
True if GV can be left out of the object symbol table.
Definition: Globals.cpp:444
LLVM_ABI void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:81
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:52
Type * getValueType() const
Definition: GlobalValue.h:298
LLVM_ABI void setPartition(StringRef Part)
Definition: Globals.cpp:228
LLVM_ABI 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.
LLVM_ABI 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.
LLVM_ABI void replaceInitializer(Constant *InitVal)
replaceInitializer - Sets the initializer for this global variable, and sets the value type of the gl...
Definition: Globals.cpp:532
LLVM_ABI void clearCodeModel()
Remove the code model for this global.
Definition: Globals.cpp:562
LLVM_ABI void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
Definition: Globals.cpp:540
LLVM_ABI void setCodeModel(CodeModel::Model CM)
Change the code model for this global.
Definition: Globals.cpp:553
void setExternallyInitialized(bool Val)
LLVM_ABI void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:507
LLVM_ABI void dropAllReferences()
Drop all references in preparation to destroy the GlobalVariable.
Definition: Globals.cpp:548
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 ...
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:70
LLVM_ABI MDNode * createGlobalObjectSectionPrefix(StringRef Prefix)
Return metadata containing the section prefix for a global object.
Definition: MDBuilder.cpp:91
Metadata node.
Definition: Metadata.h:1077
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition: Module.h:281
void removeIFunc(GlobalIFunc *IFunc)
Detach IFunc from the list but don't delete it.
Definition: Module.h:613
void insertIFunc(GlobalIFunc *IFunc)
Insert IFunc at the end of the alias list and take ownership.
Definition: Module.h:617
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
Definition: Module.cpp:466
bool getSemanticInterposition() const
Returns whether semantic interposition is to be respected.
Definition: Module.cpp:692
void removeAlias(GlobalAlias *Alias)
Detach Alias from the list but don't delete it.
Definition: Module.h:604
void eraseIFunc(GlobalIFunc *IFunc)
Remove IFunc from the list and delete it.
Definition: Module.h:615
void eraseAlias(GlobalAlias *Alias)
Remove Alias from the list and delete it.
Definition: Module.h:606
void eraseGlobalVariable(GlobalVariable *GV)
Remove global variable GV from the list and delete it.
Definition: Module.h:565
void insertGlobalVariable(GlobalVariable *GV)
Insert global variable GV at the end of the global variable list and take ownership.
Definition: Module.h:568
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.h:278
void insertAlias(GlobalAlias *Alias)
Insert Alias at the end of the alias list and take ownership.
Definition: Module.h:608
void removeGlobalVariable(GlobalVariable *GV)
Detach global variable GV from the list but don't delete it.
Definition: Module.h:563
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:876
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition: Record.h:2196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:151
bool isOSBinFormatXCOFF() const
Tests whether the OS uses the XCOFF binary format.
Definition: Triple.h:789
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:766
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
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:258
StringRef save(const char *S)
Definition: StringSaver.h:53
void dropAllReferences()
Drop all references to operands.
Definition: User.h:349
Value * getOperand(unsigned i) const
Definition: User.h:232
LLVM Value Representation.
Definition: Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
static constexpr uint64_t MaximumAlignment
Definition: Value.h:830
LLVM_ABI const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
Definition: Value.cpp:705
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:543
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:1098
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:322
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:194
An efficient, type-erasing, non-owning reference to a callable.
self_iterator getIterator()
Definition: ilist_node.h:134
#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
LLVM_ABI ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
DWARFExpression::Operation Op
constexpr char GlobalIdentifierDelimiter
Definition: GlobalValue.h:47
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