Globals.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. //===-- Globals.cpp - Implement the GlobalValue & GlobalVariable class ----===//
  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 implements the GlobalValue & GlobalVariable classes for the IR
  10. // library.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "LLVMContextImpl.h"
  14. #include "llvm/ADT/Triple.h"
  15. #include "llvm/IR/ConstantRange.h"
  16. #include "llvm/IR/Constants.h"
  17. #include "llvm/IR/DerivedTypes.h"
  18. #include "llvm/IR/GlobalAlias.h"
  19. #include "llvm/IR/GlobalValue.h"
  20. #include "llvm/IR/GlobalVariable.h"
  21. #include "llvm/IR/Module.h"
  22. #include "llvm/Support/Error.h"
  23. #include "llvm/Support/ErrorHandling.h"
  24. using namespace llvm;
  25. //===----------------------------------------------------------------------===//
  26. // GlobalValue Class
  27. //===----------------------------------------------------------------------===//
  28. // GlobalValue should be a Constant, plus a type, a module, some flags, and an
  29. // intrinsic ID. Add an assert to prevent people from accidentally growing
  30. // GlobalValue while adding flags.
  31. static_assert(sizeof(GlobalValue) ==
  32. sizeof(Constant) + 2 * sizeof(void *) + 2 * sizeof(unsigned),
  33. "unexpected GlobalValue size growth");
  34. // GlobalObject adds a comdat.
  35. static_assert(sizeof(GlobalObject) == sizeof(GlobalValue) + sizeof(void *),
  36. "unexpected GlobalObject size growth");
  37. bool GlobalValue::isMaterializable() const {
  38. if (const Function *F = dyn_cast<Function>(this))
  39. return F->isMaterializable();
  40. return false;
  41. }
  42. Error GlobalValue::materialize() {
  43. return getParent()->materialize(this);
  44. }
  45. /// Override destroyConstantImpl to make sure it doesn't get called on
  46. /// GlobalValue's because they shouldn't be treated like other constants.
  47. void GlobalValue::destroyConstantImpl() {
  48. llvm_unreachable("You can't GV->destroyConstantImpl()!");
  49. }
  50. Value *GlobalValue::handleOperandChangeImpl(Value *From, Value *To) {
  51. llvm_unreachable("Unsupported class for handleOperandChange()!");
  52. }
  53. /// copyAttributesFrom - copy all additional attributes (those not needed to
  54. /// create a GlobalValue) from the GlobalValue Src to this one.
  55. void GlobalValue::copyAttributesFrom(const GlobalValue *Src) {
  56. setVisibility(Src->getVisibility());
  57. setUnnamedAddr(Src->getUnnamedAddr());
  58. setThreadLocalMode(Src->getThreadLocalMode());
  59. setDLLStorageClass(Src->getDLLStorageClass());
  60. setDSOLocal(Src->isDSOLocal());
  61. setPartition(Src->getPartition());
  62. if (Src->hasSanitizerMetadata())
  63. setSanitizerMetadata(Src->getSanitizerMetadata());
  64. else
  65. removeSanitizerMetadata();
  66. }
  67. void GlobalValue::removeFromParent() {
  68. switch (getValueID()) {
  69. #define HANDLE_GLOBAL_VALUE(NAME) \
  70. case Value::NAME##Val: \
  71. return static_cast<NAME *>(this)->removeFromParent();
  72. #include "llvm/IR/Value.def"
  73. default:
  74. break;
  75. }
  76. llvm_unreachable("not a global");
  77. }
  78. void GlobalValue::eraseFromParent() {
  79. switch (getValueID()) {
  80. #define HANDLE_GLOBAL_VALUE(NAME) \
  81. case Value::NAME##Val: \
  82. return static_cast<NAME *>(this)->eraseFromParent();
  83. #include "llvm/IR/Value.def"
  84. default:
  85. break;
  86. }
  87. llvm_unreachable("not a global");
  88. }
  89. GlobalObject::~GlobalObject() { setComdat(nullptr); }
  90. bool GlobalValue::isInterposable() const {
  91. if (isInterposableLinkage(getLinkage()))
  92. return true;
  93. return getParent() && getParent()->getSemanticInterposition() &&
  94. !isDSOLocal();
  95. }
  96. bool GlobalValue::canBenefitFromLocalAlias() const {
  97. // See AsmPrinter::getSymbolPreferLocal(). For a deduplicate comdat kind,
  98. // references to a discarded local symbol from outside the group are not
  99. // allowed, so avoid the local alias.
  100. auto isDeduplicateComdat = [](const Comdat *C) {
  101. return C && C->getSelectionKind() != Comdat::NoDeduplicate;
  102. };
  103. return hasDefaultVisibility() &&
  104. GlobalObject::isExternalLinkage(getLinkage()) && !isDeclaration() &&
  105. !isa<GlobalIFunc>(this) && !isDeduplicateComdat(getComdat());
  106. }
  107. void GlobalObject::setAlignment(MaybeAlign Align) {
  108. assert((!Align || *Align <= MaximumAlignment) &&
  109. "Alignment is greater than MaximumAlignment!");
  110. unsigned AlignmentData = encode(Align);
  111. unsigned OldData = getGlobalValueSubClassData();
  112. setGlobalValueSubClassData((OldData & ~AlignmentMask) | AlignmentData);
  113. assert(getAlign() == Align && "Alignment representation error!");
  114. }
  115. void GlobalObject::copyAttributesFrom(const GlobalObject *Src) {
  116. GlobalValue::copyAttributesFrom(Src);
  117. setAlignment(Src->getAlign());
  118. setSection(Src->getSection());
  119. }
  120. std::string GlobalValue::getGlobalIdentifier(StringRef Name,
  121. GlobalValue::LinkageTypes Linkage,
  122. StringRef FileName) {
  123. // Value names may be prefixed with a binary '1' to indicate
  124. // that the backend should not modify the symbols due to any platform
  125. // naming convention. Do not include that '1' in the PGO profile name.
  126. if (Name[0] == '\1')
  127. Name = Name.substr(1);
  128. std::string NewName = std::string(Name);
  129. if (llvm::GlobalValue::isLocalLinkage(Linkage)) {
  130. // For local symbols, prepend the main file name to distinguish them.
  131. // Do not include the full path in the file name since there's no guarantee
  132. // that it will stay the same, e.g., if the files are checked out from
  133. // version control in different locations.
  134. if (FileName.empty())
  135. NewName = NewName.insert(0, "<unknown>:");
  136. else
  137. NewName = NewName.insert(0, FileName.str() + ":");
  138. }
  139. return NewName;
  140. }
  141. std::string GlobalValue::getGlobalIdentifier() const {
  142. return getGlobalIdentifier(getName(), getLinkage(),
  143. getParent()->getSourceFileName());
  144. }
  145. StringRef GlobalValue::getSection() const {
  146. if (auto *GA = dyn_cast<GlobalAlias>(this)) {
  147. // In general we cannot compute this at the IR level, but we try.
  148. if (const GlobalObject *GO = GA->getAliaseeObject())
  149. return GO->getSection();
  150. return "";
  151. }
  152. return cast<GlobalObject>(this)->getSection();
  153. }
  154. const Comdat *GlobalValue::getComdat() const {
  155. if (auto *GA = dyn_cast<GlobalAlias>(this)) {
  156. // In general we cannot compute this at the IR level, but we try.
  157. if (const GlobalObject *GO = GA->getAliaseeObject())
  158. return const_cast<GlobalObject *>(GO)->getComdat();
  159. return nullptr;
  160. }
  161. // ifunc and its resolver are separate things so don't use resolver comdat.
  162. if (isa<GlobalIFunc>(this))
  163. return nullptr;
  164. return cast<GlobalObject>(this)->getComdat();
  165. }
  166. void GlobalObject::setComdat(Comdat *C) {
  167. if (ObjComdat)
  168. ObjComdat->removeUser(this);
  169. ObjComdat = C;
  170. if (C)
  171. C->addUser(this);
  172. }
  173. StringRef GlobalValue::getPartition() const {
  174. if (!hasPartition())
  175. return "";
  176. return getContext().pImpl->GlobalValuePartitions[this];
  177. }
  178. void GlobalValue::setPartition(StringRef S) {
  179. // Do nothing if we're clearing the partition and it is already empty.
  180. if (!hasPartition() && S.empty())
  181. return;
  182. // Get or create a stable partition name string and put it in the table in the
  183. // context.
  184. if (!S.empty())
  185. S = getContext().pImpl->Saver.save(S);
  186. getContext().pImpl->GlobalValuePartitions[this] = S;
  187. // Update the HasPartition field. Setting the partition to the empty string
  188. // means this global no longer has a partition.
  189. HasPartition = !S.empty();
  190. }
  191. using SanitizerMetadata = GlobalValue::SanitizerMetadata;
  192. const SanitizerMetadata &GlobalValue::getSanitizerMetadata() const {
  193. assert(hasSanitizerMetadata());
  194. assert(getContext().pImpl->GlobalValueSanitizerMetadata.count(this));
  195. return getContext().pImpl->GlobalValueSanitizerMetadata[this];
  196. }
  197. void GlobalValue::setSanitizerMetadata(SanitizerMetadata Meta) {
  198. getContext().pImpl->GlobalValueSanitizerMetadata[this] = Meta;
  199. HasSanitizerMetadata = true;
  200. }
  201. void GlobalValue::removeSanitizerMetadata() {
  202. DenseMap<const GlobalValue *, SanitizerMetadata> &MetadataMap =
  203. getContext().pImpl->GlobalValueSanitizerMetadata;
  204. MetadataMap.erase(this);
  205. HasSanitizerMetadata = false;
  206. }
  207. StringRef GlobalObject::getSectionImpl() const {
  208. assert(hasSection());
  209. return getContext().pImpl->GlobalObjectSections[this];
  210. }
  211. void GlobalObject::setSection(StringRef S) {
  212. // Do nothing if we're clearing the section and it is already empty.
  213. if (!hasSection() && S.empty())
  214. return;
  215. // Get or create a stable section name string and put it in the table in the
  216. // context.
  217. if (!S.empty())
  218. S = getContext().pImpl->Saver.save(S);
  219. getContext().pImpl->GlobalObjectSections[this] = S;
  220. // Update the HasSectionHashEntryBit. Setting the section to the empty string
  221. // means this global no longer has a section.
  222. setGlobalObjectFlag(HasSectionHashEntryBit, !S.empty());
  223. }
  224. bool GlobalValue::isNobuiltinFnDef() const {
  225. const Function *F = dyn_cast<Function>(this);
  226. if (!F || F->empty())
  227. return false;
  228. return F->hasFnAttribute(Attribute::NoBuiltin);
  229. }
  230. bool GlobalValue::isDeclaration() const {
  231. // Globals are definitions if they have an initializer.
  232. if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
  233. return GV->getNumOperands() == 0;
  234. // Functions are definitions if they have a body.
  235. if (const Function *F = dyn_cast<Function>(this))
  236. return F->empty() && !F->isMaterializable();
  237. // Aliases and ifuncs are always definitions.
  238. assert(isa<GlobalAlias>(this) || isa<GlobalIFunc>(this));
  239. return false;
  240. }
  241. bool GlobalObject::canIncreaseAlignment() const {
  242. // Firstly, can only increase the alignment of a global if it
  243. // is a strong definition.
  244. if (!isStrongDefinitionForLinker())
  245. return false;
  246. // It also has to either not have a section defined, or, not have
  247. // alignment specified. (If it is assigned a section, the global
  248. // could be densely packed with other objects in the section, and
  249. // increasing the alignment could cause padding issues.)
  250. if (hasSection() && getAlign())
  251. return false;
  252. // On ELF platforms, we're further restricted in that we can't
  253. // increase the alignment of any variable which might be emitted
  254. // into a shared library, and which is exported. If the main
  255. // executable accesses a variable found in a shared-lib, the main
  256. // exe actually allocates memory for and exports the symbol ITSELF,
  257. // overriding the symbol found in the library. That is, at link
  258. // time, the observed alignment of the variable is copied into the
  259. // executable binary. (A COPY relocation is also generated, to copy
  260. // the initial data from the shadowed variable in the shared-lib
  261. // into the location in the main binary, before running code.)
  262. //
  263. // And thus, even though you might think you are defining the
  264. // global, and allocating the memory for the global in your object
  265. // file, and thus should be able to set the alignment arbitrarily,
  266. // that's not actually true. Doing so can cause an ABI breakage; an
  267. // executable might have already been built with the previous
  268. // alignment of the variable, and then assuming an increased
  269. // alignment will be incorrect.
  270. // Conservatively assume ELF if there's no parent pointer.
  271. bool isELF =
  272. (!Parent || Triple(Parent->getTargetTriple()).isOSBinFormatELF());
  273. if (isELF && !isDSOLocal())
  274. return false;
  275. return true;
  276. }
  277. template <typename Operation>
  278. static const GlobalObject *
  279. findBaseObject(const Constant *C, DenseSet<const GlobalAlias *> &Aliases,
  280. const Operation &Op) {
  281. if (auto *GO = dyn_cast<GlobalObject>(C)) {
  282. Op(*GO);
  283. return GO;
  284. }
  285. if (auto *GA = dyn_cast<GlobalAlias>(C)) {
  286. Op(*GA);
  287. if (Aliases.insert(GA).second)
  288. return findBaseObject(GA->getOperand(0), Aliases, Op);
  289. }
  290. if (auto *CE = dyn_cast<ConstantExpr>(C)) {
  291. switch (CE->getOpcode()) {
  292. case Instruction::Add: {
  293. auto *LHS = findBaseObject(CE->getOperand(0), Aliases, Op);
  294. auto *RHS = findBaseObject(CE->getOperand(1), Aliases, Op);
  295. if (LHS && RHS)
  296. return nullptr;
  297. return LHS ? LHS : RHS;
  298. }
  299. case Instruction::Sub: {
  300. if (findBaseObject(CE->getOperand(1), Aliases, Op))
  301. return nullptr;
  302. return findBaseObject(CE->getOperand(0), Aliases, Op);
  303. }
  304. case Instruction::IntToPtr:
  305. case Instruction::PtrToInt:
  306. case Instruction::BitCast:
  307. case Instruction::GetElementPtr:
  308. return findBaseObject(CE->getOperand(0), Aliases, Op);
  309. default:
  310. break;
  311. }
  312. }
  313. return nullptr;
  314. }
  315. const GlobalObject *GlobalValue::getAliaseeObject() const {
  316. DenseSet<const GlobalAlias *> Aliases;
  317. return findBaseObject(this, Aliases, [](const GlobalValue &) {});
  318. }
  319. bool GlobalValue::isAbsoluteSymbolRef() const {
  320. auto *GO = dyn_cast<GlobalObject>(this);
  321. if (!GO)
  322. return false;
  323. return GO->getMetadata(LLVMContext::MD_absolute_symbol);
  324. }
  325. std::optional<ConstantRange> GlobalValue::getAbsoluteSymbolRange() const {
  326. auto *GO = dyn_cast<GlobalObject>(this);
  327. if (!GO)
  328. return std::nullopt;
  329. MDNode *MD = GO->getMetadata(LLVMContext::MD_absolute_symbol);
  330. if (!MD)
  331. return std::nullopt;
  332. return getConstantRangeFromMetadata(*MD);
  333. }
  334. bool GlobalValue::canBeOmittedFromSymbolTable() const {
  335. if (!hasLinkOnceODRLinkage())
  336. return false;
  337. // We assume that anyone who sets global unnamed_addr on a non-constant
  338. // knows what they're doing.
  339. if (hasGlobalUnnamedAddr())
  340. return true;
  341. // If it is a non constant variable, it needs to be uniqued across shared
  342. // objects.
  343. if (auto *Var = dyn_cast<GlobalVariable>(this))
  344. if (!Var->isConstant())
  345. return false;
  346. return hasAtLeastLocalUnnamedAddr();
  347. }
  348. //===----------------------------------------------------------------------===//
  349. // GlobalVariable Implementation
  350. //===----------------------------------------------------------------------===//
  351. GlobalVariable::GlobalVariable(Type *Ty, bool constant, LinkageTypes Link,
  352. Constant *InitVal, const Twine &Name,
  353. ThreadLocalMode TLMode, unsigned AddressSpace,
  354. bool isExternallyInitialized)
  355. : GlobalObject(Ty, Value::GlobalVariableVal,
  356. OperandTraits<GlobalVariable>::op_begin(this),
  357. InitVal != nullptr, Link, Name, AddressSpace),
  358. isConstantGlobal(constant),
  359. isExternallyInitializedConstant(isExternallyInitialized) {
  360. assert(!Ty->isFunctionTy() && PointerType::isValidElementType(Ty) &&
  361. "invalid type for global variable");
  362. setThreadLocalMode(TLMode);
  363. if (InitVal) {
  364. assert(InitVal->getType() == Ty &&
  365. "Initializer should be the same type as the GlobalVariable!");
  366. Op<0>() = InitVal;
  367. }
  368. }
  369. GlobalVariable::GlobalVariable(Module &M, Type *Ty, bool constant,
  370. LinkageTypes Link, Constant *InitVal,
  371. const Twine &Name, GlobalVariable *Before,
  372. ThreadLocalMode TLMode,
  373. std::optional<unsigned> AddressSpace,
  374. bool isExternallyInitialized)
  375. : GlobalObject(Ty, Value::GlobalVariableVal,
  376. OperandTraits<GlobalVariable>::op_begin(this),
  377. InitVal != nullptr, Link, Name,
  378. AddressSpace
  379. ? *AddressSpace
  380. : M.getDataLayout().getDefaultGlobalsAddressSpace()),
  381. isConstantGlobal(constant),
  382. isExternallyInitializedConstant(isExternallyInitialized) {
  383. assert(!Ty->isFunctionTy() && PointerType::isValidElementType(Ty) &&
  384. "invalid type for global variable");
  385. setThreadLocalMode(TLMode);
  386. if (InitVal) {
  387. assert(InitVal->getType() == Ty &&
  388. "Initializer should be the same type as the GlobalVariable!");
  389. Op<0>() = InitVal;
  390. }
  391. if (Before)
  392. Before->getParent()->getGlobalList().insert(Before->getIterator(), this);
  393. else
  394. M.getGlobalList().push_back(this);
  395. }
  396. void GlobalVariable::removeFromParent() {
  397. getParent()->getGlobalList().remove(getIterator());
  398. }
  399. void GlobalVariable::eraseFromParent() {
  400. getParent()->getGlobalList().erase(getIterator());
  401. }
  402. void GlobalVariable::setInitializer(Constant *InitVal) {
  403. if (!InitVal) {
  404. if (hasInitializer()) {
  405. // Note, the num operands is used to compute the offset of the operand, so
  406. // the order here matters. Clearing the operand then clearing the num
  407. // operands ensures we have the correct offset to the operand.
  408. Op<0>().set(nullptr);
  409. setGlobalVariableNumOperands(0);
  410. }
  411. } else {
  412. assert(InitVal->getType() == getValueType() &&
  413. "Initializer type must match GlobalVariable type");
  414. // Note, the num operands is used to compute the offset of the operand, so
  415. // the order here matters. We need to set num operands to 1 first so that
  416. // we get the correct offset to the first operand when we set it.
  417. if (!hasInitializer())
  418. setGlobalVariableNumOperands(1);
  419. Op<0>().set(InitVal);
  420. }
  421. }
  422. /// Copy all additional attributes (those not needed to create a GlobalVariable)
  423. /// from the GlobalVariable Src to this one.
  424. void GlobalVariable::copyAttributesFrom(const GlobalVariable *Src) {
  425. GlobalObject::copyAttributesFrom(Src);
  426. setExternallyInitialized(Src->isExternallyInitialized());
  427. setAttributes(Src->getAttributes());
  428. }
  429. void GlobalVariable::dropAllReferences() {
  430. User::dropAllReferences();
  431. clearMetadata();
  432. }
  433. //===----------------------------------------------------------------------===//
  434. // GlobalAlias Implementation
  435. //===----------------------------------------------------------------------===//
  436. GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
  437. const Twine &Name, Constant *Aliasee,
  438. Module *ParentModule)
  439. : GlobalValue(Ty, Value::GlobalAliasVal, &Op<0>(), 1, Link, Name,
  440. AddressSpace) {
  441. setAliasee(Aliasee);
  442. if (ParentModule)
  443. ParentModule->getAliasList().push_back(this);
  444. }
  445. GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
  446. LinkageTypes Link, const Twine &Name,
  447. Constant *Aliasee, Module *ParentModule) {
  448. return new GlobalAlias(Ty, AddressSpace, Link, Name, Aliasee, ParentModule);
  449. }
  450. GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
  451. LinkageTypes Linkage, const Twine &Name,
  452. Module *Parent) {
  453. return create(Ty, AddressSpace, Linkage, Name, nullptr, Parent);
  454. }
  455. GlobalAlias *GlobalAlias::create(Type *Ty, unsigned AddressSpace,
  456. LinkageTypes Linkage, const Twine &Name,
  457. GlobalValue *Aliasee) {
  458. return create(Ty, AddressSpace, Linkage, Name, Aliasee, Aliasee->getParent());
  459. }
  460. GlobalAlias *GlobalAlias::create(LinkageTypes Link, const Twine &Name,
  461. GlobalValue *Aliasee) {
  462. return create(Aliasee->getValueType(), Aliasee->getAddressSpace(), Link, Name,
  463. Aliasee);
  464. }
  465. GlobalAlias *GlobalAlias::create(const Twine &Name, GlobalValue *Aliasee) {
  466. return create(Aliasee->getLinkage(), Name, Aliasee);
  467. }
  468. void GlobalAlias::removeFromParent() {
  469. getParent()->getAliasList().remove(getIterator());
  470. }
  471. void GlobalAlias::eraseFromParent() {
  472. getParent()->getAliasList().erase(getIterator());
  473. }
  474. void GlobalAlias::setAliasee(Constant *Aliasee) {
  475. assert((!Aliasee || Aliasee->getType() == getType()) &&
  476. "Alias and aliasee types should match!");
  477. Op<0>().set(Aliasee);
  478. }
  479. const GlobalObject *GlobalAlias::getAliaseeObject() const {
  480. DenseSet<const GlobalAlias *> Aliases;
  481. return findBaseObject(getOperand(0), Aliases, [](const GlobalValue &) {});
  482. }
  483. //===----------------------------------------------------------------------===//
  484. // GlobalIFunc Implementation
  485. //===----------------------------------------------------------------------===//
  486. GlobalIFunc::GlobalIFunc(Type *Ty, unsigned AddressSpace, LinkageTypes Link,
  487. const Twine &Name, Constant *Resolver,
  488. Module *ParentModule)
  489. : GlobalObject(Ty, Value::GlobalIFuncVal, &Op<0>(), 1, Link, Name,
  490. AddressSpace) {
  491. setResolver(Resolver);
  492. if (ParentModule)
  493. ParentModule->getIFuncList().push_back(this);
  494. }
  495. GlobalIFunc *GlobalIFunc::create(Type *Ty, unsigned AddressSpace,
  496. LinkageTypes Link, const Twine &Name,
  497. Constant *Resolver, Module *ParentModule) {
  498. return new GlobalIFunc(Ty, AddressSpace, Link, Name, Resolver, ParentModule);
  499. }
  500. void GlobalIFunc::removeFromParent() {
  501. getParent()->getIFuncList().remove(getIterator());
  502. }
  503. void GlobalIFunc::eraseFromParent() {
  504. getParent()->getIFuncList().erase(getIterator());
  505. }
  506. const Function *GlobalIFunc::getResolverFunction() const {
  507. return dyn_cast<Function>(getResolver()->stripPointerCastsAndAliases());
  508. }
  509. void GlobalIFunc::applyAlongResolverPath(
  510. function_ref<void(const GlobalValue &)> Op) const {
  511. DenseSet<const GlobalAlias *> Aliases;
  512. findBaseObject(getResolver(), Aliases, Op);
  513. }