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