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