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