GlobalValue.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/GlobalValue.h - Class to represent a global value --*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file is a common base class of all globally definable objects. As such,
  15. // it is subclassed by GlobalVariable, GlobalAlias and by Function. This is
  16. // used because you can do certain things with these global objects that you
  17. // can't do to anything else. For example, use the address of one as a
  18. // constant.
  19. //
  20. //===----------------------------------------------------------------------===//
  21. #ifndef LLVM_IR_GLOBALVALUE_H
  22. #define LLVM_IR_GLOBALVALUE_H
  23. #include "llvm/ADT/StringRef.h"
  24. #include "llvm/ADT/Twine.h"
  25. #include "llvm/IR/Constant.h"
  26. #include "llvm/IR/DerivedTypes.h"
  27. #include "llvm/IR/Value.h"
  28. #include "llvm/Support/Casting.h"
  29. #include "llvm/Support/ErrorHandling.h"
  30. #include "llvm/Support/MD5.h"
  31. #include <cassert>
  32. #include <cstdint>
  33. #include <string>
  34. namespace llvm {
  35. class Comdat;
  36. class ConstantRange;
  37. class Error;
  38. class GlobalObject;
  39. class Module;
  40. namespace Intrinsic {
  41. typedef unsigned ID;
  42. } // end namespace Intrinsic
  43. class GlobalValue : public Constant {
  44. public:
  45. /// An enumeration for the kinds of linkage for global values.
  46. enum LinkageTypes {
  47. ExternalLinkage = 0,///< Externally visible function
  48. AvailableExternallyLinkage, ///< Available for inspection, not emission.
  49. LinkOnceAnyLinkage, ///< Keep one copy of function when linking (inline)
  50. LinkOnceODRLinkage, ///< Same, but only replaced by something equivalent.
  51. WeakAnyLinkage, ///< Keep one copy of named function when linking (weak)
  52. WeakODRLinkage, ///< Same, but only replaced by something equivalent.
  53. AppendingLinkage, ///< Special purpose, only applies to global arrays
  54. InternalLinkage, ///< Rename collisions when linking (static functions).
  55. PrivateLinkage, ///< Like Internal, but omit from symbol table.
  56. ExternalWeakLinkage,///< ExternalWeak linkage description.
  57. CommonLinkage ///< Tentative definitions.
  58. };
  59. /// An enumeration for the kinds of visibility of global values.
  60. enum VisibilityTypes {
  61. DefaultVisibility = 0, ///< The GV is visible
  62. HiddenVisibility, ///< The GV is hidden
  63. ProtectedVisibility ///< The GV is protected
  64. };
  65. /// Storage classes of global values for PE targets.
  66. enum DLLStorageClassTypes {
  67. DefaultStorageClass = 0,
  68. DLLImportStorageClass = 1, ///< Function to be imported from DLL
  69. DLLExportStorageClass = 2 ///< Function to be accessible from DLL.
  70. };
  71. protected:
  72. GlobalValue(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps,
  73. LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace)
  74. : Constant(PointerType::get(Ty, AddressSpace), VTy, Ops, NumOps),
  75. ValueType(Ty), Visibility(DefaultVisibility),
  76. UnnamedAddrVal(unsigned(UnnamedAddr::None)),
  77. DllStorageClass(DefaultStorageClass), ThreadLocal(NotThreadLocal),
  78. HasLLVMReservedName(false), IsDSOLocal(false), HasPartition(false),
  79. IntID((Intrinsic::ID)0U), Parent(nullptr) {
  80. setLinkage(Linkage);
  81. setName(Name);
  82. }
  83. Type *ValueType;
  84. static const unsigned GlobalValueSubClassDataBits = 16;
  85. // All bitfields use unsigned as the underlying type so that MSVC will pack
  86. // them.
  87. unsigned Linkage : 4; // The linkage of this global
  88. unsigned Visibility : 2; // The visibility style of this global
  89. unsigned UnnamedAddrVal : 2; // This value's address is not significant
  90. unsigned DllStorageClass : 2; // DLL storage class
  91. unsigned ThreadLocal : 3; // Is this symbol "Thread Local", if so, what is
  92. // the desired model?
  93. /// True if the function's name starts with "llvm.". This corresponds to the
  94. /// value of Function::isIntrinsic(), which may be true even if
  95. /// Function::intrinsicID() returns Intrinsic::not_intrinsic.
  96. unsigned HasLLVMReservedName : 1;
  97. /// If true then there is a definition within the same linkage unit and that
  98. /// definition cannot be runtime preempted.
  99. unsigned IsDSOLocal : 1;
  100. /// True if this symbol has a partition name assigned (see
  101. /// https://lld.llvm.org/Partitions.html).
  102. unsigned HasPartition : 1;
  103. private:
  104. // Give subclasses access to what otherwise would be wasted padding.
  105. // (16 + 4 + 2 + 2 + 2 + 3 + 1 + 1 + 1) == 32.
  106. unsigned SubClassData : GlobalValueSubClassDataBits;
  107. friend class Constant;
  108. void destroyConstantImpl();
  109. Value *handleOperandChangeImpl(Value *From, Value *To);
  110. /// Returns true if the definition of this global may be replaced by a
  111. /// differently optimized variant of the same source level function at link
  112. /// time.
  113. bool mayBeDerefined() const {
  114. switch (getLinkage()) {
  115. case WeakODRLinkage:
  116. case LinkOnceODRLinkage:
  117. case AvailableExternallyLinkage:
  118. return true;
  119. case WeakAnyLinkage:
  120. case LinkOnceAnyLinkage:
  121. case CommonLinkage:
  122. case ExternalWeakLinkage:
  123. case ExternalLinkage:
  124. case AppendingLinkage:
  125. case InternalLinkage:
  126. case PrivateLinkage:
  127. return isInterposable();
  128. }
  129. llvm_unreachable("Fully covered switch above!");
  130. }
  131. protected:
  132. /// The intrinsic ID for this subclass (which must be a Function).
  133. ///
  134. /// This member is defined by this class, but not used for anything.
  135. /// Subclasses can use it to store their intrinsic ID, if they have one.
  136. ///
  137. /// This is stored here to save space in Function on 64-bit hosts.
  138. Intrinsic::ID IntID;
  139. unsigned getGlobalValueSubClassData() const {
  140. return SubClassData;
  141. }
  142. void setGlobalValueSubClassData(unsigned V) {
  143. assert(V < (1 << GlobalValueSubClassDataBits) && "It will not fit");
  144. SubClassData = V;
  145. }
  146. Module *Parent; // The containing module.
  147. // Used by SymbolTableListTraits.
  148. void setParent(Module *parent) {
  149. Parent = parent;
  150. }
  151. ~GlobalValue() {
  152. removeDeadConstantUsers(); // remove any dead constants using this.
  153. }
  154. public:
  155. enum ThreadLocalMode {
  156. NotThreadLocal = 0,
  157. GeneralDynamicTLSModel,
  158. LocalDynamicTLSModel,
  159. InitialExecTLSModel,
  160. LocalExecTLSModel
  161. };
  162. GlobalValue(const GlobalValue &) = delete;
  163. unsigned getAddressSpace() const;
  164. enum class UnnamedAddr {
  165. None,
  166. Local,
  167. Global,
  168. };
  169. bool hasGlobalUnnamedAddr() const {
  170. return getUnnamedAddr() == UnnamedAddr::Global;
  171. }
  172. /// Returns true if this value's address is not significant in this module.
  173. /// This attribute is intended to be used only by the code generator and LTO
  174. /// to allow the linker to decide whether the global needs to be in the symbol
  175. /// table. It should probably not be used in optimizations, as the value may
  176. /// have uses outside the module; use hasGlobalUnnamedAddr() instead.
  177. bool hasAtLeastLocalUnnamedAddr() const {
  178. return getUnnamedAddr() != UnnamedAddr::None;
  179. }
  180. UnnamedAddr getUnnamedAddr() const {
  181. return UnnamedAddr(UnnamedAddrVal);
  182. }
  183. void setUnnamedAddr(UnnamedAddr Val) { UnnamedAddrVal = unsigned(Val); }
  184. static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B) {
  185. if (A == UnnamedAddr::None || B == UnnamedAddr::None)
  186. return UnnamedAddr::None;
  187. if (A == UnnamedAddr::Local || B == UnnamedAddr::Local)
  188. return UnnamedAddr::Local;
  189. return UnnamedAddr::Global;
  190. }
  191. bool hasComdat() const { return getComdat() != nullptr; }
  192. const Comdat *getComdat() const;
  193. Comdat *getComdat() {
  194. return const_cast<Comdat *>(
  195. static_cast<const GlobalValue *>(this)->getComdat());
  196. }
  197. VisibilityTypes getVisibility() const { return VisibilityTypes(Visibility); }
  198. bool hasDefaultVisibility() const { return Visibility == DefaultVisibility; }
  199. bool hasHiddenVisibility() const { return Visibility == HiddenVisibility; }
  200. bool hasProtectedVisibility() const {
  201. return Visibility == ProtectedVisibility;
  202. }
  203. void setVisibility(VisibilityTypes V) {
  204. assert((!hasLocalLinkage() || V == DefaultVisibility) &&
  205. "local linkage requires default visibility");
  206. Visibility = V;
  207. if (isImplicitDSOLocal())
  208. setDSOLocal(true);
  209. }
  210. /// If the value is "Thread Local", its value isn't shared by the threads.
  211. bool isThreadLocal() const { return getThreadLocalMode() != NotThreadLocal; }
  212. void setThreadLocal(bool Val) {
  213. setThreadLocalMode(Val ? GeneralDynamicTLSModel : NotThreadLocal);
  214. }
  215. void setThreadLocalMode(ThreadLocalMode Val) {
  216. assert(Val == NotThreadLocal || getValueID() != Value::FunctionVal);
  217. ThreadLocal = Val;
  218. }
  219. ThreadLocalMode getThreadLocalMode() const {
  220. return static_cast<ThreadLocalMode>(ThreadLocal);
  221. }
  222. DLLStorageClassTypes getDLLStorageClass() const {
  223. return DLLStorageClassTypes(DllStorageClass);
  224. }
  225. bool hasDLLImportStorageClass() const {
  226. return DllStorageClass == DLLImportStorageClass;
  227. }
  228. bool hasDLLExportStorageClass() const {
  229. return DllStorageClass == DLLExportStorageClass;
  230. }
  231. void setDLLStorageClass(DLLStorageClassTypes C) { DllStorageClass = C; }
  232. bool hasSection() const { return !getSection().empty(); }
  233. StringRef getSection() const;
  234. /// Global values are always pointers.
  235. PointerType *getType() const { return cast<PointerType>(User::getType()); }
  236. Type *getValueType() const { return ValueType; }
  237. bool isImplicitDSOLocal() const {
  238. return hasLocalLinkage() ||
  239. (!hasDefaultVisibility() && !hasExternalWeakLinkage());
  240. }
  241. void setDSOLocal(bool Local) { IsDSOLocal = Local; }
  242. bool isDSOLocal() const {
  243. return IsDSOLocal;
  244. }
  245. bool hasPartition() const {
  246. return HasPartition;
  247. }
  248. StringRef getPartition() const;
  249. void setPartition(StringRef Part);
  250. static LinkageTypes getLinkOnceLinkage(bool ODR) {
  251. return ODR ? LinkOnceODRLinkage : LinkOnceAnyLinkage;
  252. }
  253. static LinkageTypes getWeakLinkage(bool ODR) {
  254. return ODR ? WeakODRLinkage : WeakAnyLinkage;
  255. }
  256. static bool isExternalLinkage(LinkageTypes Linkage) {
  257. return Linkage == ExternalLinkage;
  258. }
  259. static bool isAvailableExternallyLinkage(LinkageTypes Linkage) {
  260. return Linkage == AvailableExternallyLinkage;
  261. }
  262. static bool isLinkOnceAnyLinkage(LinkageTypes Linkage) {
  263. return Linkage == LinkOnceAnyLinkage;
  264. }
  265. static bool isLinkOnceODRLinkage(LinkageTypes Linkage) {
  266. return Linkage == LinkOnceODRLinkage;
  267. }
  268. static bool isLinkOnceLinkage(LinkageTypes Linkage) {
  269. return isLinkOnceAnyLinkage(Linkage) || isLinkOnceODRLinkage(Linkage);
  270. }
  271. static bool isWeakAnyLinkage(LinkageTypes Linkage) {
  272. return Linkage == WeakAnyLinkage;
  273. }
  274. static bool isWeakODRLinkage(LinkageTypes Linkage) {
  275. return Linkage == WeakODRLinkage;
  276. }
  277. static bool isWeakLinkage(LinkageTypes Linkage) {
  278. return isWeakAnyLinkage(Linkage) || isWeakODRLinkage(Linkage);
  279. }
  280. static bool isAppendingLinkage(LinkageTypes Linkage) {
  281. return Linkage == AppendingLinkage;
  282. }
  283. static bool isInternalLinkage(LinkageTypes Linkage) {
  284. return Linkage == InternalLinkage;
  285. }
  286. static bool isPrivateLinkage(LinkageTypes Linkage) {
  287. return Linkage == PrivateLinkage;
  288. }
  289. static bool isLocalLinkage(LinkageTypes Linkage) {
  290. return isInternalLinkage(Linkage) || isPrivateLinkage(Linkage);
  291. }
  292. static bool isExternalWeakLinkage(LinkageTypes Linkage) {
  293. return Linkage == ExternalWeakLinkage;
  294. }
  295. static bool isCommonLinkage(LinkageTypes Linkage) {
  296. return Linkage == CommonLinkage;
  297. }
  298. static bool isValidDeclarationLinkage(LinkageTypes Linkage) {
  299. return isExternalWeakLinkage(Linkage) || isExternalLinkage(Linkage);
  300. }
  301. /// Whether the definition of this global may be replaced by something
  302. /// non-equivalent at link time. For example, if a function has weak linkage
  303. /// then the code defining it may be replaced by different code.
  304. static bool isInterposableLinkage(LinkageTypes Linkage) {
  305. switch (Linkage) {
  306. case WeakAnyLinkage:
  307. case LinkOnceAnyLinkage:
  308. case CommonLinkage:
  309. case ExternalWeakLinkage:
  310. return true;
  311. case AvailableExternallyLinkage:
  312. case LinkOnceODRLinkage:
  313. case WeakODRLinkage:
  314. // The above three cannot be overridden but can be de-refined.
  315. case ExternalLinkage:
  316. case AppendingLinkage:
  317. case InternalLinkage:
  318. case PrivateLinkage:
  319. return false;
  320. }
  321. llvm_unreachable("Fully covered switch above!");
  322. }
  323. /// Whether the definition of this global may be discarded if it is not used
  324. /// in its compilation unit.
  325. static bool isDiscardableIfUnused(LinkageTypes Linkage) {
  326. return isLinkOnceLinkage(Linkage) || isLocalLinkage(Linkage) ||
  327. isAvailableExternallyLinkage(Linkage);
  328. }
  329. /// Whether the definition of this global may be replaced at link time. NB:
  330. /// Using this method outside of the code generators is almost always a
  331. /// mistake: when working at the IR level use isInterposable instead as it
  332. /// knows about ODR semantics.
  333. static bool isWeakForLinker(LinkageTypes Linkage) {
  334. return Linkage == WeakAnyLinkage || Linkage == WeakODRLinkage ||
  335. Linkage == LinkOnceAnyLinkage || Linkage == LinkOnceODRLinkage ||
  336. Linkage == CommonLinkage || Linkage == ExternalWeakLinkage;
  337. }
  338. /// Return true if the currently visible definition of this global (if any) is
  339. /// exactly the definition we will see at runtime.
  340. ///
  341. /// Non-exact linkage types inhibits most non-inlining IPO, since a
  342. /// differently optimized variant of the same function can have different
  343. /// observable or undefined behavior than in the variant currently visible.
  344. /// For instance, we could have started with
  345. ///
  346. /// void foo(int *v) {
  347. /// int t = 5 / v[0];
  348. /// (void) t;
  349. /// }
  350. ///
  351. /// and "refined" it to
  352. ///
  353. /// void foo(int *v) { }
  354. ///
  355. /// However, we cannot infer readnone for `foo`, since that would justify
  356. /// DSE'ing a store to `v[0]` across a call to `foo`, which can cause
  357. /// undefined behavior if the linker replaces the actual call destination with
  358. /// the unoptimized `foo`.
  359. ///
  360. /// Inlining is okay across non-exact linkage types as long as they're not
  361. /// interposable (see \c isInterposable), since in such cases the currently
  362. /// visible variant is *a* correct implementation of the original source
  363. /// function; it just isn't the *only* correct implementation.
  364. bool isDefinitionExact() const {
  365. return !mayBeDerefined();
  366. }
  367. /// Return true if this global has an exact defintion.
  368. bool hasExactDefinition() const {
  369. // While this computes exactly the same thing as
  370. // isStrongDefinitionForLinker, the intended uses are different. This
  371. // function is intended to help decide if specific inter-procedural
  372. // transforms are correct, while isStrongDefinitionForLinker's intended use
  373. // is in low level code generation.
  374. return !isDeclaration() && isDefinitionExact();
  375. }
  376. /// Return true if this global's definition can be substituted with an
  377. /// *arbitrary* definition at link time or load time. We cannot do any IPO or
  378. /// inlining across interposable call edges, since the callee can be
  379. /// replaced with something arbitrary.
  380. bool isInterposable() const;
  381. bool canBenefitFromLocalAlias() const;
  382. bool hasExternalLinkage() const { return isExternalLinkage(getLinkage()); }
  383. bool hasAvailableExternallyLinkage() const {
  384. return isAvailableExternallyLinkage(getLinkage());
  385. }
  386. bool hasLinkOnceLinkage() const { return isLinkOnceLinkage(getLinkage()); }
  387. bool hasLinkOnceAnyLinkage() const {
  388. return isLinkOnceAnyLinkage(getLinkage());
  389. }
  390. bool hasLinkOnceODRLinkage() const {
  391. return isLinkOnceODRLinkage(getLinkage());
  392. }
  393. bool hasWeakLinkage() const { return isWeakLinkage(getLinkage()); }
  394. bool hasWeakAnyLinkage() const { return isWeakAnyLinkage(getLinkage()); }
  395. bool hasWeakODRLinkage() const { return isWeakODRLinkage(getLinkage()); }
  396. bool hasAppendingLinkage() const { return isAppendingLinkage(getLinkage()); }
  397. bool hasInternalLinkage() const { return isInternalLinkage(getLinkage()); }
  398. bool hasPrivateLinkage() const { return isPrivateLinkage(getLinkage()); }
  399. bool hasLocalLinkage() const { return isLocalLinkage(getLinkage()); }
  400. bool hasExternalWeakLinkage() const {
  401. return isExternalWeakLinkage(getLinkage());
  402. }
  403. bool hasCommonLinkage() const { return isCommonLinkage(getLinkage()); }
  404. bool hasValidDeclarationLinkage() const {
  405. return isValidDeclarationLinkage(getLinkage());
  406. }
  407. void setLinkage(LinkageTypes LT) {
  408. if (isLocalLinkage(LT))
  409. Visibility = DefaultVisibility;
  410. Linkage = LT;
  411. if (isImplicitDSOLocal())
  412. setDSOLocal(true);
  413. }
  414. LinkageTypes getLinkage() const { return LinkageTypes(Linkage); }
  415. bool isDiscardableIfUnused() const {
  416. return isDiscardableIfUnused(getLinkage());
  417. }
  418. bool isWeakForLinker() const { return isWeakForLinker(getLinkage()); }
  419. protected:
  420. /// Copy all additional attributes (those not needed to create a GlobalValue)
  421. /// from the GlobalValue Src to this one.
  422. void copyAttributesFrom(const GlobalValue *Src);
  423. public:
  424. /// If the given string begins with the GlobalValue name mangling escape
  425. /// character '\1', drop it.
  426. ///
  427. /// This function applies a specific mangling that is used in PGO profiles,
  428. /// among other things. If you're trying to get a symbol name for an
  429. /// arbitrary GlobalValue, this is not the function you're looking for; see
  430. /// Mangler.h.
  431. static StringRef dropLLVMManglingEscape(StringRef Name) {
  432. if (!Name.empty() && Name[0] == '\1')
  433. return Name.substr(1);
  434. return Name;
  435. }
  436. /// Return the modified name for a global value suitable to be
  437. /// used as the key for a global lookup (e.g. profile or ThinLTO).
  438. /// The value's original name is \c Name and has linkage of type
  439. /// \c Linkage. The value is defined in module \c FileName.
  440. static std::string getGlobalIdentifier(StringRef Name,
  441. GlobalValue::LinkageTypes Linkage,
  442. StringRef FileName);
  443. /// Return the modified name for this global value suitable to be
  444. /// used as the key for a global lookup (e.g. profile or ThinLTO).
  445. std::string getGlobalIdentifier() const;
  446. /// Declare a type to represent a global unique identifier for a global value.
  447. /// This is a 64 bits hash that is used by PGO and ThinLTO to have a compact
  448. /// unique way to identify a symbol.
  449. using GUID = uint64_t;
  450. /// Return a 64-bit global unique ID constructed from global value name
  451. /// (i.e. returned by getGlobalIdentifier()).
  452. static GUID getGUID(StringRef GlobalName) { return MD5Hash(GlobalName); }
  453. /// Return a 64-bit global unique ID constructed from global value name
  454. /// (i.e. returned by getGlobalIdentifier()).
  455. GUID getGUID() const { return getGUID(getGlobalIdentifier()); }
  456. /// @name Materialization
  457. /// Materialization is used to construct functions only as they're needed.
  458. /// This
  459. /// is useful to reduce memory usage in LLVM or parsing work done by the
  460. /// BitcodeReader to load the Module.
  461. /// @{
  462. /// If this function's Module is being lazily streamed in functions from disk
  463. /// or some other source, this method can be used to check to see if the
  464. /// function has been read in yet or not.
  465. bool isMaterializable() const;
  466. /// Make sure this GlobalValue is fully read.
  467. Error materialize();
  468. /// @}
  469. /// Return true if the primary definition of this global value is outside of
  470. /// the current translation unit.
  471. bool isDeclaration() const;
  472. bool isDeclarationForLinker() const {
  473. if (hasAvailableExternallyLinkage())
  474. return true;
  475. return isDeclaration();
  476. }
  477. /// Returns true if this global's definition will be the one chosen by the
  478. /// linker.
  479. ///
  480. /// NB! Ideally this should not be used at the IR level at all. If you're
  481. /// interested in optimization constraints implied by the linker's ability to
  482. /// choose an implementation, prefer using \c hasExactDefinition.
  483. bool isStrongDefinitionForLinker() const {
  484. return !(isDeclarationForLinker() || isWeakForLinker());
  485. }
  486. const GlobalObject *getAliaseeObject() const;
  487. GlobalObject *getAliaseeObject() {
  488. return const_cast<GlobalObject *>(
  489. static_cast<const GlobalValue *>(this)->getAliaseeObject());
  490. }
  491. /// Returns whether this is a reference to an absolute symbol.
  492. bool isAbsoluteSymbolRef() const;
  493. /// If this is an absolute symbol reference, returns the range of the symbol,
  494. /// otherwise returns None.
  495. Optional<ConstantRange> getAbsoluteSymbolRange() const;
  496. /// This method unlinks 'this' from the containing module, but does not delete
  497. /// it.
  498. void removeFromParent();
  499. /// This method unlinks 'this' from the containing module and deletes it.
  500. void eraseFromParent();
  501. /// Get the module that this global value is contained inside of...
  502. Module *getParent() { return Parent; }
  503. const Module *getParent() const { return Parent; }
  504. // Methods for support type inquiry through isa, cast, and dyn_cast:
  505. static bool classof(const Value *V) {
  506. return V->getValueID() == Value::FunctionVal ||
  507. V->getValueID() == Value::GlobalVariableVal ||
  508. V->getValueID() == Value::GlobalAliasVal ||
  509. V->getValueID() == Value::GlobalIFuncVal;
  510. }
  511. /// True if GV can be left out of the object symbol table. This is the case
  512. /// for linkonce_odr values whose address is not significant. While legal, it
  513. /// is not normally profitable to omit them from the .o symbol table. Using
  514. /// this analysis makes sense when the information can be passed down to the
  515. /// linker or we are in LTO.
  516. bool canBeOmittedFromSymbolTable() const;
  517. };
  518. } // end namespace llvm
  519. #endif // LLVM_IR_GLOBALVALUE_H
  520. #ifdef __GNUC__
  521. #pragma GCC diagnostic pop
  522. #endif