LLVM 24.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"
28#include <cassert>
29#include <cstdint>
30#include <string>
31
32namespace llvm {
33
34class Comdat;
35class ConstantRange;
36class DataLayout;
37class Error;
38class GlobalObject;
39class Module;
40
41namespace Intrinsic {
42typedef unsigned ID;
43} // end namespace Intrinsic
44
45// Choose ';' as the delimiter. ':' was used once but it doesn't work well for
46// Objective-C functions which commonly have :'s in their names.
47inline constexpr char GlobalIdentifierDelimiter = ';';
48
49class GlobalValue : public Constant {
50public:
51 /// An enumeration for the kinds of linkage for global values.
53 ExternalLinkage = 0,///< Externally visible function
54 AvailableExternallyLinkage, ///< Available for inspection, not emission.
55 LinkOnceAnyLinkage, ///< Keep one copy of function when linking (inline)
56 LinkOnceODRLinkage, ///< Same, but only replaced by something equivalent.
57 WeakAnyLinkage, ///< Keep one copy of named function when linking (weak)
58 WeakODRLinkage, ///< Same, but only replaced by something equivalent.
59 AppendingLinkage, ///< Special purpose, only applies to global arrays
60 InternalLinkage, ///< Rename collisions when linking (static functions).
61 PrivateLinkage, ///< Like Internal, but omit from symbol table.
62 ExternalWeakLinkage,///< ExternalWeak linkage description.
63 CommonLinkage ///< Tentative definitions.
64 };
65
66 /// An enumeration for the kinds of visibility of global values.
68 DefaultVisibility = 0, ///< The GV is visible
69 HiddenVisibility, ///< The GV is hidden
70 ProtectedVisibility ///< The GV is protected
71 };
72
73 /// Storage classes of global values for PE targets.
76 DLLImportStorageClass = 1, ///< Function to be imported from DLL
77 DLLExportStorageClass = 2 ///< Function to be accessible from DLL.
78 };
79
80protected:
93
95
96 static const unsigned GlobalValueSubClassDataBits = 14;
97
98 // All bitfields use unsigned as the underlying type so that MSVC will pack
99 // them.
100 unsigned Linkage : 4; // The linkage of this global
101 unsigned Visibility : 2; // The visibility style of this global
102 unsigned UnnamedAddrVal : 2; // This value's address is not significant
103 unsigned DllStorageClass : 2; // DLL storage class
104
105 unsigned ThreadLocal : 3; // Is this symbol "Thread Local", if so, what is
106 // the desired model?
107
108 /// True if the function's name starts with "llvm.". This corresponds to the
109 /// value of Function::isIntrinsic(), which may be true even if
110 /// Function::intrinsicID() returns Intrinsic::not_intrinsic.
112
113 /// If true then there is a definition within the same linkage unit and that
114 /// definition cannot be runtime preempted.
115 unsigned IsDSOLocal : 1;
116
117 /// True if this symbol has a partition name assigned (see
118 /// https://lld.llvm.org/Partitions.html).
119 unsigned HasPartition : 1;
120
121 /// True if this symbol has sanitizer metadata available. Should only happen
122 /// if sanitizers were enabled when building the translation unit which
123 /// contains this GV.
125
126private:
127 /// Optimization hint for removeDeadConstantUsers. This bit is set to true
128 /// when non-GlobalValue Constants set this GlobalValue as an operand, and it
129 /// is cleared by removeDeadConstantUsers when no such Constant users remain.
130 /// While it is false, removeDeadConstantUsers does not need to walk the use
131 /// list (O(uses)), which is often long and cold for Functions with many
132 /// callers.
133 unsigned MayHaveConstantUsers : 1;
134
135 // Give subclasses access to what otherwise would be wasted padding.
136 // (14 + 4 + 2 + 2 + 2 + 3 + 1 + 1 + 1 + 1 + 1) == 32.
137 unsigned SubClassData : GlobalValueSubClassDataBits;
138
139 friend class Constant;
140
141 void destroyConstantImpl();
142 Value *handleOperandChangeImpl(Value *From, Value *To);
143
144 /// Returns true if the definition of this global may be replaced by a
145 /// differently optimized variant of the same source level function at link
146 /// time.
147 bool mayBeDerefined() const {
148 switch (getLinkage()) {
149 case WeakODRLinkage:
152 return true;
153
154 case WeakAnyLinkage:
156 case CommonLinkage:
158 case ExternalLinkage:
159 case AppendingLinkage:
160 case InternalLinkage:
161 case PrivateLinkage:
162 // Optimizations may assume builtin semantics for functions defined as
163 // nobuiltin due to attributes at call-sites. To avoid applying IPO based
164 // on nobuiltin semantics, treat such function definitions as maybe
165 // derefined.
166 return isInterposable() || isNobuiltinFnDef();
167 }
168
169 llvm_unreachable("Fully covered switch above!");
170 }
171
172 /// Returns true if the global is a function definition with the nobuiltin
173 /// attribute.
174 LLVM_ABI bool isNobuiltinFnDef() const;
175
176 /// Returns true if the global is a function definition with the noipa
177 /// attribute.
178 LLVM_ABI bool isNoipaFnDef() const;
179
180protected:
181 /// The intrinsic ID for this subclass (which must be a Function).
182 ///
183 /// This member is defined by this class, but not used for anything.
184 /// Subclasses can use it to store their intrinsic ID, if they have one.
185 ///
186 /// This is stored here to save space in Function on 64-bit hosts.
188
189 unsigned getGlobalValueSubClassData() const {
190 return SubClassData;
191 }
193 assert(V < (1 << GlobalValueSubClassDataBits) && "It will not fit");
194 SubClassData = V;
195 }
196
197 Module *Parent = nullptr; // The containing module.
198
199 // Used by SymbolTableListTraits.
200 void setParent(Module *parent) {
201 Parent = parent;
202 }
203
205 removeDeadConstantUsers(); // remove any dead constants using this.
206 }
207
208public:
216
217 GlobalValue(const GlobalValue &) = delete;
218
219 unsigned getAddressSpace() const {
220 return getType()->getAddressSpace();
221 }
222
223 enum class UnnamedAddr {
227 };
228
229 bool hasGlobalUnnamedAddr() const {
231 }
232
233 /// Returns true if this value's address is not significant in this module.
234 /// This attribute is intended to be used only by the code generator and LTO
235 /// to allow the linker to decide whether the global needs to be in the symbol
236 /// table. It should probably not be used in optimizations, as the value may
237 /// have uses outside the module; use hasGlobalUnnamedAddr() instead.
240 }
241
246
254
255 bool hasComdat() const { return getComdat() != nullptr; }
256 LLVM_ABI const Comdat *getComdat() const;
258 return const_cast<Comdat *>(
259 static_cast<const GlobalValue *>(this)->getComdat());
260 }
261
267 }
270 "local linkage requires default visibility");
271 Visibility = V;
272 if (isImplicitDSOLocal())
273 setDSOLocal(true);
274 }
275
276 /// If the value is "Thread Local", its value isn't shared by the threads.
277 bool isThreadLocal() const { return getThreadLocalMode() != NotThreadLocal; }
282 assert(Val == NotThreadLocal || getValueID() != Value::FunctionVal);
283 ThreadLocal = Val;
284 }
286 return static_cast<ThreadLocalMode>(ThreadLocal);
287 }
288
300 "local linkage requires DefaultStorageClass");
302 }
303
304 bool hasSection() const { return !getSection().empty(); }
306
307 /// Global values are always pointers.
309
310 Type *getValueType() const { return ValueType; }
311
312 bool isImplicitDSOLocal() const {
313 return hasLocalLinkage() ||
315 }
316
318
319 bool isDSOLocal() const {
320 return IsDSOLocal;
321 }
322
323 bool hasPartition() const {
324 return HasPartition;
325 }
328
329 // ASan, HWASan and Memtag sanitizers have some instrumentation that applies
330 // specifically to global variables.
335 // For ASan and HWASan, this instrumentation is implicitly applied to all
336 // global variables when built with -fsanitize=*. What we need is a way to
337 // persist the information that a certain global variable should *not* have
338 // sanitizers applied, which occurs if:
339 // 1. The global variable is in the sanitizer ignore list, or
340 // 2. The global variable is created by the sanitizers itself for internal
341 // usage, or
342 // 3. The global variable has __attribute__((no_sanitize("..."))) or
343 // __attribute__((disable_sanitizer_instrumentation)).
344 //
345 // This is important, a some IR passes like GlobalMerge can delete global
346 // variables and replace them with new ones. If the old variables were
347 // marked to be unsanitized, then the new ones should also be.
348 unsigned NoAddress : 1;
349 unsigned NoHWAddress : 1;
350
351 // Memtag sanitization works differently: sanitization is requested by clang
352 // when `-fsanitize=memtag-globals` is provided, and the request can be
353 // denied (and the attribute removed) by the AArch64 global tagging pass if
354 // it can't be fulfilled (e.g. the global variable is a TLS variable).
355 // Memtag sanitization has to interact with other parts of LLVM (like
356 // supressing certain optimisations, emitting assembly directives, or
357 // creating special relocation sections).
358 //
359 // Use `GlobalValue::isTagged()` to check whether tagging should be enabled
360 // for a global variable.
361 unsigned Memtag : 1;
362
363 // ASan-specific metadata. Is this global variable dynamically initialized
364 // (from a C++ language perspective), and should therefore be checked for
365 // ODR violations.
366 unsigned IsDynInit : 1;
367 };
368
370
371 /// Return true if a constant other than a GlobalValue may use this global,
372 /// that is, if removeDeadConstantUsers may have something to remove.
373 bool mayHaveConstantUsers() const { return MayHaveConstantUsers; }
374
375 /// Record that a constant other than a GlobalValue now uses this global.
376 void setMayHaveConstantUsers() { MayHaveConstantUsers = true; }
377
379 // Note: Not byref as it's a POD and otherwise it's too easy to call
380 // G.setSanitizerMetadata(G2.getSanitizerMetadata()), and the argument becomes
381 // dangling when the backing storage allocates the metadata for `G`, as the
382 // storage is shared between `G1` and `G2`.
386
387 bool isTagged() const {
389 }
390
393 }
394 static LinkageTypes getWeakLinkage(bool ODR) {
395 return ODR ? WeakODRLinkage : WeakAnyLinkage;
396 }
397
399 return Linkage == ExternalLinkage;
400 }
414 return Linkage == WeakAnyLinkage;
415 }
417 return Linkage == WeakODRLinkage;
418 }
426 return Linkage == InternalLinkage;
427 }
429 return Linkage == PrivateLinkage;
430 }
438 return Linkage == CommonLinkage;
439 }
443
444 /// Whether the definition of this global may be replaced by something
445 /// non-equivalent at link time. For example, if a function has weak linkage
446 /// then the code defining it may be replaced by different code.
448 switch (Linkage) {
449 case WeakAnyLinkage:
451 case CommonLinkage:
453 return true;
454
457 case WeakODRLinkage:
458 // The above three cannot be overridden but can be de-refined.
459
460 case ExternalLinkage:
461 case AppendingLinkage:
462 case InternalLinkage:
463 case PrivateLinkage:
464 return false;
465 }
466 llvm_unreachable("Fully covered switch above!");
467 }
468
469 /// Whether the definition of this global may be discarded if it is not used
470 /// in its compilation unit.
475
476 /// Whether the definition of this global may be replaced at link time. NB:
477 /// Using this method outside of the code generators is almost always a
478 /// mistake: when working at the IR level use isInterposable instead as it
479 /// knows about ODR semantics.
485
486 /// Return true if the currently visible definition of this global (if any) is
487 /// exactly the definition we will see at runtime.
488 ///
489 /// Non-exact linkage types inhibits most non-inlining IPO, since a
490 /// differently optimized variant of the same function can have different
491 /// observable or undefined behavior than in the variant currently visible.
492 /// For instance, we could have started with
493 ///
494 /// void foo(int *v) {
495 /// int t = 5 / v[0];
496 /// (void) t;
497 /// }
498 ///
499 /// and "refined" it to
500 ///
501 /// void foo(int *v) { }
502 ///
503 /// However, we cannot infer readnone for `foo`, since that would justify
504 /// DSE'ing a store to `v[0]` across a call to `foo`, which can cause
505 /// undefined behavior if the linker replaces the actual call destination with
506 /// the unoptimized `foo`.
507 ///
508 /// Inlining is okay across non-exact linkage types as long as they're not
509 /// interposable (see \c isInterposable), since in such cases the currently
510 /// visible variant is *a* correct implementation of the original source
511 /// function; it just isn't the *only* correct implementation.
512 bool isDefinitionExact() const {
513 return !mayBeDerefined();
514 }
515
516 /// Return true if this global has an exact defintion.
517 bool hasExactDefinition() const {
518 // While this computes exactly the same thing as
519 // isStrongDefinitionForLinker, the intended uses are different. This
520 // function is intended to help decide if specific inter-procedural
521 // transforms are correct, while isStrongDefinitionForLinker's intended use
522 // is in low level code generation.
523 return !isDeclaration() && isDefinitionExact();
524 }
525
526 /// Return true if this global's definition can be substituted with an
527 /// *arbitrary* definition at link time or load time. We cannot do any IPO or
528 /// inlining across interposable call edges, since the callee can be
529 /// replaced with something arbitrary. For most IPO passes, the `noipa`
530 /// attribute on a function definition is also treated as if it were
531 /// interposable (and thus blocking interprocedural analysis). Passes
532 /// which already have their own distinct control attributes (e.g. inlining)
533 /// may set `CheckNoIPA = false` when calling this.
534 LLVM_ABI bool isInterposable(bool CheckNoIPA = true) const;
536
544 }
547 }
548 bool hasWeakLinkage() const { return isWeakLinkage(getLinkage()); }
554 bool hasLocalLinkage() const { return isLocalLinkage(getLinkage()); }
557 }
558 bool hasCommonLinkage() const { return isCommonLinkage(getLinkage()); }
562
564 if (isLocalLinkage(LT)) {
567 }
568 Linkage = LT;
569 if (isImplicitDSOLocal())
570 setDSOLocal(true);
571 }
573
576 }
577
578 bool isWeakForLinker() const { return isWeakForLinker(getLinkage()); }
579
580 /// Assign a stable name to this GlobalValue if it is unnamed. setName will
581 /// make the name unique (e.g. __llvm_unnamed.1) if it is already taken.
582 void nameUnnamed() {
583 if (!hasName())
584 setName("__llvm_unnamed");
585 }
586
587 /// Promote this GlobalValue to external linkage with hidden visibility if
588 /// it has local linkage, and name it if it is unnamed.
596
597protected:
598 /// Copy all additional attributes (those not needed to create a GlobalValue)
599 /// from the GlobalValue Src to this one.
600 LLVM_ABI void copyAttributesFrom(const GlobalValue *Src);
601
602public:
603 /// If the given string begins with the GlobalValue name mangling escape
604 /// character '\1', drop it.
605 ///
606 /// This function applies a specific mangling that is used in PGO profiles,
607 /// among other things. If you're trying to get a symbol name for an
608 /// arbitrary GlobalValue, this is not the function you're looking for; see
609 /// Mangler.h.
611 Name.consume_front("\1");
612 return Name;
613 }
614
615 /// Declare a type to represent a global unique identifier for a global value.
616 /// This is a 64 bits hash that is used by PGO and ThinLTO to have a compact
617 /// unique way to identify a symbol.
618 using GUID = uint64_t;
619
620 /// Return the modified name for a global value suitable to be
621 /// used as the key for a global lookup (e.g. profile or ThinLTO).
622 /// The value's original name is \c Name and has linkage of type
623 /// \c Linkage. The value is defined in module \c FileName.
624 LLVM_ABI static std::string
626 StringRef FileName);
627
628private:
629 /// Return the modified name for this global value suitable to be
630 /// used as the key for a global lookup (e.g. profile or ThinLTO).
631 LLVM_ABI std::string getGlobalIdentifier() const;
632
633 /// Assign a GUID to this value based on its current name and linkage.
634 /// This GUID will remain the same even if those change. This method is
635 /// idempotent -- if a GUID has already been assigned, calling it again
636 /// will do nothing.
637 ///
638 /// This is private (exposed only to \c AssignGUIDPass), as users don't need
639 /// to call it. GUIDs are assigned only by \c AssignGUIDPass. The pass
640 /// pipeline should be set up such that GUIDs are always available when
641 /// needed. If not, the GUID assignment pass should be moved (or run again)
642 /// such that they are.
643 void assignGUID();
644
645 // assignGUID needs to be accessible from AssignGUIDPass, which is called
646 // early in the pipeline to make GUIDs available to later passes. But we'd
647 // rather not expose it publicly, as no-one else should call it.
648 friend class AssignGUIDPass;
649
650 MDNode *getGUIDMetadata() const;
651
652public:
653 /// Return a 64-bit global unique ID constructed from the name of a global
654 /// symbol. Since this call doesn't supply the linkage or defining filename,
655 /// the GUID computation will assume that the global has external linkage.
657
658 /// Recompute and assign a GUID to this value, replacing the existing GUID.
659 LLVM_ABI void reassignGUID();
660
661 /// Return a 64-bit global unique ID for this value. It is based on the
662 /// "original" name and linkage of this value (i.e. whenever its GUID was
663 /// assigned). This might not match the current name and linkage.
664 ///
665 /// The \c AssignGUIDPass must be run before this is called, otherwise
666 /// GUIDs won't be available. This pass can be run multiple times as it does
667 /// nothing if GUID metadata is already present.
668 LLVM_ABI GUID getGUID() const;
669
670 /// Return the GUID for this value if it has been assigned, nullopt
671 /// otherwise. This should only need to be used in some exceptional
672 /// situations. If possible whatever code needs access to a GUID should
673 /// be set up to run after AssignGUIDPass, in which case it will always
674 /// be available.
675 LLVM_ABI std::optional<GUID> getGUIDIfAssigned() const;
676
677 /// Return the GUID for this value if it has been assigned, otherwise fall
678 /// back to computing it based on its current name and linkage.
679 ///
680 /// This is to be used in situations where we need a GUID but can't guarantee
681 /// that it's been computed. Notably, if we're reading from bitcode files
682 /// that might pre-date the storage of GUIDs in metadata.
684
685 /// @name Materialization
686 /// Materialization is used to construct functions only as they're needed.
687 /// This
688 /// is useful to reduce memory usage in LLVM or parsing work done by the
689 /// BitcodeReader to load the Module.
690 /// @{
691
692 /// If this function's Module is being lazily streamed in functions from disk
693 /// or some other source, this method can be used to check to see if the
694 /// function has been read in yet or not.
695 LLVM_ABI bool isMaterializable() const;
696
697 /// Make sure this GlobalValue is fully read.
699
700 /// @}
701
702 /// Return true if the primary definition of this global value is outside of
703 /// the current translation unit.
704 LLVM_ABI bool isDeclaration() const;
705
708 return true;
709
710 return isDeclaration();
711 }
712
713 /// Returns true if this global's definition will be the one chosen by the
714 /// linker.
715 ///
716 /// NB! Ideally this should not be used at the IR level at all. If you're
717 /// interested in optimization constraints implied by the linker's ability to
718 /// choose an implementation, prefer using \c hasExactDefinition.
721 }
722
725 return const_cast<GlobalObject *>(
726 static_cast<const GlobalValue *>(this)->getAliaseeObject());
727 }
728
729 /// Returns whether this is a reference to an absolute symbol.
730 LLVM_ABI bool isAbsoluteSymbolRef() const;
731
732 /// If this is an absolute symbol reference, returns the range of the symbol,
733 /// otherwise returns std::nullopt.
734 LLVM_ABI std::optional<ConstantRange> getAbsoluteSymbolRange() const;
735
736 /// This method unlinks 'this' from the containing module, but does not delete
737 /// it.
739
740 /// This method unlinks 'this' from the containing module and deletes it.
742
743 /// Get the module that this global value is contained inside of...
744 Module *getParent() { return Parent; }
745 const Module *getParent() const { return Parent; }
746
747 /// Get the data layout of the module this global belongs to.
748 ///
749 /// Requires the global to have a parent module.
750 LLVM_ABI const DataLayout &getDataLayout() const;
751
752 // Methods for support type inquiry through isa, cast, and dyn_cast:
753 static bool classof(const Value *V) {
754 return V->getValueID() == Value::FunctionVal ||
755 V->getValueID() == Value::GlobalVariableVal ||
756 V->getValueID() == Value::GlobalAliasVal ||
757 V->getValueID() == Value::GlobalIFuncVal;
758 }
759
760 /// True if GV can be left out of the object symbol table. This is the case
761 /// for linkonce_odr values whose address is not significant. While legal, it
762 /// is not normally profitable to omit them from the .o symbol table. Using
763 /// this analysis makes sense when the information can be passed down to the
764 /// linker or we are in LTO.
766};
767
768} // end namespace llvm
769
770#endif // LLVM_IR_GLOBALVALUE_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
GlobalValue::SanitizerMetadata SanitizerMetadata
Definition Globals.cpp:317
This class represents a range of values.
LLVM_ABI void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
bool isDefinitionExact() const
Return true if the currently visible definition of this global (if any) is exactly the definition we ...
unsigned HasSanitizerMetadata
True if this symbol has sanitizer metadata available.
static bool isWeakAnyLinkage(LinkageTypes Linkage)
bool hasLinkOnceLinkage() const
const Module * getParent() const
static bool isAppendingLinkage(LinkageTypes Linkage)
void externalize()
Promote this GlobalValue to external linkage with hidden visibility if it has local linkage,...
bool hasPartition() const
static bool isLinkOnceAnyLinkage(LinkageTypes Linkage)
static LLVM_ABI GUID getGUIDAssumingExternalLinkage(StringRef GlobalName)
Return a 64-bit global unique ID constructed from the name of a global symbol.
Definition Globals.cpp:80
LLVM_ABI const SanitizerMetadata & getSanitizerMetadata() const
Definition Globals.cpp:318
bool hasExternalLinkage() const
bool isDSOLocal() const
unsigned HasPartition
True if this symbol has a partition name assigned (see https://lld.llvm.org/Partitions....
LLVM_ABI void removeSanitizerMetadata()
Definition Globals.cpp:329
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
static bool isExternalWeakLinkage(LinkageTypes Linkage)
VisibilityTypes getVisibility() const
bool isImplicitDSOLocal() const
static bool isLocalLinkage(LinkageTypes Linkage)
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition Globals.cpp:408
bool hasValidDeclarationLinkage() const
LinkageTypes getLinkage() const
void setUnnamedAddr(UnnamedAddr Val)
static bool isWeakODRLinkage(LinkageTypes Linkage)
bool hasLinkOnceAnyLinkage() const
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
bool hasLocalLinkage() const
LLVM_ABI GUID getGUIDOrFallback() const
Return the GUID for this value if it has been assigned, otherwise fall back to computing it based on ...
Definition Globals.cpp:110
bool hasDefaultVisibility() const
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
bool hasPrivateLinkage() const
LLVM_ABI bool isAbsoluteSymbolRef() const
Returns whether this is a reference to an absolute symbol.
Definition Globals.cpp:526
bool isTagged() const
void setDLLStorageClass(DLLStorageClassTypes C)
LLVM_ABI const Comdat * getComdat() const
Definition Globals.cpp:274
void setThreadLocalMode(ThreadLocalMode Val)
static bool isLinkOnceLinkage(LinkageTypes Linkage)
Intrinsic::ID IntID
The intrinsic ID for this subclass (which must be a Function).
bool hasHiddenVisibility() const
bool hasExternalWeakLinkage() const
ThreadLocalMode getThreadLocalMode() const
bool hasExactDefinition() const
Return true if this global has an exact defintion.
unsigned HasLLVMReservedName
True if the function's name starts with "llvm.".
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
friend class Constant
bool hasWeakAnyLinkage() const
void setParent(Module *parent)
bool hasDLLImportStorageClass() const
void setLinkage(LinkageTypes LT)
DLLStorageClassTypes
Storage classes of global values for PE targets.
Definition GlobalValue.h:74
@ DLLExportStorageClass
Function to be accessible from DLL.
Definition GlobalValue.h:77
@ DLLImportStorageClass
Function to be imported from DLL.
Definition GlobalValue.h:76
bool hasDLLExportStorageClass() const
bool isDeclarationForLinker() const
Comdat * getComdat()
bool hasSanitizerMetadata() const
static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B)
GlobalObject * getAliaseeObject()
unsigned getAddressSpace() const
LLVM_ABI StringRef getSection() const
Definition Globals.cpp:264
LLVM_ABI StringRef getPartition() const
Definition Globals.cpp:295
Module * getParent()
Get the module that this global value is contained inside of...
static bool isCommonLinkage(LinkageTypes Linkage)
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition Globals.cpp:521
void setDSOLocal(bool Local)
LLVM_ABI 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:534
void setMayHaveConstantUsers()
Record that a constant other than a GlobalValue now uses this global.
bool hasInternalLinkage() const
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition Globals.cpp:158
void nameUnnamed()
Assign a stable name to this GlobalValue if it is unnamed.
static bool isPrivateLinkage(LinkageTypes Linkage)
LLVM_ABI GUID getGUID() const
Return a 64-bit global unique ID for this value.
Definition Globals.cpp:103
bool isDiscardableIfUnused() const
static bool isExternalLinkage(LinkageTypes Linkage)
friend class AssignGUIDPass
LLVM_ABI std::optional< GUID > getGUIDIfAssigned() const
Return the GUID for this value if it has been assigned, nullopt otherwise.
Definition Globals.cpp:116
bool isStrongDefinitionForLinker() const
Returns true if this global's definition will be the one chosen by the linker.
PointerType * getType() const
Global values are always pointers.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition GlobalValue.h:67
@ DefaultVisibility
The GV is visible.
Definition GlobalValue.h:68
@ HiddenVisibility
The GV is hidden.
Definition GlobalValue.h:69
@ ProtectedVisibility
The GV is protected.
Definition GlobalValue.h:70
LLVM_ABI void copyAttributesFrom(const GlobalValue *Src)
Copy all additional attributes (those not needed to create a GlobalValue) from the GlobalValue Src to...
Definition Globals.cpp:66
static bool isValidDeclarationLinkage(LinkageTypes Linkage)
static const unsigned GlobalValueSubClassDataBits
Definition GlobalValue.h:96
static bool isInternalLinkage(LinkageTypes Linkage)
static LLVM_ABI std::string getGlobalIdentifier(StringRef Name, GlobalValue::LinkageTypes Linkage, StringRef FileName)
Return the modified name for a global value suitable to be used as the key for a global lookup (e....
Definition Globals.cpp:234
LLVM_ABI void setNoSanitizeMetadata()
Definition Globals.cpp:336
bool hasSection() const
void setVisibility(VisibilityTypes V)
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Definition Globals.cpp:205
LLVM_ABI bool canBenefitFromLocalAlias() const
Definition Globals.cpp:187
bool hasComdat() const
static bool isInterposableLinkage(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time.
bool hasWeakLinkage() const
bool hasAtLeastLocalUnnamedAddr() const
Returns true if this value's address is not significant in this module.
unsigned getGlobalValueSubClassData() const
static LinkageTypes getWeakLinkage(bool ODR)
bool hasWeakODRLinkage() const
void setGlobalValueSubClassData(unsigned V)
unsigned IsDSOLocal
If true then there is a definition within the same linkage unit and that definition cannot be runtime...
static LinkageTypes getLinkOnceLinkage(bool ODR)
LLVM_ABI bool isMaterializable() const
If this function's Module is being lazily streamed in functions from disk or some other source,...
Definition Globals.cpp:47
bool isWeakForLinker() const
bool hasCommonLinkage() const
bool hasGlobalUnnamedAddr() const
LLVM_ABI Error materialize()
Make sure this GlobalValue is fully read.
Definition Globals.cpp:52
UnnamedAddr getUnnamedAddr() const
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
GlobalValue(const GlobalValue &)=delete
bool hasAppendingLinkage() const
bool mayHaveConstantUsers() const
Return true if a constant other than a GlobalValue may use this global, that is, if removeDeadConstan...
static bool isWeakLinkage(LinkageTypes Linkage)
static bool isDiscardableIfUnused(LinkageTypes Linkage)
Whether the definition of this global may be discarded if it is not used in its compilation unit.
LLVM_ABI void setSanitizerMetadata(SanitizerMetadata Meta)
Definition Globals.cpp:324
static bool classof(const Value *V)
bool hasLinkOnceODRLinkage() const
LLVM_ABI bool canBeOmittedFromSymbolTable() const
True if GV can be left out of the object symbol table.
Definition Globals.cpp:546
LLVM_ABI void reassignGUID()
Recompute and assign a GUID to this value, replacing the existing GUID.
Definition Globals.cpp:96
LLVM_ABI void removeFromParent()
This method unlinks 'this' from the containing module, but does not delete it.
Definition Globals.cpp:146
bool hasAvailableExternallyLinkage() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition GlobalValue.h:52
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition GlobalValue.h:61
@ CommonLinkage
Tentative definitions.
Definition GlobalValue.h:63
@ InternalLinkage
Rename collisions when linking (static functions).
Definition GlobalValue.h:60
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
Definition GlobalValue.h:55
@ WeakODRLinkage
Same, but only replaced by something equivalent.
Definition GlobalValue.h:58
@ ExternalLinkage
Externally visible function.
Definition GlobalValue.h:53
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition GlobalValue.h:57
@ AppendingLinkage
Special purpose, only applies to global arrays.
Definition GlobalValue.h:59
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition GlobalValue.h:54
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition GlobalValue.h:62
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition GlobalValue.h:56
void setThreadLocal(bool Val)
DLLStorageClassTypes getDLLStorageClass() const
Type * getValueType() const
GlobalValue(Type *Ty, ValueTy VTy, AllocInfo AllocInfo, LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace)
Definition GlobalValue.h:81
static bool isLinkOnceODRLinkage(LinkageTypes Linkage)
bool hasProtectedVisibility() const
LLVM_ABI bool isInterposable(bool CheckNoIPA=true) const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
Definition Globals.cpp:178
unsigned DllStorageClass
unsigned UnnamedAddrVal
LLVM_ABI void setPartition(StringRef Part)
Definition Globals.cpp:301
Metadata node.
Definition Metadata.h:1081
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
Class to represent pointers.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
Definition Value.cpp:389
LLVMContext & getContext() const
All values hold a context through their type.
Definition Value.h:260
unsigned getValueID() const
Return an ID for the concrete type of this object.
Definition Value.h:545
bool hasName() const
Definition Value.h:263
ValueTy
Concrete subclass of this.
Definition Value.h:526
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
constexpr char GlobalIdentifierDelimiter
Definition GlobalValue.h:47
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
Information about how a User object was allocated, to be passed into the User constructor.
Definition User.h:79