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