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
84void GlobalValue::assignGUID() {
85 if (getGUIDMetadata() != nullptr)
86 return;
87
88 const GUID G =
91 LLVMContext::MD_unique_id,
94}
95
97 auto MaybeGUID = getGUIDIfAssigned();
98 assert(MaybeGUID.has_value() &&
99 "GUID was not assigned before calling GetGUID()");
100 return *MaybeGUID;
101}
102
104 if (auto MaybeGUID = getGUIDIfAssigned(); MaybeGUID)
105 return *MaybeGUID;
107}
108
109std::optional<GlobalValue::GUID> GlobalValue::getGUIDIfAssigned() const {
110 // First check the metadata.
111 auto *MD = getGUIDMetadata();
112 if (MD != nullptr)
113 return cast<ConstantInt>(cast<ConstantAsMetadata>(MD->getOperand(0))
114 ->getValue()
115 ->stripPointerCasts())
116 ->getZExtValue();
117
118 // Handle a few special cases where we just want to compute it based on the
119 // current properties.
120 // TODO: Maybe we should use a more robust check for intrinsics than just
121 // matching on the name?
122 if (isDeclaration() || isa<GlobalAlias>(this) ||
123 getName().starts_with("llvm.")) {
125 }
126
127 // Otherwise we try to look it up in the module, for cases where we've read
128 // the GUID table but not the metadata. This happens when lazy-loading a
129 // module.
130 return getParent()->getGUID(this);
131}
132
133MDNode *GlobalValue::getGUIDMetadata() const {
134 if (auto *GO = dyn_cast<GlobalObject>(this))
135 return GO->getMetadata(LLVMContext::MD_unique_id);
136 return nullptr;
137}
138
140 switch (getValueID()) {
141#define HANDLE_GLOBAL_VALUE(NAME) \
142 case Value::NAME##Val: \
143 return static_cast<NAME *>(this)->removeFromParent();
144#include "llvm/IR/Value.def"
145 default:
146 break;
147 }
148 llvm_unreachable("not a global");
149}
150
152 switch (getValueID()) {
153#define HANDLE_GLOBAL_VALUE(NAME) \
154 case Value::NAME##Val: \
155 return static_cast<NAME *>(this)->eraseFromParent();
156#include "llvm/IR/Value.def"
157 default:
158 break;
159 }
160 llvm_unreachable("not a global");
161}
162
164 // Remove associated metadata from context.
165 if (hasMetadata())
167
168 setComdat(nullptr);
169}
170
173 return true;
174 return !isDSOLocal() && getParent() &&
176}
177
179 if (isTagged()) {
180 // Cannot create local aliases to MTE tagged globals. The address of a
181 // tagged global includes a tag that is assigned by the loader in the
182 // GOT.
183 return false;
184 }
185 // See AsmPrinter::getSymbolPreferLocal(). For a deduplicate comdat kind,
186 // references to a discarded local symbol from outside the group are not
187 // allowed, so avoid the local alias.
188 auto isDeduplicateComdat = [](const Comdat *C) {
189 return C && C->getSelectionKind() != Comdat::NoDeduplicate;
190 };
191 return hasDefaultVisibility() &&
193 !isa<GlobalIFunc>(this) && !isDeduplicateComdat(getComdat());
194}
195
197 return getParent()->getDataLayout();
198}
199
202 "Alignment is greater than MaximumAlignment!");
203 unsigned AlignmentData = encode(Align);
204 unsigned OldData = getGlobalValueSubClassData();
205 setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
206 assert(getAlign() == Align && "Alignment representation error!");
207}
208
211 "Alignment is greater than MaximumAlignment!");
212 unsigned AlignmentData = encode(Align);
213 unsigned OldData = getGlobalValueSubClassData();
214 setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
215 assert(getAlign() && *getAlign() == Align &&
216 "Alignment representation error!");
217}
218
221 setAlignment(Src->getAlign());
222 setSection(Src->getSection());
223}
224
227 StringRef FileName) {
228 // Value names may be prefixed with a binary '1' to indicate
229 // that the backend should not modify the symbols due to any platform
230 // naming convention. Do not include that '1' in the PGO profile name.
231 Name.consume_front("\1");
232
233 std::string GlobalName;
235 // For local symbols, prepend the main file name to distinguish them.
236 // Do not include the full path in the file name since there's no guarantee
237 // that it will stay the same, e.g., if the files are checked out from
238 // version control in different locations.
239 if (FileName.empty())
240 GlobalName += "<unknown>";
241 else
242 GlobalName += FileName;
243
244 GlobalName += GlobalIdentifierDelimiter;
245 }
246 GlobalName += Name;
247 return GlobalName;
248}
249
250std::string GlobalValue::getGlobalIdentifier() const {
252 getParent()->getSourceFileName());
253}
254
256 if (auto *GA = dyn_cast<GlobalAlias>(this)) {
257 // In general we cannot compute this at the IR level, but we try.
258 if (const GlobalObject *GO = GA->getAliaseeObject())
259 return GO->getSection();
260 return "";
261 }
262 return cast<GlobalObject>(this)->getSection();
263}
264
266 if (auto *GA = dyn_cast<GlobalAlias>(this)) {
267 // In general we cannot compute this at the IR level, but we try.
268 if (const GlobalObject *GO = GA->getAliaseeObject())
269 return const_cast<GlobalObject *>(GO)->getComdat();
270 return nullptr;
271 }
272 // ifunc and its resolver are separate things so don't use resolver comdat.
273 if (isa<GlobalIFunc>(this))
274 return nullptr;
275 return cast<GlobalObject>(this)->getComdat();
276}
277
279 if (ObjComdat)
280 ObjComdat->removeUser(this);
281 ObjComdat = C;
282 if (C)
283 C->addUser(this);
284}
285
287 if (!hasPartition())
288 return "";
289 return getContext().pImpl->GlobalValuePartitions[this];
290}
291
293 // Do nothing if we're clearing the partition and it is already empty.
294 if (!hasPartition() && S.empty())
295 return;
296
297 // Get or create a stable partition name string and put it in the table in the
298 // context.
299 if (!S.empty())
300 S = getContext().pImpl->Saver.save(S);
302
303 // Update the HasPartition field. Setting the partition to the empty string
304 // means this global no longer has a partition.
305 HasPartition = !S.empty();
306}
307
311 assert(getContext().pImpl->GlobalValueSanitizerMetadata.count(this));
313}
314
319
326
329 Meta.NoAddress = true;
330 Meta.NoHWAddress = true;
332}
333
334StringRef GlobalObject::getSectionImpl() const {
336 return getContext().pImpl->GlobalObjectSections[this];
337}
338
340 // Do nothing if we're clearing the section and it is already empty.
341 if (!hasSection() && S.empty())
342 return;
343
344 // Get or create a stable section name string and put it in the table in the
345 // context.
346 if (!S.empty())
347 S = getContext().pImpl->Saver.save(S);
349
350 // Update the HasSectionHashEntryBit. Setting the section to the empty string
351 // means this global no longer has a section.
352 setGlobalObjectFlag(HasSectionHashEntryBit, !S.empty());
353}
354
356 StringRef ExistingPrefix;
357 if (std::optional<StringRef> MaybePrefix = getSectionPrefix())
358 ExistingPrefix = *MaybePrefix;
359
360 if (ExistingPrefix == Prefix)
361 return false;
362
363 if (Prefix.empty()) {
364 setMetadata(LLVMContext::MD_section_prefix, nullptr);
365 return true;
366 }
367 MDBuilder MDB(getContext());
368 setMetadata(LLVMContext::MD_section_prefix,
370 return true;
371}
372
373std::optional<StringRef> GlobalObject::getSectionPrefix() const {
374 if (MDNode *MD = getMetadata(LLVMContext::MD_section_prefix)) {
375 [[maybe_unused]] StringRef MDName =
376 cast<MDString>(MD->getOperand(0))->getString();
377 assert((MDName == "section_prefix" ||
378 (isa<Function>(this) && MDName == "function_section_prefix")) &&
379 "Metadata not match");
380 return cast<MDString>(MD->getOperand(1))->getString();
381 }
382 return std::nullopt;
383}
384
385bool GlobalValue::isNobuiltinFnDef() const {
386 const Function *F = dyn_cast<Function>(this);
387 if (!F || F->empty())
388 return false;
389 return F->hasFnAttribute(Attribute::NoBuiltin);
390}
391
393 // Globals are definitions if they have an initializer.
394 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
395 return GV->getNumOperands() == 0;
396
397 // Functions are definitions if they have a body.
398 if (const Function *F = dyn_cast<Function>(this))
399 return F->empty() && !F->isMaterializable();
400
401 // Aliases and ifuncs are always definitions.
403 return false;
404}
405
407 // Firstly, can only increase the alignment of a global if it
408 // is a strong definition.
410 return false;
411
412 // It also has to either not have a section defined, or, not have
413 // alignment specified. (If it is assigned a section, the global
414 // could be densely packed with other objects in the section, and
415 // increasing the alignment could cause padding issues.)
416 if (hasSection() && getAlign())
417 return false;
418
419 // On ELF platforms, we're further restricted in that we can't
420 // increase the alignment of any variable which might be emitted
421 // into a shared library, and which is exported. If the main
422 // executable accesses a variable found in a shared-lib, the main
423 // exe actually allocates memory for and exports the symbol ITSELF,
424 // overriding the symbol found in the library. That is, at link
425 // time, the observed alignment of the variable is copied into the
426 // executable binary. (A COPY relocation is also generated, to copy
427 // the initial data from the shadowed variable in the shared-lib
428 // into the location in the main binary, before running code.)
429 //
430 // And thus, even though you might think you are defining the
431 // global, and allocating the memory for the global in your object
432 // file, and thus should be able to set the alignment arbitrarily,
433 // that's not actually true. Doing so can cause an ABI breakage; an
434 // executable might have already been built with the previous
435 // alignment of the variable, and then assuming an increased
436 // alignment will be incorrect.
437
438 // Conservatively assume ELF if there's no parent pointer.
439 bool isELF = (!Parent || Parent->getTargetTriple().isOSBinFormatELF());
440 if (isELF && !isDSOLocal())
441 return false;
442
443 // GV with toc-data attribute is defined in a TOC entry. To mitigate TOC
444 // overflow, the alignment of such symbol should not be increased. Otherwise,
445 // padding is needed thus more TOC entries are wasted.
446 bool isXCOFF = (!Parent || Parent->getTargetTriple().isOSBinFormatXCOFF());
447 if (isXCOFF)
448 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
449 if (GV->hasAttribute("toc-data"))
450 return false;
451
452 return true;
453}
454
457 getAllMetadata(MDs);
458 for (const auto &V : MDs)
459 if (V.first != LLVMContext::MD_dbg && V.first != LLVMContext::MD_unique_id)
460 return true;
461 return false;
462}
463
464template <typename Operation>
465static const GlobalObject *
467 const Operation &Op) {
468 if (auto *GO = dyn_cast<GlobalObject>(C)) {
469 Op(*GO);
470 return GO;
471 }
472 if (auto *GA = dyn_cast<GlobalAlias>(C)) {
473 Op(*GA);
474 if (Aliases.insert(GA).second)
475 return findBaseObject(GA->getOperand(0), Aliases, Op);
476 }
477 if (auto *CE = dyn_cast<ConstantExpr>(C)) {
478 switch (CE->getOpcode()) {
479 case Instruction::Add: {
480 auto *LHS = findBaseObject(CE->getOperand(0), Aliases, Op);
481 auto *RHS = findBaseObject(CE->getOperand(1), Aliases, Op);
482 if (LHS && RHS)
483 return nullptr;
484 return LHS ? LHS : RHS;
485 }
486 case Instruction::Sub: {
487 if (findBaseObject(CE->getOperand(1), Aliases, Op))
488 return nullptr;
489 return findBaseObject(CE->getOperand(0), Aliases, Op);
490 }
491 case Instruction::IntToPtr:
492 case Instruction::PtrToAddr:
493 case Instruction::PtrToInt:
494 case Instruction::BitCast:
495 case Instruction::AddrSpaceCast:
496 case Instruction::GetElementPtr:
497 return findBaseObject(CE->getOperand(0), Aliases, Op);
498 default:
499 break;
500 }
501 }
502 return nullptr;
503}
504
507 return findBaseObject(this, Aliases, [](const GlobalValue &) {});
508}
509
511 auto *GO = dyn_cast<GlobalObject>(this);
512 if (!GO)
513 return false;
514
515 return GO->getMetadata(LLVMContext::MD_absolute_symbol);
516}
517
518std::optional<ConstantRange> GlobalValue::getAbsoluteSymbolRange() const {
519 auto *GO = dyn_cast<GlobalObject>(this);
520 if (!GO)
521 return std::nullopt;
522
523 MDNode *MD = GO->getMetadata(LLVMContext::MD_absolute_symbol);
524 if (!MD)
525 return std::nullopt;
526
528}
529
532 return false;
533
534 // We assume that anyone who sets global unnamed_addr on a non-constant
535 // knows what they're doing.
537 return true;
538
539 // If it is a non constant variable, it needs to be uniqued across shared
540 // objects.
541 if (auto *Var = dyn_cast<GlobalVariable>(this))
542 if (!Var->isConstant())
543 return false;
544
546}
547
548//===----------------------------------------------------------------------===//
549// GlobalVariable Implementation
550//===----------------------------------------------------------------------===//
551
553 Constant *InitVal, const Twine &Name,
554 ThreadLocalMode TLMode, unsigned AddressSpace,
556 : GlobalObject(Ty, Value::GlobalVariableVal, AllocMarker, Link, Name,
558 isConstantGlobal(constant),
559 isExternallyInitializedConstant(isExternallyInitialized) {
560 assert(!Ty->isFunctionTy() && PointerType::isValidElementType(Ty) &&
561 "invalid type for global variable");
562 setThreadLocalMode(TLMode);
563 if (InitVal) {
564 assert(InitVal->getType() == Ty &&
565 "Initializer should be the same type as the GlobalVariable!");
566 Op<0>() = InitVal;
567 } else {
568 setGlobalVariableNumOperands(0);
569 }
570}
571
573 LinkageTypes Link, Constant *InitVal,
574 const Twine &Name, GlobalVariable *Before,
575 ThreadLocalMode TLMode,
576 std::optional<unsigned> AddressSpace,
578 : GlobalVariable(Ty, constant, Link, InitVal, Name, TLMode,
580 ? *AddressSpace
581 : M.getDataLayout().getDefaultGlobalsAddressSpace(),
583 if (Before)
584 Before->getParent()->insertGlobalVariable(Before->getIterator(), this);
585 else
586 M.insertGlobalVariable(this);
587}
588
592
596
598 if (!InitVal) {
599 if (hasInitializer()) {
600 // Note, the num operands is used to compute the offset of the operand, so
601 // the order here matters. Clearing the operand then clearing the num
602 // operands ensures we have the correct offset to the operand.
603 Op<0>().set(nullptr);
604 setGlobalVariableNumOperands(0);
605 }
606 } else {
607 assert(InitVal->getType() == getValueType() &&
608 "Initializer type must match GlobalVariable type");
609 // Note, the num operands is used to compute the offset of the operand, so
610 // the order here matters. We need to set num operands to 1 first so that
611 // we get the correct offset to the first operand when we set it.
612 if (!hasInitializer())
613 setGlobalVariableNumOperands(1);
614 Op<0>().set(InitVal);
615 }
616}
617
619 assert(InitVal && "Can't compute type of null initializer");
620 ValueType = InitVal->getType();
621 setInitializer(InitVal);
622}
623
625 // We don't support scalable global variables.
626 return DL.getTypeAllocSize(getValueType()).getFixedValue();
627}
628
629/// Copy all additional attributes (those not needed to create a GlobalVariable)
630/// from the GlobalVariable Src to this one.
633 setExternallyInitialized(Src->isExternallyInitialized());
634 setAttributes(Src->getAttributes());
635 if (auto CM = Src->getCodeModel())
636 setCodeModel(*CM);
637}
638
643
645 unsigned CodeModelData = static_cast<unsigned>(CM) + 1;
646 unsigned OldData = getGlobalValueSubClassData();
647 unsigned NewData = (OldData & ~(CodeModelMask << CodeModelShift)) |
648 (CodeModelData << CodeModelShift);
650 assert(getCodeModel() == CM && "Code model representation error!");
651}
652
654 unsigned CodeModelData = 0;
655 unsigned OldData = getGlobalValueSubClassData();
656 unsigned NewData = (OldData & ~(CodeModelMask << CodeModelShift)) |
657 (CodeModelData << CodeModelShift);
659 assert(getCodeModel() == std::nullopt && "Code model representation error!");
660}
661
662//===----------------------------------------------------------------------===//
663// GlobalAlias Implementation
664//===----------------------------------------------------------------------===//
665
666GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
667 const Twine &Name, Constant *Aliasee,
668 Module *ParentModule)
669 : GlobalValue(Ty, Value::GlobalAliasVal, AllocMarker, Link, Name,
670 AddressSpace) {
671 setAliasee(Aliasee);
672 if (ParentModule)
673 ParentModule->insertAlias(this);
674}
675
676GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
677 LinkageTypes Link, const Twine &Name,
678 Constant *Aliasee, Module *ParentModule) {
679 return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
680}
681
682GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
683 LinkageTypes Linkage, const Twine &Name,
684 Module *Parent) {
685 return create(Ty, AddressSpace, Linkage, Name, nullptr, Parent);
686}
687
688GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
689 LinkageTypes Linkage, const Twine &Name,
690 GlobalValue *Aliasee) {
691 return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->getParent());
692}
693
694GlobalAlias *GlobalAlias::create(LinkageTypes Link, const Twine &Name,
695 GlobalValue *Aliasee) {
696 return create(Aliasee->getValueType(), Aliasee->getAddressSpace(), Link, Name,
697 Aliasee);
698}
699
700GlobalAlias *GlobalAlias::create(const Twine &Name, GlobalValue *Aliasee) {
701 return create(Aliasee->getLinkage(), Name, Aliasee);
702}
703
705
707
709 assert((!Aliasee || Aliasee->getType() == getType()) &&
710 "Alias and aliasee types should match!");
711 Op<0>().set(Aliasee);
712}
713
716 return findBaseObject(getOperand(0), Aliases, [](const GlobalValue &) {});
717}
718
719//===----------------------------------------------------------------------===//
720// GlobalIFunc Implementation
721//===----------------------------------------------------------------------===//
722
723GlobalIFunc::GlobalIFunc(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
724 const Twine &Name, Constant *Resolver,
725 Module *ParentModule)
726 : GlobalObject(Ty, Value::GlobalIFuncVal, AllocMarker, Link, Name,
727 AddressSpace) {
728 setResolver(Resolver);
729 if (ParentModule)
730 ParentModule->insertIFunc(this);
731}
732
733GlobalIFunc *GlobalIFunc::create(Type *Ty, unsigned AddressSpace,
734 LinkageTypes Link, const Twine &Name,
735 Constant *Resolver, Module *ParentModule) {
736 return new GlobalIFunc(Ty, AddressSpace, Link, Name, Resolver, ParentModule);
737}
738
740
742
746
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:308
static const GlobalObject * findBaseObject(const Constant *C, DenseSet< const GlobalAlias * > &Aliases, const Operation &Op)
Definition Globals.cpp:466
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define G(x, y, z)
Definition MD5.cpp:55
PowerPC Reduce CR logical Operation
DEMANGLE_NAMESPACE_BEGIN bool starts_with(std::string_view self, char C) noexcept
Value * RHS
Value * LHS
@ NoDeduplicate
No deduplication is performed.
Definition Comdat.h:40
static ConstantAsMetadata * get(Constant *C)
Definition Metadata.h:537
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:332
Implements a dense probed hash-table based set.
Definition DenseSet.h:289
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:706
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition Globals.cpp:714
LLVM_ABI void setAliasee(Constant *Aliasee)
These methods retrieve and set alias target.
Definition Globals.cpp:708
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:676
LLVM_ABI void removeFromParent()
removeFromParent - This method unlinks 'this' from the containing module, but does not delete it.
Definition Globals.cpp:704
LLVM_ABI void applyAlongResolverPath(function_ref< void(const GlobalValue &)> Op) const
Definition Globals.cpp:747
LLVM_ABI const Function * getResolverFunction() const
Definition Globals.cpp:743
LLVM_ABI void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition Globals.cpp:739
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:733
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition Globals.cpp:741
const Constant * getResolver() const
Definition GlobalIFunc.h:73
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:355
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.
bool hasMetadata() const
Return true if this GlobalObject has any metadata attached to it.
LLVM_ABI void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
Definition Globals.cpp:209
GlobalObject(Type *Ty, ValueTy VTy, AllocInfo AllocInfo, LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace=0)
LLVM_ABI void setComdat(Comdat *C)
Definition Globals.cpp:278
LLVM_ABI void copyAttributesFrom(const GlobalObject *Src)
Definition Globals.cpp:219
LLVM_ABI void setSection(StringRef S)
Change the section for this global.
Definition Globals.cpp:339
LLVM_ABI bool hasMetadataOtherThanDebugLocAndGuid() const
Definition Globals.cpp:455
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this GlobalObject.
LLVM_ABI ~GlobalObject()
Definition Globals.cpp:163
LLVM_ABI std::optional< StringRef > getSectionPrefix() const
Get the section prefix for this global object.
Definition Globals.cpp:373
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
LLVM_ABI bool canIncreaseAlignment() const
Returns true if the alignment of the value can be unilaterally increased.
Definition Globals.cpp:406
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:309
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:320
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:392
LinkageTypes getLinkage() const
void setUnnamedAddr(UnnamedAddr Val)
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
GUID getGUIDOrFallback() const
Return the GUID for this value if it has been assigned, otherwise fall back to computing it based on ...
Definition Globals.cpp:103
bool hasDefaultVisibility() const
LLVM_ABI bool isAbsoluteSymbolRef() const
Returns whether this is a reference to an absolute symbol.
Definition Globals.cpp:510
bool isTagged() const
void setDLLStorageClass(DLLStorageClassTypes C)
LLVM_ABI const Comdat * getComdat() const
Definition Globals.cpp:265
void setThreadLocalMode(ThreadLocalMode Val)
friend class Constant
bool hasSanitizerMetadata() const
unsigned getAddressSpace() const
LLVM_ABI StringRef getSection() const
Definition Globals.cpp:255
LLVM_ABI StringRef getPartition() const
Definition Globals.cpp:286
Module * getParent()
Get the module that this global value is contained inside of...
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition Globals.cpp:505
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:518
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition Globals.cpp:151
GUID getGUID() const
Return a 64-bit global unique ID for this value.
Definition Globals.cpp:96
static bool isExternalLinkage(LinkageTypes Linkage)
std::optional< GUID > getGUIDIfAssigned() const
Return the GUID for this value if it has been assigned, nullopt otherwise.
Definition Globals.cpp:109
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:225
LLVM_ABI void setNoSanitizeMetadata()
Definition Globals.cpp:327
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:171
void setVisibility(VisibilityTypes V)
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Definition Globals.cpp:196
LLVM_ABI bool canBenefitFromLocalAlias() const
Definition Globals.cpp:178
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:315
bool hasLinkOnceODRLinkage() const
LLVM_ABI bool canBeOmittedFromSymbolTable() const
True if GV can be left out of the object symbol table.
Definition Globals.cpp:530
LLVM_ABI void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition Globals.cpp:139
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:292
LLVM_ABI void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
Definition Globals.cpp:597
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:589
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:618
LLVM_ABI void clearCodeModel()
Remove the code model for this global.
Definition Globals.cpp:653
LLVM_ABI void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
Definition Globals.cpp:631
LLVM_ABI uint64_t getGlobalSize(const DataLayout &DL) const
Get the size of this global variable in bytes.
Definition Globals.cpp:624
LLVM_ABI void setCodeModel(CodeModel::Model CM)
Change the code model for this global.
Definition Globals.cpp:644
void setExternallyInitialized(bool Val)
LLVM_ABI void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition Globals.cpp:593
LLVM_ABI void dropAllReferences()
Drop all references in preparation to destroy the GlobalVariable.
Definition Globals.cpp:639
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:552
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:1075
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1567
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
void removeIFunc(GlobalIFunc *IFunc)
Detach IFunc from the list but don't delete it.
Definition Module.h:640
void insertIFunc(GlobalIFunc *IFunc)
Insert IFunc at the end of the alias list and take ownership.
Definition Module.h:644
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:631
void eraseIFunc(GlobalIFunc *IFunc)
Remove IFunc from the list and delete it.
Definition Module.h:642
void eraseAlias(GlobalAlias *Alias)
Remove Alias from the list and delete it.
Definition Module.h:633
void eraseGlobalVariable(GlobalVariable *GV)
Remove global variable GV from the list and delete it.
Definition Module.h:568
std::optional< GlobalValue::GUID > getGUID(const Value *V) const
Definition Module.h:582
void insertGlobalVariable(GlobalVariable *GV)
Insert global variable GV at the end of the global variable list and take ownership.
Definition Module.h:571
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition Module.h:281
void insertAlias(GlobalAlias *Alias)
Insert Alias at the end of the alias list and take ownership.
Definition Module.h:635
void removeGlobalVariable(GlobalVariable *GV)
Detach global variable GV from the list but don't delete it.
Definition Module.h:566
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition Type.cpp:942
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition Record.h:2202
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
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
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:310
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:255
static constexpr uint64_t MaximumAlignment
Definition Value.h:798
LLVM_ABI const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
Definition Value.cpp:716
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:258
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition Value.h:543
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:318
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:212
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