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