LLVM 19.0.0git
GlobalValue.h
Go to the documentation of this file.
1//===-- llvm/GlobalValue.h - Class to represent a global value --*- C++ -*-===//
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 is a common base class of all globally definable objects. As such,
10// it is subclassed by GlobalVariable, GlobalAlias and by Function. This is
11// used because you can do certain things with these global objects that you
12// can't do to anything else. For example, use the address of one as a
13// constant.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_IR_GLOBALVALUE_H
18#define LLVM_IR_GLOBALVALUE_H
19
20#include "llvm/ADT/StringRef.h"
21#include "llvm/ADT/Twine.h"
22#include "llvm/IR/Constant.h"
24#include "llvm/IR/Value.h"
27#include <cassert>
28#include <cstdint>
29#include <string>
30
31namespace llvm {
32
33class Comdat;
34class ConstantRange;
35class Error;
36class GlobalObject;
37class Module;
38
39namespace Intrinsic {
40typedef unsigned ID;
41} // end namespace Intrinsic
42
43// Choose ';' as the delimiter. ':' was used once but it doesn't work well for
44// Objective-C functions which commonly have :'s in their names.
45inline constexpr char kGlobalIdentifierDelimiter = ';';
46
47class GlobalValue : public Constant {
48public:
49 /// An enumeration for the kinds of linkage for global values.
51 ExternalLinkage = 0,///< Externally visible function
52 AvailableExternallyLinkage, ///< Available for inspection, not emission.
53 LinkOnceAnyLinkage, ///< Keep one copy of function when linking (inline)
54 LinkOnceODRLinkage, ///< Same, but only replaced by something equivalent.
55 WeakAnyLinkage, ///< Keep one copy of named function when linking (weak)
56 WeakODRLinkage, ///< Same, but only replaced by something equivalent.
57 AppendingLinkage, ///< Special purpose, only applies to global arrays
58 InternalLinkage, ///< Rename collisions when linking (static functions).
59 PrivateLinkage, ///< Like Internal, but omit from symbol table.
60 ExternalWeakLinkage,///< ExternalWeak linkage description.
61 CommonLinkage ///< Tentative definitions.
62 };
63
64 /// An enumeration for the kinds of visibility of global values.
66 DefaultVisibility = 0, ///< The GV is visible
67 HiddenVisibility, ///< The GV is hidden
68 ProtectedVisibility ///< The GV is protected
69 };
70
71 /// Storage classes of global values for PE targets.
74 DLLImportStorageClass = 1, ///< Function to be imported from DLL
75 DLLExportStorageClass = 2 ///< Function to be accessible from DLL.
76 };
77
78protected:
79 GlobalValue(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
80 LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace)
81 : Constant(PointerType::get(Ty, AddressSpace), VTy, Ops, NumOps),
89 }
90
92
93 static const unsigned GlobalValueSubClassDataBits = 15;
94
95 // All bitfields use unsigned as the underlying type so that MSVC will pack
96 // them.
97 unsigned Linkage : 4; // The linkage of this global
98 unsigned Visibility : 2; // The visibility style of this global
99 unsigned UnnamedAddrVal : 2; // This value's address is not significant
100 unsigned DllStorageClass : 2; // DLL storage class
101
102 unsigned ThreadLocal : 3; // Is this symbol "Thread Local", if so, what is
103 // the desired model?
104
105 /// True if the function's name starts with "llvm.". This corresponds to the
106 /// value of Function::isIntrinsic(), which may be true even if
107 /// Function::intrinsicID() returns Intrinsic::not_intrinsic.
109
110 /// If true then there is a definition within the same linkage unit and that
111 /// definition cannot be runtime preempted.
112 unsigned IsDSOLocal : 1;
113
114 /// True if this symbol has a partition name assigned (see
115 /// https://lld.llvm.org/Partitions.html).
116 unsigned HasPartition : 1;
117
118 /// True if this symbol has sanitizer metadata available. Should only happen
119 /// if sanitizers were enabled when building the translation unit which
120 /// contains this GV.
122
123private:
124 // Give subclasses access to what otherwise would be wasted padding.
125 // (15 + 4 + 2 + 2 + 2 + 3 + 1 + 1 + 1 + 1) == 32.
126 unsigned SubClassData : GlobalValueSubClassDataBits;
127
128 friend class Constant;
129
130 void destroyConstantImpl();
131 Value *handleOperandChangeImpl(Value *From, Value *To);
132
133 /// Returns true if the definition of this global may be replaced by a
134 /// differently optimized variant of the same source level function at link
135 /// time.
136 bool mayBeDerefined() const {
137 switch (getLinkage()) {
138 case WeakODRLinkage:
141 return true;
142
143 case WeakAnyLinkage:
145 case CommonLinkage:
147 case ExternalLinkage:
148 case AppendingLinkage:
149 case InternalLinkage:
150 case PrivateLinkage:
151 // Optimizations may assume builtin semantics for functions defined as
152 // nobuiltin due to attributes at call-sites. To avoid applying IPO based
153 // on nobuiltin semantics, treat such function definitions as maybe
154 // derefined.
155 return isInterposable() || isNobuiltinFnDef();
156 }
157
158 llvm_unreachable("Fully covered switch above!");
159 }
160
161 /// Returns true if the global is a function definition with the nobuiltin
162 /// attribute.
163 bool isNobuiltinFnDef() const;
164
165protected:
166 /// The intrinsic ID for this subclass (which must be a Function).
167 ///
168 /// This member is defined by this class, but not used for anything.
169 /// Subclasses can use it to store their intrinsic ID, if they have one.
170 ///
171 /// This is stored here to save space in Function on 64-bit hosts.
173
174 unsigned getGlobalValueSubClassData() const {
175 return SubClassData;
176 }
177 void setGlobalValueSubClassData(unsigned V) {
178 assert(V < (1 << GlobalValueSubClassDataBits) && "It will not fit");
179 SubClassData = V;
180 }
181
182 Module *Parent = nullptr; // The containing module.
183
184 // Used by SymbolTableListTraits.
185 void setParent(Module *parent) {
186 Parent = parent;
187 }
188
190 removeDeadConstantUsers(); // remove any dead constants using this.
191 }
192
193public:
200 };
201
202 GlobalValue(const GlobalValue &) = delete;
203
204 unsigned getAddressSpace() const {
205 return getType()->getAddressSpace();
206 }
207
208 enum class UnnamedAddr {
209 None,
210 Local,
211 Global,
212 };
213
214 bool hasGlobalUnnamedAddr() const {
216 }
217
218 /// Returns true if this value's address is not significant in this module.
219 /// This attribute is intended to be used only by the code generator and LTO
220 /// to allow the linker to decide whether the global needs to be in the symbol
221 /// table. It should probably not be used in optimizations, as the value may
222 /// have uses outside the module; use hasGlobalUnnamedAddr() instead.
225 }
226
229 }
231
234 return UnnamedAddr::None;
236 return UnnamedAddr::Local;
237 return UnnamedAddr::Global;
238 }
239
240 bool hasComdat() const { return getComdat() != nullptr; }
241 const Comdat *getComdat() const;
243 return const_cast<Comdat *>(
244 static_cast<const GlobalValue *>(this)->getComdat());
245 }
246
252 }
255 "local linkage requires default visibility");
256 Visibility = V;
257 if (isImplicitDSOLocal())
258 setDSOLocal(true);
259 }
260
261 /// If the value is "Thread Local", its value isn't shared by the threads.
262 bool isThreadLocal() const { return getThreadLocalMode() != NotThreadLocal; }
263 void setThreadLocal(bool Val) {
265 }
267 assert(Val == NotThreadLocal || getValueID() != Value::FunctionVal);
268 ThreadLocal = Val;
269 }
271 return static_cast<ThreadLocalMode>(ThreadLocal);
272 }
273
276 }
279 }
282 }
285 "local linkage requires DefaultStorageClass");
287 }
288
289 bool hasSection() const { return !getSection().empty(); }
290 StringRef getSection() const;
291
292 /// Global values are always pointers.
293 PointerType *getType() const { return cast<PointerType>(User::getType()); }
294
295 Type *getValueType() const { return ValueType; }
296
297 bool isImplicitDSOLocal() const {
298 return hasLocalLinkage() ||
300 }
301
303
304 bool isDSOLocal() const {
305 return IsDSOLocal;
306 }
307
308 bool hasPartition() const {
309 return HasPartition;
310 }
311 StringRef getPartition() const;
312 void setPartition(StringRef Part);
313
314 // ASan, HWASan and Memtag sanitizers have some instrumentation that applies
315 // specifically to global variables.
320 // For ASan and HWASan, this instrumentation is implicitly applied to all
321 // global variables when built with -fsanitize=*. What we need is a way to
322 // persist the information that a certain global variable should *not* have
323 // sanitizers applied, which occurs if:
324 // 1. The global variable is in the sanitizer ignore list, or
325 // 2. The global variable is created by the sanitizers itself for internal
326 // usage, or
327 // 3. The global variable has __attribute__((no_sanitize("..."))) or
328 // __attribute__((disable_sanitizer_instrumentation)).
329 //
330 // This is important, a some IR passes like GlobalMerge can delete global
331 // variables and replace them with new ones. If the old variables were
332 // marked to be unsanitized, then the new ones should also be.
333 unsigned NoAddress : 1;
334 unsigned NoHWAddress : 1;
335
336 // Memtag sanitization works differently: sanitization is requested by clang
337 // when `-fsanitize=memtag-globals` is provided, and the request can be
338 // denied (and the attribute removed) by the AArch64 global tagging pass if
339 // it can't be fulfilled (e.g. the global variable is a TLS variable).
340 // Memtag sanitization has to interact with other parts of LLVM (like
341 // supressing certain optimisations, emitting assembly directives, or
342 // creating special relocation sections).
343 //
344 // Use `GlobalValue::isTagged()` to check whether tagging should be enabled
345 // for a global variable.
346 unsigned Memtag : 1;
347
348 // ASan-specific metadata. Is this global variable dynamically initialized
349 // (from a C++ language perspective), and should therefore be checked for
350 // ODR violations.
351 unsigned IsDynInit : 1;
352 };
353
356 // Note: Not byref as it's a POD and otherwise it's too easy to call
357 // G.setSanitizerMetadata(G2.getSanitizerMetadata()), and the argument becomes
358 // dangling when the backing storage allocates the metadata for `G`, as the
359 // storage is shared between `G1` and `G2`.
363
364 bool isTagged() const {
366 }
367
370 }
371 static LinkageTypes getWeakLinkage(bool ODR) {
372 return ODR ? WeakODRLinkage : WeakAnyLinkage;
373 }
374
376 return Linkage == ExternalLinkage;
377 }
380 }
382 return Linkage == LinkOnceAnyLinkage;
383 }
385 return Linkage == LinkOnceODRLinkage;
386 }
389 }
391 return Linkage == WeakAnyLinkage;
392 }
394 return Linkage == WeakODRLinkage;
395 }
398 }
400 return Linkage == AppendingLinkage;
401 }
403 return Linkage == InternalLinkage;
404 }
406 return Linkage == PrivateLinkage;
407 }
410 }
413 }
415 return Linkage == CommonLinkage;
416 }
419 }
420
421 /// Whether the definition of this global may be replaced by something
422 /// non-equivalent at link time. For example, if a function has weak linkage
423 /// then the code defining it may be replaced by different code.
425 switch (Linkage) {
426 case WeakAnyLinkage:
428 case CommonLinkage:
430 return true;
431
434 case WeakODRLinkage:
435 // The above three cannot be overridden but can be de-refined.
436
437 case ExternalLinkage:
438 case AppendingLinkage:
439 case InternalLinkage:
440 case PrivateLinkage:
441 return false;
442 }
443 llvm_unreachable("Fully covered switch above!");
444 }
445
446 /// Whether the definition of this global may be discarded if it is not used
447 /// in its compilation unit.
451 }
452
453 /// Whether the definition of this global may be replaced at link time. NB:
454 /// Using this method outside of the code generators is almost always a
455 /// mistake: when working at the IR level use isInterposable instead as it
456 /// knows about ODR semantics.
461 }
462
463 /// Return true if the currently visible definition of this global (if any) is
464 /// exactly the definition we will see at runtime.
465 ///
466 /// Non-exact linkage types inhibits most non-inlining IPO, since a
467 /// differently optimized variant of the same function can have different
468 /// observable or undefined behavior than in the variant currently visible.
469 /// For instance, we could have started with
470 ///
471 /// void foo(int *v) {
472 /// int t = 5 / v[0];
473 /// (void) t;
474 /// }
475 ///
476 /// and "refined" it to
477 ///
478 /// void foo(int *v) { }
479 ///
480 /// However, we cannot infer readnone for `foo`, since that would justify
481 /// DSE'ing a store to `v[0]` across a call to `foo`, which can cause
482 /// undefined behavior if the linker replaces the actual call destination with
483 /// the unoptimized `foo`.
484 ///
485 /// Inlining is okay across non-exact linkage types as long as they're not
486 /// interposable (see \c isInterposable), since in such cases the currently
487 /// visible variant is *a* correct implementation of the original source
488 /// function; it just isn't the *only* correct implementation.
489 bool isDefinitionExact() const {
490 return !mayBeDerefined();
491 }
492
493 /// Return true if this global has an exact defintion.
494 bool hasExactDefinition() const {
495 // While this computes exactly the same thing as
496 // isStrongDefinitionForLinker, the intended uses are different. This
497 // function is intended to help decide if specific inter-procedural
498 // transforms are correct, while isStrongDefinitionForLinker's intended use
499 // is in low level code generation.
500 return !isDeclaration() && isDefinitionExact();
501 }
502
503 /// Return true if this global's definition can be substituted with an
504 /// *arbitrary* definition at link time or load time. We cannot do any IPO or
505 /// inlining across interposable call edges, since the callee can be
506 /// replaced with something arbitrary.
507 bool isInterposable() const;
508 bool canBenefitFromLocalAlias() const;
509
513 }
517 }
520 }
521 bool hasWeakLinkage() const { return isWeakLinkage(getLinkage()); }
527 bool hasLocalLinkage() const { return isLocalLinkage(getLinkage()); }
530 }
531 bool hasCommonLinkage() const { return isCommonLinkage(getLinkage()); }
534 }
535
537 if (isLocalLinkage(LT)) {
540 }
541 Linkage = LT;
542 if (isImplicitDSOLocal())
543 setDSOLocal(true);
544 }
546
549 }
550
551 bool isWeakForLinker() const { return isWeakForLinker(getLinkage()); }
552
553protected:
554 /// Copy all additional attributes (those not needed to create a GlobalValue)
555 /// from the GlobalValue Src to this one.
556 void copyAttributesFrom(const GlobalValue *Src);
557
558public:
559 /// If the given string begins with the GlobalValue name mangling escape
560 /// character '\1', drop it.
561 ///
562 /// This function applies a specific mangling that is used in PGO profiles,
563 /// among other things. If you're trying to get a symbol name for an
564 /// arbitrary GlobalValue, this is not the function you're looking for; see
565 /// Mangler.h.
567 Name.consume_front("\1");
568 return Name;
569 }
570
571 /// Return the modified name for a global value suitable to be
572 /// used as the key for a global lookup (e.g. profile or ThinLTO).
573 /// The value's original name is \c Name and has linkage of type
574 /// \c Linkage. The value is defined in module \c FileName.
575 static std::string getGlobalIdentifier(StringRef Name,
577 StringRef FileName);
578
579 /// Return the modified name for this global value suitable to be
580 /// used as the key for a global lookup (e.g. profile or ThinLTO).
581 std::string getGlobalIdentifier() const;
582
583 /// Declare a type to represent a global unique identifier for a global value.
584 /// This is a 64 bits hash that is used by PGO and ThinLTO to have a compact
585 /// unique way to identify a symbol.
586 using GUID = uint64_t;
587
588 /// Return a 64-bit global unique ID constructed from global value name
589 /// (i.e. returned by getGlobalIdentifier()).
590 static GUID getGUID(StringRef GlobalName);
591
592 /// Return a 64-bit global unique ID constructed from global value name
593 /// (i.e. returned by getGlobalIdentifier()).
595
596 /// @name Materialization
597 /// Materialization is used to construct functions only as they're needed.
598 /// This
599 /// is useful to reduce memory usage in LLVM or parsing work done by the
600 /// BitcodeReader to load the Module.
601 /// @{
602
603 /// If this function's Module is being lazily streamed in functions from disk
604 /// or some other source, this method can be used to check to see if the
605 /// function has been read in yet or not.
606 bool isMaterializable() const;
607
608 /// Make sure this GlobalValue is fully read.
610
611/// @}
612
613 /// Return true if the primary definition of this global value is outside of
614 /// the current translation unit.
615 bool isDeclaration() const;
616
619 return true;
620
621 return isDeclaration();
622 }
623
624 /// Returns true if this global's definition will be the one chosen by the
625 /// linker.
626 ///
627 /// NB! Ideally this should not be used at the IR level at all. If you're
628 /// interested in optimization constraints implied by the linker's ability to
629 /// choose an implementation, prefer using \c hasExactDefinition.
632 }
633
634 const GlobalObject *getAliaseeObject() const;
636 return const_cast<GlobalObject *>(
637 static_cast<const GlobalValue *>(this)->getAliaseeObject());
638 }
639
640 /// Returns whether this is a reference to an absolute symbol.
641 bool isAbsoluteSymbolRef() const;
642
643 /// If this is an absolute symbol reference, returns the range of the symbol,
644 /// otherwise returns std::nullopt.
645 std::optional<ConstantRange> getAbsoluteSymbolRange() const;
646
647 /// This method unlinks 'this' from the containing module, but does not delete
648 /// it.
649 void removeFromParent();
650
651 /// This method unlinks 'this' from the containing module and deletes it.
652 void eraseFromParent();
653
654 /// Get the module that this global value is contained inside of...
655 Module *getParent() { return Parent; }
656 const Module *getParent() const { return Parent; }
657
658 // Methods for support type inquiry through isa, cast, and dyn_cast:
659 static bool classof(const Value *V) {
660 return V->getValueID() == Value::FunctionVal ||
661 V->getValueID() == Value::GlobalVariableVal ||
662 V->getValueID() == Value::GlobalAliasVal ||
663 V->getValueID() == Value::GlobalIFuncVal;
664 }
665
666 /// True if GV can be left out of the object symbol table. This is the case
667 /// for linkonce_odr values whose address is not significant. While legal, it
668 /// is not normally profitable to omit them from the .o symbol table. Using
669 /// this analysis makes sense when the information can be passed down to the
670 /// linker or we are in LTO.
671 bool canBeOmittedFromSymbolTable() const;
672};
673
674} // end namespace llvm
675
676#endif // LLVM_IR_GLOBALVALUE_H
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
std::string Name
GlobalValue::SanitizerMetadata SanitizerMetadata
Definition: Globals.cpp:232
Machine Check Debug Module
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This is an important base class in LLVM.
Definition: Constant.h:41
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
Definition: Constants.cpp:723
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
bool isDefinitionExact() const
Return true if the currently visible definition of this global (if any) is exactly the definition we ...
Definition: GlobalValue.h:489
unsigned HasSanitizerMetadata
True if this symbol has sanitizer metadata available.
Definition: GlobalValue.h:121
static bool isWeakAnyLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:390
bool hasLinkOnceLinkage() const
Definition: GlobalValue.h:514
const Module * getParent() const
Definition: GlobalValue.h:656
static bool isAppendingLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:399
bool hasPartition() const
Definition: GlobalValue.h:308
static bool isLinkOnceAnyLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:381
const SanitizerMetadata & getSanitizerMetadata() const
Definition: Globals.cpp:233
bool hasExternalLinkage() const
Definition: GlobalValue.h:510
bool isDSOLocal() const
Definition: GlobalValue.h:304
unsigned HasPartition
True if this symbol has a partition name assigned (see https://lld.llvm.org/Partitions....
Definition: GlobalValue.h:116
void removeSanitizerMetadata()
Definition: Globals.cpp:244
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
Definition: GlobalValue.h:262
static bool isExternalWeakLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:411
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:247
bool isImplicitDSOLocal() const
Definition: GlobalValue.h:297
static bool isLocalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:408
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:286
bool hasValidDeclarationLinkage() const
Definition: GlobalValue.h:532
LinkageTypes getLinkage() const
Definition: GlobalValue.h:545
void setUnnamedAddr(UnnamedAddr Val)
Definition: GlobalValue.h:230
static bool isWeakODRLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:393
bool hasLinkOnceAnyLinkage() const
Definition: GlobalValue.h:515
bool hasLocalLinkage() const
Definition: GlobalValue.h:527
bool hasDefaultVisibility() const
Definition: GlobalValue.h:248
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Definition: GlobalValue.h:566
bool hasPrivateLinkage() const
Definition: GlobalValue.h:526
bool isAbsoluteSymbolRef() const
Returns whether this is a reference to an absolute symbol.
Definition: Globals.cpp:395
bool isTagged() const
Definition: GlobalValue.h:364
void setDLLStorageClass(DLLStorageClassTypes C)
Definition: GlobalValue.h:283
const Comdat * getComdat() const
Definition: Globals.cpp:189
void setThreadLocalMode(ThreadLocalMode Val)
Definition: GlobalValue.h:266
unsigned Visibility
Definition: GlobalValue.h:98
static bool isLinkOnceLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:387
Intrinsic::ID IntID
The intrinsic ID for this subclass (which must be a Function).
Definition: GlobalValue.h:172
bool hasHiddenVisibility() const
Definition: GlobalValue.h:249
bool hasExternalWeakLinkage() const
Definition: GlobalValue.h:528
ThreadLocalMode getThreadLocalMode() const
Definition: GlobalValue.h:270
bool hasExactDefinition() const
Return true if this global has an exact defintion.
Definition: GlobalValue.h:494
unsigned HasLLVMReservedName
True if the function's name starts with "llvm.".
Definition: GlobalValue.h:108
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:378
bool hasWeakAnyLinkage() const
Definition: GlobalValue.h:522
void setParent(Module *parent)
Definition: GlobalValue.h:185
bool hasDLLImportStorageClass() const
Definition: GlobalValue.h:277
void setLinkage(LinkageTypes LT)
Definition: GlobalValue.h:536
DLLStorageClassTypes
Storage classes of global values for PE targets.
Definition: GlobalValue.h:72
@ DLLExportStorageClass
Function to be accessible from DLL.
Definition: GlobalValue.h:75
@ DLLImportStorageClass
Function to be imported from DLL.
Definition: GlobalValue.h:74
bool hasDLLExportStorageClass() const
Definition: GlobalValue.h:280
bool isDeclarationForLinker() const
Definition: GlobalValue.h:617
Comdat * getComdat()
Definition: GlobalValue.h:242
bool hasSanitizerMetadata() const
Definition: GlobalValue.h:354
static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B)
Definition: GlobalValue.h:232
GlobalObject * getAliaseeObject()
Definition: GlobalValue.h:635
unsigned getAddressSpace() const
Definition: GlobalValue.h:204
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:594
StringRef getSection() const
Definition: Globals.cpp:179
StringRef getPartition() const
Definition: Globals.cpp:210
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:655
static bool isCommonLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:414
const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:390
void setDSOLocal(bool Local)
Definition: GlobalValue.h:302
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:403
bool hasInternalLinkage() const
Definition: GlobalValue.h:525
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:91
static bool isPrivateLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:405
bool isDiscardableIfUnused() const
Definition: GlobalValue.h:547
static bool isExternalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:375
GlobalValue(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps, LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace)
Definition: GlobalValue.h:79
bool isStrongDefinitionForLinker() const
Returns true if this global's definition will be the one chosen by the linker.
Definition: GlobalValue.h:630
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:293
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition: GlobalValue.h:65
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:66
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:67
@ ProtectedVisibility
The GV is protected.
Definition: GlobalValue.h:68
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
static bool isValidDeclarationLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:417
static const unsigned GlobalValueSubClassDataBits
Definition: GlobalValue.h:93
static bool isInternalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:402
void setNoSanitizeMetadata()
Definition: Globals.cpp:251
bool hasSection() const
Definition: GlobalValue.h:289
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:253
bool canBenefitFromLocalAlias() const
Definition: Globals.cpp:112
bool hasComdat() const
Definition: GlobalValue.h:240
static bool isInterposableLinkage(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time.
Definition: GlobalValue.h:424
bool hasWeakLinkage() const
Definition: GlobalValue.h:521
bool hasAtLeastLocalUnnamedAddr() const
Returns true if this value's address is not significant in this module.
Definition: GlobalValue.h:223
unsigned getGlobalValueSubClassData() const
Definition: GlobalValue.h:174
static LinkageTypes getWeakLinkage(bool ODR)
Definition: GlobalValue.h:371
bool hasWeakODRLinkage() const
Definition: GlobalValue.h:523
void setGlobalValueSubClassData(unsigned V)
Definition: GlobalValue.h:177
unsigned IsDSOLocal
If true then there is a definition within the same linkage unit and that definition cannot be runtime...
Definition: GlobalValue.h:112
static LinkageTypes getLinkOnceLinkage(bool ODR)
Definition: GlobalValue.h:368
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 isWeakForLinker() const
Definition: GlobalValue.h:551
bool hasCommonLinkage() const
Definition: GlobalValue.h:531
bool hasGlobalUnnamedAddr() const
Definition: GlobalValue.h:214
Error materialize()
Make sure this GlobalValue is fully read.
Definition: Globals.cpp:48
UnnamedAddr getUnnamedAddr() const
Definition: GlobalValue.h:227
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
Definition: GlobalValue.h:457
GlobalValue(const GlobalValue &)=delete
bool hasAppendingLinkage() const
Definition: GlobalValue.h:524
unsigned ThreadLocal
Definition: GlobalValue.h:102
static bool isWeakLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:396
unsigned Linkage
Definition: GlobalValue.h:97
static bool isDiscardableIfUnused(LinkageTypes Linkage)
Whether the definition of this global may be discarded if it is not used in its compilation unit.
Definition: GlobalValue.h:448
void setSanitizerMetadata(SanitizerMetadata Meta)
Definition: Globals.cpp:239
static bool classof(const Value *V)
Definition: GlobalValue.h:659
bool hasLinkOnceODRLinkage() const
Definition: GlobalValue.h:518
bool canBeOmittedFromSymbolTable() const
True if GV can be left out of the object symbol table.
Definition: Globals.cpp:415
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:79
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:511
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:174
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:50
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:59
@ CommonLinkage
Tentative definitions.
Definition: GlobalValue.h:61
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:58
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
Definition: GlobalValue.h:53
@ WeakODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:56
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:51
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition: GlobalValue.h:55
@ AppendingLinkage
Special purpose, only applies to global arrays.
Definition: GlobalValue.h:57
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition: GlobalValue.h:52
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition: GlobalValue.h:60
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:54
void setThreadLocal(bool Val)
Definition: GlobalValue.h:263
DLLStorageClassTypes getDLLStorageClass() const
Definition: GlobalValue.h:274
Type * getValueType() const
Definition: GlobalValue.h:295
static bool isLinkOnceODRLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:384
bool hasProtectedVisibility() const
Definition: GlobalValue.h:250
unsigned DllStorageClass
Definition: GlobalValue.h:100
unsigned UnnamedAddrVal
Definition: GlobalValue.h:99
void setPartition(StringRef Part)
Definition: Globals.cpp:216
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Class to represent pointers.
Definition: DerivedTypes.h:646
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:679
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
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
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:377
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition: Value.h:532
ValueTy
Concrete subclass of this.
Definition: Value.h:513
#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
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
AddressSpace
Definition: NVPTXBaseInfo.h:21
constexpr char kGlobalIdentifierDelimiter
Definition: GlobalValue.h:45
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)