LLVM  15.0.0git
LinkModules.cpp
Go to the documentation of this file.
1 //===- lib/Linker/LinkModules.cpp - Module Linker Implementation ----------===//
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 LLVM module linker.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "LinkDiagnosticInfo.h"
14 #include "llvm-c/Linker.h"
15 #include "llvm/ADT/SetVector.h"
16 #include "llvm/IR/Comdat.h"
17 #include "llvm/IR/GlobalValue.h"
18 #include "llvm/IR/LLVMContext.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/Linker/Linker.h"
21 #include "llvm/Support/Error.h"
22 using namespace llvm;
23 
24 namespace {
25 
26 enum class LinkFrom { Dst, Src, Both };
27 
28 /// This is an implementation class for the LinkModules function, which is the
29 /// entrypoint for this file.
30 class ModuleLinker {
31  IRMover &Mover;
32  std::unique_ptr<Module> SrcM;
33 
34  SetVector<GlobalValue *> ValuesToLink;
35 
36  /// For symbol clashes, prefer those from Src.
37  unsigned Flags;
38 
39  /// List of global value names that should be internalized.
40  StringSet<> Internalize;
41 
42  /// Function that will perform the actual internalization. The reason for a
43  /// callback is that the linker cannot call internalizeModule without
44  /// creating a circular dependency between IPO and the linker.
45  std::function<void(Module &, const StringSet<> &)> InternalizeCallback;
46 
47  /// Used as the callback for lazy linking.
48  /// The mover has just hit GV and we have to decide if it, and other members
49  /// of the same comdat, should be linked. Every member to be linked is passed
50  /// to Add.
51  void addLazyFor(GlobalValue &GV, const IRMover::ValueAdder &Add);
52 
53  bool shouldOverrideFromSrc() { return Flags & Linker::OverrideFromSrc; }
54  bool shouldLinkOnlyNeeded() { return Flags & Linker::LinkOnlyNeeded; }
55 
56  bool shouldLinkFromSource(bool &LinkFromSrc, const GlobalValue &Dest,
57  const GlobalValue &Src);
58 
59  /// Should we have mover and linker error diag info?
60  bool emitError(const Twine &Message) {
61  SrcM->getContext().diagnose(LinkDiagnosticInfo(DS_Error, Message));
62  return true;
63  }
64 
65  bool getComdatLeader(Module &M, StringRef ComdatName,
66  const GlobalVariable *&GVar);
67  bool computeResultingSelectionKind(StringRef ComdatName,
70  Comdat::SelectionKind &Result,
71  LinkFrom &From);
73  ComdatsChosen;
74  bool getComdatResult(const Comdat *SrcC, Comdat::SelectionKind &SK,
75  LinkFrom &From);
76  // Keep track of the lazy linked global members of each comdat in source.
78 
79  /// Given a global in the source module, return the global in the
80  /// destination module that is being linked to, if any.
81  GlobalValue *getLinkedToGlobal(const GlobalValue *SrcGV) {
82  Module &DstM = Mover.getModule();
83  // If the source has no name it can't link. If it has local linkage,
84  // there is no name match-up going on.
85  if (!SrcGV->hasName() || GlobalValue::isLocalLinkage(SrcGV->getLinkage()))
86  return nullptr;
87 
88  // Otherwise see if we have a match in the destination module's symtab.
89  GlobalValue *DGV = DstM.getNamedValue(SrcGV->getName());
90  if (!DGV)
91  return nullptr;
92 
93  // If we found a global with the same name in the dest module, but it has
94  // internal linkage, we are really not doing any linkage here.
95  if (DGV->hasLocalLinkage())
96  return nullptr;
97 
98  // Otherwise, we do in fact link to the destination global.
99  return DGV;
100  }
101 
102  /// Drop GV if it is a member of a comdat that we are dropping.
103  /// This can happen with COFF's largest selection kind.
104  void dropReplacedComdat(GlobalValue &GV,
105  const DenseSet<const Comdat *> &ReplacedDstComdats);
106 
107  bool linkIfNeeded(GlobalValue &GV, SmallVectorImpl<GlobalValue *> &GVToClone);
108 
109 public:
110  ModuleLinker(IRMover &Mover, std::unique_ptr<Module> SrcM, unsigned Flags,
111  std::function<void(Module &, const StringSet<> &)>
112  InternalizeCallback = {})
113  : Mover(Mover), SrcM(std::move(SrcM)), Flags(Flags),
114  InternalizeCallback(std::move(InternalizeCallback)) {}
115 
116  bool run();
117 };
118 } // namespace
119 
129 }
130 
131 bool ModuleLinker::getComdatLeader(Module &M, StringRef ComdatName,
132  const GlobalVariable *&GVar) {
133  const GlobalValue *GVal = M.getNamedValue(ComdatName);
134  if (const auto *GA = dyn_cast_or_null<GlobalAlias>(GVal)) {
135  GVal = GA->getAliaseeObject();
136  if (!GVal)
137  // We cannot resolve the size of the aliasee yet.
138  return emitError("Linking COMDATs named '" + ComdatName +
139  "': COMDAT key involves incomputable alias size.");
140  }
141 
142  GVar = dyn_cast_or_null<GlobalVariable>(GVal);
143  if (!GVar)
144  return emitError(
145  "Linking COMDATs named '" + ComdatName +
146  "': GlobalVariable required for data dependent selection!");
147 
148  return false;
149 }
150 
151 bool ModuleLinker::computeResultingSelectionKind(StringRef ComdatName,
154  Comdat::SelectionKind &Result,
155  LinkFrom &From) {
156  Module &DstM = Mover.getModule();
157  // The ability to mix Comdat::SelectionKind::Any with
158  // Comdat::SelectionKind::Largest is a behavior that comes from COFF.
159  bool DstAnyOrLargest = Dst == Comdat::SelectionKind::Any ||
160  Dst == Comdat::SelectionKind::Largest;
161  bool SrcAnyOrLargest = Src == Comdat::SelectionKind::Any ||
162  Src == Comdat::SelectionKind::Largest;
163  if (DstAnyOrLargest && SrcAnyOrLargest) {
164  if (Dst == Comdat::SelectionKind::Largest ||
165  Src == Comdat::SelectionKind::Largest)
166  Result = Comdat::SelectionKind::Largest;
167  else
169  } else if (Src == Dst) {
170  Result = Dst;
171  } else {
172  return emitError("Linking COMDATs named '" + ComdatName +
173  "': invalid selection kinds!");
174  }
175 
176  switch (Result) {
178  // Go with Dst.
179  From = LinkFrom::Dst;
180  break;
181  case Comdat::SelectionKind::NoDeduplicate:
182  From = LinkFrom::Both;
183  break;
184  case Comdat::SelectionKind::ExactMatch:
185  case Comdat::SelectionKind::Largest:
186  case Comdat::SelectionKind::SameSize: {
187  const GlobalVariable *DstGV;
188  const GlobalVariable *SrcGV;
189  if (getComdatLeader(DstM, ComdatName, DstGV) ||
190  getComdatLeader(*SrcM, ComdatName, SrcGV))
191  return true;
192 
193  const DataLayout &DstDL = DstM.getDataLayout();
194  const DataLayout &SrcDL = SrcM->getDataLayout();
195  uint64_t DstSize = DstDL.getTypeAllocSize(DstGV->getValueType());
196  uint64_t SrcSize = SrcDL.getTypeAllocSize(SrcGV->getValueType());
197  if (Result == Comdat::SelectionKind::ExactMatch) {
198  if (SrcGV->getInitializer() != DstGV->getInitializer())
199  return emitError("Linking COMDATs named '" + ComdatName +
200  "': ExactMatch violated!");
201  From = LinkFrom::Dst;
202  } else if (Result == Comdat::SelectionKind::Largest) {
203  From = SrcSize > DstSize ? LinkFrom::Src : LinkFrom::Dst;
204  } else if (Result == Comdat::SelectionKind::SameSize) {
205  if (SrcSize != DstSize)
206  return emitError("Linking COMDATs named '" + ComdatName +
207  "': SameSize violated!");
208  From = LinkFrom::Dst;
209  } else {
210  llvm_unreachable("unknown selection kind");
211  }
212  break;
213  }
214  }
215 
216  return false;
217 }
218 
219 bool ModuleLinker::getComdatResult(const Comdat *SrcC,
220  Comdat::SelectionKind &Result,
221  LinkFrom &From) {
222  Module &DstM = Mover.getModule();
224  StringRef ComdatName = SrcC->getName();
225  Module::ComdatSymTabType &ComdatSymTab = DstM.getComdatSymbolTable();
226  Module::ComdatSymTabType::iterator DstCI = ComdatSymTab.find(ComdatName);
227 
228  if (DstCI == ComdatSymTab.end()) {
229  // Use the comdat if it is only available in one of the modules.
230  From = LinkFrom::Src;
231  Result = SSK;
232  return false;
233  }
234 
235  const Comdat *DstC = &DstCI->second;
237  return computeResultingSelectionKind(ComdatName, SSK, DSK, Result, From);
238 }
239 
240 bool ModuleLinker::shouldLinkFromSource(bool &LinkFromSrc,
241  const GlobalValue &Dest,
242  const GlobalValue &Src) {
243 
244  // Should we unconditionally use the Src?
245  if (shouldOverrideFromSrc()) {
246  LinkFromSrc = true;
247  return false;
248  }
249 
250  // We always have to add Src if it has appending linkage.
251  if (Src.hasAppendingLinkage() || Dest.hasAppendingLinkage()) {
252  LinkFromSrc = true;
253  return false;
254  }
255 
256  bool SrcIsDeclaration = Src.isDeclarationForLinker();
257  bool DestIsDeclaration = Dest.isDeclarationForLinker();
258 
259  if (SrcIsDeclaration) {
260  // If Src is external or if both Src & Dest are external.. Just link the
261  // external globals, we aren't adding anything.
262  if (Src.hasDLLImportStorageClass()) {
263  // If one of GVs is marked as DLLImport, result should be dllimport'ed.
264  LinkFromSrc = DestIsDeclaration;
265  return false;
266  }
267  // If the Dest is weak, use the source linkage.
268  if (Dest.hasExternalWeakLinkage()) {
269  LinkFromSrc = true;
270  return false;
271  }
272  // Link an available_externally over a declaration.
273  LinkFromSrc = !Src.isDeclaration() && Dest.isDeclaration();
274  return false;
275  }
276 
277  if (DestIsDeclaration) {
278  // If Dest is external but Src is not:
279  LinkFromSrc = true;
280  return false;
281  }
282 
283  if (Src.hasCommonLinkage()) {
284  if (Dest.hasLinkOnceLinkage() || Dest.hasWeakLinkage()) {
285  LinkFromSrc = true;
286  return false;
287  }
288 
289  if (!Dest.hasCommonLinkage()) {
290  LinkFromSrc = false;
291  return false;
292  }
293 
294  const DataLayout &DL = Dest.getParent()->getDataLayout();
295  uint64_t DestSize = DL.getTypeAllocSize(Dest.getValueType());
296  uint64_t SrcSize = DL.getTypeAllocSize(Src.getValueType());
297  LinkFromSrc = SrcSize > DestSize;
298  return false;
299  }
300 
301  if (Src.isWeakForLinker()) {
304 
305  if (Dest.hasLinkOnceLinkage() && Src.hasWeakLinkage()) {
306  LinkFromSrc = true;
307  return false;
308  }
309 
310  LinkFromSrc = false;
311  return false;
312  }
313 
314  if (Dest.isWeakForLinker()) {
315  assert(Src.hasExternalLinkage());
316  LinkFromSrc = true;
317  return false;
318  }
319 
320  assert(!Src.hasExternalWeakLinkage());
322  assert(Dest.hasExternalLinkage() && Src.hasExternalLinkage() &&
323  "Unexpected linkage type!");
324  return emitError("Linking globals named '" + Src.getName() +
325  "': symbol multiply defined!");
326 }
327 
328 bool ModuleLinker::linkIfNeeded(GlobalValue &GV,
329  SmallVectorImpl<GlobalValue *> &GVToClone) {
330  GlobalValue *DGV = getLinkedToGlobal(&GV);
331 
332  if (shouldLinkOnlyNeeded()) {
333  // Always import variables with appending linkage.
334  if (!GV.hasAppendingLinkage()) {
335  // Don't import globals unless they are referenced by the destination
336  // module.
337  if (!DGV)
338  return false;
339  // Don't import globals that are already defined in the destination module
340  if (!DGV->isDeclaration())
341  return false;
342  }
343  }
344 
345  if (DGV && !GV.hasLocalLinkage() && !GV.hasAppendingLinkage()) {
346  auto *DGVar = dyn_cast<GlobalVariable>(DGV);
347  auto *SGVar = dyn_cast<GlobalVariable>(&GV);
348  if (DGVar && SGVar) {
349  if (DGVar->isDeclaration() && SGVar->isDeclaration() &&
350  (!DGVar->isConstant() || !SGVar->isConstant())) {
351  DGVar->setConstant(false);
352  SGVar->setConstant(false);
353  }
354  if (DGVar->hasCommonLinkage() && SGVar->hasCommonLinkage()) {
356  std::max(DGVar->getAlignment(), SGVar->getAlignment()));
357  SGVar->setAlignment(Align);
358  DGVar->setAlignment(Align);
359  }
360  }
361 
362  GlobalValue::VisibilityTypes Visibility =
364  DGV->setVisibility(Visibility);
365  GV.setVisibility(Visibility);
366 
368  DGV->getUnnamedAddr(), GV.getUnnamedAddr());
369  DGV->setUnnamedAddr(UnnamedAddr);
370  GV.setUnnamedAddr(UnnamedAddr);
371  }
372 
373  if (!DGV && !shouldOverrideFromSrc() &&
374  (GV.hasLocalLinkage() || GV.hasLinkOnceLinkage() ||
376  return false;
377 
378  if (GV.isDeclaration())
379  return false;
380 
381  LinkFrom ComdatFrom = LinkFrom::Dst;
382  if (const Comdat *SC = GV.getComdat()) {
383  std::tie(std::ignore, ComdatFrom) = ComdatsChosen[SC];
384  if (ComdatFrom == LinkFrom::Dst)
385  return false;
386  }
387 
388  bool LinkFromSrc = true;
389  if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, GV))
390  return true;
391  if (DGV && ComdatFrom == LinkFrom::Both)
392  GVToClone.push_back(LinkFromSrc ? DGV : &GV);
393  if (LinkFromSrc)
394  ValuesToLink.insert(&GV);
395  return false;
396 }
397 
398 void ModuleLinker::addLazyFor(GlobalValue &GV, const IRMover::ValueAdder &Add) {
399  // Add these to the internalize list
401  !shouldLinkOnlyNeeded())
402  return;
403 
404  if (InternalizeCallback)
405  Internalize.insert(GV.getName());
406  Add(GV);
407 
408  const Comdat *SC = GV.getComdat();
409  if (!SC)
410  return;
411  for (GlobalValue *GV2 : LazyComdatMembers[SC]) {
412  GlobalValue *DGV = getLinkedToGlobal(GV2);
413  bool LinkFromSrc = true;
414  if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, *GV2))
415  return;
416  if (!LinkFromSrc)
417  continue;
418  if (InternalizeCallback)
419  Internalize.insert(GV2->getName());
420  Add(*GV2);
421  }
422 }
423 
424 void ModuleLinker::dropReplacedComdat(
425  GlobalValue &GV, const DenseSet<const Comdat *> &ReplacedDstComdats) {
426  Comdat *C = GV.getComdat();
427  if (!C)
428  return;
429  if (!ReplacedDstComdats.count(C))
430  return;
431  if (GV.use_empty()) {
432  GV.eraseFromParent();
433  return;
434  }
435 
436  if (auto *F = dyn_cast<Function>(&GV)) {
437  F->deleteBody();
438  } else if (auto *Var = dyn_cast<GlobalVariable>(&GV)) {
439  Var->setInitializer(nullptr);
440  } else {
441  auto &Alias = cast<GlobalAlias>(GV);
442  Module &M = *Alias.getParent();
443  GlobalValue *Declaration;
444  if (auto *FTy = dyn_cast<FunctionType>(Alias.getValueType())) {
445  Declaration = Function::Create(FTy, GlobalValue::ExternalLinkage, "", &M);
446  } else {
447  Declaration =
448  new GlobalVariable(M, Alias.getValueType(), /*isConstant*/ false,
450  /*Initializer*/ nullptr);
451  }
452  Declaration->takeName(&Alias);
453  Alias.replaceAllUsesWith(Declaration);
454  Alias.eraseFromParent();
455  }
456 }
457 
458 bool ModuleLinker::run() {
459  Module &DstM = Mover.getModule();
460  DenseSet<const Comdat *> ReplacedDstComdats;
461 
462  for (const auto &SMEC : SrcM->getComdatSymbolTable()) {
463  const Comdat &C = SMEC.getValue();
464  if (ComdatsChosen.count(&C))
465  continue;
467  LinkFrom From;
468  if (getComdatResult(&C, SK, From))
469  return true;
470  ComdatsChosen[&C] = std::make_pair(SK, From);
471 
472  if (From != LinkFrom::Src)
473  continue;
474 
475  Module::ComdatSymTabType &ComdatSymTab = DstM.getComdatSymbolTable();
476  Module::ComdatSymTabType::iterator DstCI = ComdatSymTab.find(C.getName());
477  if (DstCI == ComdatSymTab.end())
478  continue;
479 
480  // The source comdat is replacing the dest one.
481  const Comdat *DstC = &DstCI->second;
482  ReplacedDstComdats.insert(DstC);
483  }
484 
485  // Alias have to go first, since we are not able to find their comdats
486  // otherwise.
488  dropReplacedComdat(GV, ReplacedDstComdats);
489 
491  dropReplacedComdat(GV, ReplacedDstComdats);
492 
493  for (Function &GV : llvm::make_early_inc_range(DstM))
494  dropReplacedComdat(GV, ReplacedDstComdats);
495 
496  for (GlobalVariable &GV : SrcM->globals())
497  if (GV.hasLinkOnceLinkage())
498  if (const Comdat *SC = GV.getComdat())
499  LazyComdatMembers[SC].push_back(&GV);
500 
501  for (Function &SF : *SrcM)
502  if (SF.hasLinkOnceLinkage())
503  if (const Comdat *SC = SF.getComdat())
504  LazyComdatMembers[SC].push_back(&SF);
505 
506  for (GlobalAlias &GA : SrcM->aliases())
507  if (GA.hasLinkOnceLinkage())
508  if (const Comdat *SC = GA.getComdat())
509  LazyComdatMembers[SC].push_back(&GA);
510 
511  // Insert all of the globals in src into the DstM module... without linking
512  // initializers (which could refer to functions not yet mapped over).
514  for (GlobalVariable &GV : SrcM->globals())
515  if (linkIfNeeded(GV, GVToClone))
516  return true;
517 
518  for (Function &SF : *SrcM)
519  if (linkIfNeeded(SF, GVToClone))
520  return true;
521 
522  for (GlobalAlias &GA : SrcM->aliases())
523  if (linkIfNeeded(GA, GVToClone))
524  return true;
525 
526  for (GlobalIFunc &GI : SrcM->ifuncs())
527  if (linkIfNeeded(GI, GVToClone))
528  return true;
529 
530  // For a variable in a comdat nodeduplicate, its initializer should be
531  // preserved (its content may be implicitly used by other members) even if
532  // symbol resolution does not pick it. Clone it into an unnamed private
533  // variable.
534  for (GlobalValue *GV : GVToClone) {
535  if (auto *Var = dyn_cast<GlobalVariable>(GV)) {
536  auto *NewVar = new GlobalVariable(*Var->getParent(), Var->getValueType(),
537  Var->isConstant(), Var->getLinkage(),
538  Var->getInitializer());
539  NewVar->copyAttributesFrom(Var);
540  NewVar->setVisibility(GlobalValue::DefaultVisibility);
541  NewVar->setLinkage(GlobalValue::PrivateLinkage);
542  NewVar->setDSOLocal(true);
543  NewVar->setComdat(Var->getComdat());
544  if (Var->getParent() != &Mover.getModule())
545  ValuesToLink.insert(NewVar);
546  } else {
547  emitError("linking '" + GV->getName() +
548  "': non-variables in comdat nodeduplicate are not handled");
549  }
550  }
551 
552  for (unsigned I = 0; I < ValuesToLink.size(); ++I) {
553  GlobalValue *GV = ValuesToLink[I];
554  const Comdat *SC = GV->getComdat();
555  if (!SC)
556  continue;
557  for (GlobalValue *GV2 : LazyComdatMembers[SC]) {
558  GlobalValue *DGV = getLinkedToGlobal(GV2);
559  bool LinkFromSrc = true;
560  if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, *GV2))
561  return true;
562  if (LinkFromSrc)
563  ValuesToLink.insert(GV2);
564  }
565  }
566 
567  if (InternalizeCallback) {
568  for (GlobalValue *GV : ValuesToLink)
569  Internalize.insert(GV->getName());
570  }
571 
572  // FIXME: Propagate Errors through to the caller instead of emitting
573  // diagnostics.
574  bool HasErrors = false;
575  if (Error E =
576  Mover.move(std::move(SrcM), ValuesToLink.getArrayRef(),
578  [this](GlobalValue &GV, IRMover::ValueAdder Add) {
579  addLazyFor(GV, Add);
580  }),
581  /* IsPerformingImport */ false)) {
583  DstM.getContext().diagnose(LinkDiagnosticInfo(DS_Error, EIB.message()));
584  HasErrors = true;
585  });
586  }
587  if (HasErrors)
588  return true;
589 
590  if (InternalizeCallback)
591  InternalizeCallback(DstM, Internalize);
592 
593  return false;
594 }
595 
596 Linker::Linker(Module &M) : Mover(M) {}
597 
599  std::unique_ptr<Module> Src, unsigned Flags,
600  std::function<void(Module &, const StringSet<> &)> InternalizeCallback) {
601  ModuleLinker ModLinker(Mover, std::move(Src), Flags,
602  std::move(InternalizeCallback));
603  return ModLinker.run();
604 }
605 
606 //===----------------------------------------------------------------------===//
607 // LinkModules entrypoint.
608 //===----------------------------------------------------------------------===//
609 
610 /// This function links two modules together, with the resulting Dest module
611 /// modified to be the composite of the two input modules. If an error occurs,
612 /// true is returned and ErrorMsg (if not null) is set to indicate the problem.
613 /// Upon failure, the Dest module could be in a modified state, and shouldn't be
614 /// relied on to be consistent.
616  Module &Dest, std::unique_ptr<Module> Src, unsigned Flags,
617  std::function<void(Module &, const StringSet<> &)> InternalizeCallback) {
618  Linker L(Dest);
619  return L.linkInModule(std::move(Src), Flags, std::move(InternalizeCallback));
620 }
621 
622 //===----------------------------------------------------------------------===//
623 // C API.
624 //===----------------------------------------------------------------------===//
625 
627  Module *D = unwrap(Dest);
628  std::unique_ptr<Module> M(unwrap(Src));
629  return Linker::linkModules(*D, std::move(M));
630 }
llvm::GlobalValue::UnnamedAddr
UnnamedAddr
Definition: GlobalValue.h:189
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
Comdat.h
llvm::Comdat::getName
StringRef getName() const
Definition: Comdat.cpp:28
llvm::GlobalValue::hasCommonLinkage
bool hasCommonLinkage() const
Definition: GlobalValue.h:454
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::GlobalValue::hasExternalLinkage
bool hasExternalLinkage() const
Definition: GlobalValue.h:433
llvm::unique_function
unique_function is a type-erasing functor similar to std::function.
Definition: FunctionExtras.h:56
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition: GlobalValue.h:466
llvm::GlobalValue::HiddenVisibility
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
llvm::Function
Definition: Function.h:60
llvm::SetVector::size
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:77
llvm::GlobalValue::hasWeakLinkage
bool hasWeakLinkage() const
Definition: GlobalValue.h:444
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::GlobalValue::isLocalLinkage
static bool isLocalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:331
llvm::Value::hasName
bool hasName() const
Definition: Value.h:261
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::SystemZICMP::Any
@ Any
Definition: SystemZISelLowering.h:377
llvm::GlobalAlias
Definition: GlobalAlias.h:28
Error.h
llvm::StringMap::end
iterator end()
Definition: StringMap.h:205
Module.h
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:147
llvm::GlobalValue::DefaultVisibility
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:63
llvm::CFLAAType::Both
@ Both
llvm::StringSet::insert
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition: StringSet.h:34
llvm::GlobalValue::setUnnamedAddr
void setUnnamedAddr(UnnamedAddr Val)
Definition: GlobalValue.h:211
llvm::StringMap::find
iterator find(StringRef Key)
Definition: StringMap.h:218
llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::count
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:97
llvm::GlobalValue::hasExternalWeakLinkage
bool hasExternalWeakLinkage() const
Definition: GlobalValue.h:451
llvm::IRMover::getModule
Module & getModule()
Definition: IRMover.h:81
LLVMLinkModules2
LLVMBool LLVMLinkModules2(LLVMModuleRef Dest, LLVMModuleRef Src)
Definition: LinkModules.cpp:626
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::Linker::LinkOnlyNeeded
@ LinkOnlyNeeded
Definition: Linker.h:29
GlobalValue.h
llvm::GlobalValue::isDeclaration
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:241
LinkDiagnosticInfo.h
llvm::PPCISD::SC
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
Definition: PPCISelLowering.h:418
llvm::GlobalValue::VisibilityTypes
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition: GlobalValue.h:62
llvm::GlobalValue::hasAppendingLinkage
bool hasAppendingLinkage() const
Definition: GlobalValue.h:447
llvm::Module::globals
iterator_range< global_iterator > globals()
Definition: Module.h:614
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Linker.h
llvm::Comdat::SelectionKind
SelectionKind
Definition: Comdat.h:35
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::Linker::linkModules
static bool linkModules(Module &Dest, std::unique_ptr< Module > Src, unsigned Flags=Flags::None, std::function< void(Module &, const StringSet<> &)> InternalizeCallback={})
This function links two modules together, with the resulting Dest module modified to be the composite...
Definition: LinkModules.cpp:615
llvm::ms_demangle::QualifierMangleMode::Result
@ Result
llvm::MaybeAlign
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:109
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::Module::getComdatSymbolTable
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
Definition: Module.h:599
llvm::IRMover::move
Error move(std::unique_ptr< Module > Src, ArrayRef< GlobalValue * > ValuesToLink, LazyCallback AddLazyFor, bool IsPerformingImport)
Move in the provide values in ValuesToLink from Src.
Definition: IRMover.cpp:1714
llvm::unwrap
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:264
Align
uint64_t Align
Definition: ELFObjHandler.cpp:81
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::Comdat
Definition: Comdat.h:33
llvm::ErrorInfoBase
Base class for error info classes.
Definition: Error.h:46
llvm::Value::use_empty
bool use_empty() const
Definition: Value.h:344
llvm::ErrorInfoBase::message
virtual std::string message() const
Return the error message as a string.
Definition: Error.h:54
llvm::StringMap< Comdat >
llvm::dxil::PointerTypeAnalysis::run
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
Definition: PointerTypeAnalysis.cpp:101
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
llvm::Module::aliases
iterator_range< alias_iterator > aliases()
Definition: Module.h:654
llvm::GlobalValue::hasAvailableExternallyLinkage
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:434
llvm::IRMover
Definition: IRMover.h:26
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::GlobalVariable::getInitializer
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Definition: GlobalVariable.h:135
llvm::StringMapIterator
Definition: StringMap.h:27
llvm::GlobalValue::isWeakForLinker
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
Definition: GlobalValue.h:380
uint64_t
llvm::GlobalValue::getVisibility
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:228
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:577
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::DenseMap
Definition: DenseMap.h:716
llvm::IRMover::ValueAdder
std::function< void(GlobalValue &)> ValueAdder
Definition: IRMover.h:65
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::make_early_inc_range
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition: STLExtras.h:608
llvm::Function::Create
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:137
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::GlobalValue::hasLocalLinkage
bool hasLocalLinkage() const
Definition: GlobalValue.h:450
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
getMinVisibility
static GlobalValue::VisibilityTypes getMinVisibility(GlobalValue::VisibilityTypes A, GlobalValue::VisibilityTypes B)
Definition: LinkModules.cpp:121
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::Linker
This class provides the core functionality of linking in LLVM.
Definition: Linker.h:22
llvm::SetVector::insert
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
llvm::Linker::Linker
Linker(Module &M)
Definition: LinkModules.cpp:596
llvm::StringSet
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:23
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::GlobalValue::getAliaseeObject
const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:329
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:305
llvm::GlobalValue::eraseFromParent
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:84
llvm::GlobalValue::getUnnamedAddr
UnnamedAddr getUnnamedAddr() const
Definition: GlobalValue.h:208
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::Linker::Flags
Flags
Definition: Linker.h:26
LLVMBool
int LLVMBool
Definition: Types.h:28
llvm::Linker::OverrideFromSrc
@ OverrideFromSrc
Definition: Linker.h:28
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::Linker::linkInModule
bool linkInModule(std::unique_ptr< Module > Src, unsigned Flags=Flags::None, std::function< void(Module &, const StringSet<> &)> InternalizeCallback={})
Link Src into the composite.
Definition: LinkModules.cpp:598
llvm::GlobalValue::getComdat
const Comdat * getComdat() const
Definition: Globals.cpp:177
llvm::Module::getContext
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:262
llvm::GlobalValue::ProtectedVisibility
@ ProtectedVisibility
The GV is protected.
Definition: GlobalValue.h:65
llvm::MCID::Add
@ Add
Definition: MCInstrDesc.h:185
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
llvm::GlobalValue::PrivateLinkage
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:56
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::GlobalValue::isDeclarationForLinker
bool isDeclarationForLinker() const
Definition: GlobalValue.h:539
llvm::LinkDiagnosticInfo
Definition: LinkDiagnosticInfo.h:15
llvm::GlobalValue::hasLinkOnceLinkage
bool hasLinkOnceLinkage() const
Definition: GlobalValue.h:437
Linker.h
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::Module::getDataLayout
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:398
llvm::GlobalValue::getValueType
Type * getValueType() const
Definition: GlobalValue.h:272
LLVMContext.h
From
BlockVerifier::State From
Definition: BlockVerifier.cpp:55
llvm::Value::takeName
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:378
llvm::Comdat::getSelectionKind
SelectionKind getSelectionKind() const
Definition: Comdat.h:46
llvm::SetVector
A vector that has set insertion semantics.
Definition: SetVector.h:40
llvm::GlobalIFunc
Definition: GlobalIFunc.h:34
llvm::GlobalValue::setVisibility
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:234
llvm::handleAllErrors
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Definition: Error.h:966
llvm::DS_Error
@ DS_Error
Definition: DiagnosticInfo.h:50
llvm::GlobalValue::getMinUnnamedAddr
static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B)
Definition: GlobalValue.h:213
llvm::Module::getNamedValue
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
Definition: Module.cpp:110
SetVector.h
LLVMModuleRef
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:61
llvm::DataLayout::getTypeAllocSize
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:506