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