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 "llvm/Support/MD5.h"
28#include <cassert>
29#include <cstdint>
30#include <string>
31
32namespace llvm {
33
34class Comdat;
35class ConstantRange;
36class Error;
37class GlobalObject;
38class Module;
39
40namespace Intrinsic {
41typedef unsigned ID;
42} // end namespace Intrinsic
43
44// Choose ';' as the delimiter. ':' was used once but it doesn't work well for
45// Objective-C functions which commonly have :'s in their names.
46inline constexpr char kGlobalIdentifierDelimiter = ';';
47
48class GlobalValue : public Constant {
49public:
50 /// An enumeration for the kinds of linkage for global values.
52 ExternalLinkage = 0,///< Externally visible function
53 AvailableExternallyLinkage, ///< Available for inspection, not emission.
54 LinkOnceAnyLinkage, ///< Keep one copy of function when linking (inline)
55 LinkOnceODRLinkage, ///< Same, but only replaced by something equivalent.
56 WeakAnyLinkage, ///< Keep one copy of named function when linking (weak)
57 WeakODRLinkage, ///< Same, but only replaced by something equivalent.
58 AppendingLinkage, ///< Special purpose, only applies to global arrays
59 InternalLinkage, ///< Rename collisions when linking (static functions).
60 PrivateLinkage, ///< Like Internal, but omit from symbol table.
61 ExternalWeakLinkage,///< ExternalWeak linkage description.
62 CommonLinkage ///< Tentative definitions.
63 };
64
65 /// An enumeration for the kinds of visibility of global values.
67 DefaultVisibility = 0, ///< The GV is visible
68 HiddenVisibility, ///< The GV is hidden
69 ProtectedVisibility ///< The GV is protected
70 };
71
72 /// Storage classes of global values for PE targets.
75 DLLImportStorageClass = 1, ///< Function to be imported from DLL
76 DLLExportStorageClass = 2 ///< Function to be accessible from DLL.
77 };
78
79protected:
80 GlobalValue(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
81 LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace)
82 : Constant(PointerType::get(Ty, AddressSpace), VTy, Ops, NumOps),
90 }
91
93
94 static const unsigned GlobalValueSubClassDataBits = 15;
95
96 // All bitfields use unsigned as the underlying type so that MSVC will pack
97 // them.
98 unsigned Linkage : 4; // The linkage of this global
99 unsigned Visibility : 2; // The visibility style of this global
100 unsigned UnnamedAddrVal : 2; // This value's address is not significant
101 unsigned DllStorageClass : 2; // DLL storage class
102
103 unsigned ThreadLocal : 3; // Is this symbol "Thread Local", if so, what is
104 // the desired model?
105
106 /// True if the function's name starts with "llvm.". This corresponds to the
107 /// value of Function::isIntrinsic(), which may be true even if
108 /// Function::intrinsicID() returns Intrinsic::not_intrinsic.
110
111 /// If true then there is a definition within the same linkage unit and that
112 /// definition cannot be runtime preempted.
113 unsigned IsDSOLocal : 1;
114
115 /// True if this symbol has a partition name assigned (see
116 /// https://lld.llvm.org/Partitions.html).
117 unsigned HasPartition : 1;
118
119 /// True if this symbol has sanitizer metadata available. Should only happen
120 /// if sanitizers were enabled when building the translation unit which
121 /// contains this GV.
123
124private:
125 // Give subclasses access to what otherwise would be wasted padding.
126 // (15 + 4 + 2 + 2 + 2 + 3 + 1 + 1 + 1 + 1) == 32.
127 unsigned SubClassData : GlobalValueSubClassDataBits;
128
129 friend class Constant;
130
131 void destroyConstantImpl();
132 Value *handleOperandChangeImpl(Value *From, Value *To);
133
134 /// Returns true if the definition of this global may be replaced by a
135 /// differently optimized variant of the same source level function at link
136 /// time.
137 bool mayBeDerefined() const {
138 switch (getLinkage()) {
139 case WeakODRLinkage:
142 return true;
143
144 case WeakAnyLinkage:
146 case CommonLinkage:
148 case ExternalLinkage:
149 case AppendingLinkage:
150 case InternalLinkage:
151 case PrivateLinkage:
152 // Optimizations may assume builtin semantics for functions defined as
153 // nobuiltin due to attributes at call-sites. To avoid applying IPO based
154 // on nobuiltin semantics, treat such function definitions as maybe
155 // derefined.
156 return isInterposable() || isNobuiltinFnDef();
157 }
158
159 llvm_unreachable("Fully covered switch above!");
160 }
161
162 /// Returns true if the global is a function definition with the nobuiltin
163 /// attribute.
164 bool isNobuiltinFnDef() const;
165
166protected:
167 /// The intrinsic ID for this subclass (which must be a Function).
168 ///
169 /// This member is defined by this class, but not used for anything.
170 /// Subclasses can use it to store their intrinsic ID, if they have one.
171 ///
172 /// This is stored here to save space in Function on 64-bit hosts.
174
175 unsigned getGlobalValueSubClassData() const {
176 return SubClassData;
177 }
178 void setGlobalValueSubClassData(unsigned V) {
179 assert(V < (1 << GlobalValueSubClassDataBits) && "It will not fit");
180 SubClassData = V;
181 }
182
183 Module *Parent = nullptr; // The containing module.
184
185 // Used by SymbolTableListTraits.
186 void setParent(Module *parent) {
187 Parent = parent;
188 }
189
191 removeDeadConstantUsers(); // remove any dead constants using this.
192 }
193
194public:
201 };
202
203 GlobalValue(const GlobalValue &) = delete;
204
205 unsigned getAddressSpace() const {
206 return getType()->getAddressSpace();
207 }
208
209 enum class UnnamedAddr {
210 None,
211 Local,
212 Global,
213 };
214
215 bool hasGlobalUnnamedAddr() const {
217 }
218
219 /// Returns true if this value's address is not significant in this module.
220 /// This attribute is intended to be used only by the code generator and LTO
221 /// to allow the linker to decide whether the global needs to be in the symbol
222 /// table. It should probably not be used in optimizations, as the value may
223 /// have uses outside the module; use hasGlobalUnnamedAddr() instead.
226 }
227
230 }
232
235 return UnnamedAddr::None;
237 return UnnamedAddr::Local;
238 return UnnamedAddr::Global;
239 }
240
241 bool hasComdat() const { return getComdat() != nullptr; }
242 const Comdat *getComdat() const;
244 return const_cast<Comdat *>(
245 static_cast<const GlobalValue *>(this)->getComdat());
246 }
247
253 }
256 "local linkage requires default visibility");
257 Visibility = V;
258 if (isImplicitDSOLocal())
259 setDSOLocal(true);
260 }
261
262 /// If the value is "Thread Local", its value isn't shared by the threads.
263 bool isThreadLocal() const { return getThreadLocalMode() != NotThreadLocal; }
264 void setThreadLocal(bool Val) {
266 }
268 assert(Val == NotThreadLocal || getValueID() != Value::FunctionVal);
269 ThreadLocal = Val;
270 }
272 return static_cast<ThreadLocalMode>(ThreadLocal);
273 }
274
277 }
280 }
283 }
286 "local linkage requires DefaultStorageClass");
288 }
289
290 bool hasSection() const { return !getSection().empty(); }
291 StringRef getSection() const;
292
293 /// Global values are always pointers.
294 PointerType *getType() const { return cast<PointerType>(User::getType()); }
295
296 Type *getValueType() const { return ValueType; }
297
298 bool isImplicitDSOLocal() const {
299 return hasLocalLinkage() ||
301 }
302
304
305 bool isDSOLocal() const {
306 return IsDSOLocal;
307 }
308
309 bool hasPartition() const {
310 return HasPartition;
311 }
312 StringRef getPartition() const;
313 void setPartition(StringRef Part);
314
315 // ASan, HWASan and Memtag sanitizers have some instrumentation that applies
316 // specifically to global variables.
321 // For ASan and HWASan, this instrumentation is implicitly applied to all
322 // global variables when built with -fsanitize=*. What we need is a way to
323 // persist the information that a certain global variable should *not* have
324 // sanitizers applied, which occurs if:
325 // 1. The global variable is in the sanitizer ignore list, or
326 // 2. The global variable is created by the sanitizers itself for internal
327 // usage, or
328 // 3. The global variable has __attribute__((no_sanitize("..."))) or
329 // __attribute__((disable_sanitizer_instrumentation)).
330 //
331 // This is important, a some IR passes like GlobalMerge can delete global
332 // variables and replace them with new ones. If the old variables were
333 // marked to be unsanitized, then the new ones should also be.
334 unsigned NoAddress : 1;
335 unsigned NoHWAddress : 1;
336
337 // Memtag sanitization works differently: sanitization is requested by clang
338 // when `-fsanitize=memtag-globals` is provided, and the request can be
339 // denied (and the attribute removed) by the AArch64 global tagging pass if
340 // it can't be fulfilled (e.g. the global variable is a TLS variable).
341 // Memtag sanitization has to interact with other parts of LLVM (like
342 // supressing certain optimisations, emitting assembly directives, or
343 // creating special relocation sections).
344 //
345 // Use `GlobalValue::isTagged()` to check whether tagging should be enabled
346 // for a global variable.
347 unsigned Memtag : 1;
348
349 // ASan-specific metadata. Is this global variable dynamically initialized
350 // (from a C++ language perspective), and should therefore be checked for
351 // ODR violations.
352 unsigned IsDynInit : 1;
353 };
354
357 // Note: Not byref as it's a POD and otherwise it's too easy to call
358 // G.setSanitizerMetadata(G2.getSanitizerMetadata()), and the argument becomes
359 // dangling when the backing storage allocates the metadata for `G`, as the
360 // 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) { return MD5Hash(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:227
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:722
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:122
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:309
static bool isLinkOnceAnyLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:381
const SanitizerMetadata & getSanitizerMetadata() const
Definition: Globals.cpp:228
bool hasExternalLinkage() const
Definition: GlobalValue.h:510
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:239
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
Definition: GlobalValue.h:263
static bool isExternalWeakLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:411
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:248
bool isImplicitDSOLocal() const
Definition: GlobalValue.h:298
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:274
bool hasValidDeclarationLinkage() const
Definition: GlobalValue.h:532
LinkageTypes getLinkage() const
Definition: GlobalValue.h:545
void setUnnamedAddr(UnnamedAddr Val)
Definition: GlobalValue.h:231
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:249
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:373
bool isTagged() const
Definition: GlobalValue.h:364
void setDLLStorageClass(DLLStorageClassTypes C)
Definition: GlobalValue.h:284
const Comdat * getComdat() const
Definition: Globals.cpp:184
void setThreadLocalMode(ThreadLocalMode Val)
Definition: GlobalValue.h:267
unsigned Visibility
Definition: GlobalValue.h:99
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:173
bool hasHiddenVisibility() const
Definition: GlobalValue.h:250
bool hasExternalWeakLinkage() const
Definition: GlobalValue.h:528
ThreadLocalMode getThreadLocalMode() const
Definition: GlobalValue.h:271
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:109
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:378
bool hasWeakAnyLinkage() const
Definition: GlobalValue.h:522
void setParent(Module *parent)
Definition: GlobalValue.h:186
bool hasDLLImportStorageClass() const
Definition: GlobalValue.h:278
void setLinkage(LinkageTypes LT)
Definition: GlobalValue.h:536
DLLStorageClassTypes
Storage classes of global values for PE targets.
Definition: GlobalValue.h:73
@ DLLExportStorageClass
Function to be accessible from DLL.
Definition: GlobalValue.h:76
@ DLLImportStorageClass
Function to be imported from DLL.
Definition: GlobalValue.h:75
bool hasDLLExportStorageClass() const
Definition: GlobalValue.h:281
bool isDeclarationForLinker() const
Definition: GlobalValue.h:617
Comdat * getComdat()
Definition: GlobalValue.h:243
bool hasSanitizerMetadata() const
Definition: GlobalValue.h:355
static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B)
Definition: GlobalValue.h:233
GlobalObject * getAliaseeObject()
Definition: GlobalValue.h:635
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:594
StringRef getSection() const
Definition: Globals.cpp:174
StringRef getPartition() const
Definition: Globals.cpp:205
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:368
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:381
bool hasInternalLinkage() const
Definition: GlobalValue.h:525
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:86
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:80
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:294
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition: GlobalValue.h:66
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:67
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:68
@ ProtectedVisibility
The GV is protected.
Definition: GlobalValue.h:69
void copyAttributesFrom(const GlobalValue *Src)
Copy all additional attributes (those not needed to create a GlobalValue) from the GlobalValue Src to...
Definition: Globals.cpp:61
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:590
static bool isValidDeclarationLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:417
static const unsigned GlobalValueSubClassDataBits
Definition: GlobalValue.h:94
static bool isInternalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:402
bool hasSection() const
Definition: GlobalValue.h:290
bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
Definition: Globals.cpp:100
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:254
bool canBenefitFromLocalAlias() const
Definition: Globals.cpp:107
bool hasComdat() const
Definition: GlobalValue.h:241
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:224
unsigned getGlobalValueSubClassData() const
Definition: GlobalValue.h:175
static LinkageTypes getWeakLinkage(bool ODR)
Definition: GlobalValue.h:371
bool hasWeakODRLinkage() const
Definition: GlobalValue.h:523
void setGlobalValueSubClassData(unsigned V)
Definition: GlobalValue.h:178
unsigned IsDSOLocal
If true then there is a definition within the same linkage unit and that definition cannot be runtime...
Definition: GlobalValue.h:113
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:42
bool isWeakForLinker() const
Definition: GlobalValue.h:551
bool hasCommonLinkage() const
Definition: GlobalValue.h:531
bool hasGlobalUnnamedAddr() const
Definition: GlobalValue.h:215
Error materialize()
Make sure this GlobalValue is fully read.
Definition: Globals.cpp:47
UnnamedAddr getUnnamedAddr() const
Definition: GlobalValue.h:228
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:103
static bool isWeakLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:396
unsigned Linkage
Definition: GlobalValue.h:98
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:234
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:393
void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition: Globals.cpp:74
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:169
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:51
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:60
@ CommonLinkage
Tentative definitions.
Definition: GlobalValue.h:62
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:59
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
Definition: GlobalValue.h:54
@ WeakODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:57
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:52
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition: GlobalValue.h:56
@ AppendingLinkage
Special purpose, only applies to global arrays.
Definition: GlobalValue.h:58
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition: GlobalValue.h:53
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition: GlobalValue.h:61
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition: GlobalValue.h:55
void setThreadLocal(bool Val)
Definition: GlobalValue.h:264
DLLStorageClassTypes getDLLStorageClass() const
Definition: GlobalValue.h:275
Type * getValueType() const
Definition: GlobalValue.h:296
static bool isLinkOnceODRLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:384
bool hasProtectedVisibility() const
Definition: GlobalValue.h:251
unsigned DllStorageClass
Definition: GlobalValue.h:101
unsigned UnnamedAddrVal
Definition: GlobalValue.h:100
void setPartition(StringRef Part)
Definition: Globals.cpp:211
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
uint64_t MD5Hash(const FunctionId &Obj)
Definition: FunctionId.h:167
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:46
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)