LLVM  6.0.0svn
LinkModules.cpp
Go to the documentation of this file.
1 //===- lib/Linker/LinkModules.cpp - Module Linker Implementation ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the LLVM module linker.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "LinkDiagnosticInfo.h"
15 #include "llvm-c/Linker.h"
16 #include "llvm/ADT/SetVector.h"
17 #include "llvm/IR/Comdat.h"
19 #include "llvm/IR/GlobalValue.h"
20 #include "llvm/IR/LLVMContext.h"
21 #include "llvm/IR/Module.h"
22 #include "llvm/Linker/Linker.h"
23 #include "llvm/Support/Error.h"
24 using namespace llvm;
25 
26 namespace {
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  bool &LinkFromSrc);
72  std::map<const Comdat *, std::pair<Comdat::SelectionKind, bool>>
73  ComdatsChosen;
74  bool getComdatResult(const Comdat *SrcC, Comdat::SelectionKind &SK,
75  bool &LinkFromSrc);
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);
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 }
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->getBaseObject();
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  bool &LinkFromSrc) {
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  LinkFromSrc = false;
180  break;
181  case Comdat::SelectionKind::NoDuplicates:
182  return emitError("Linking COMDATs named '" + ComdatName +
183  "': noduplicates has been violated!");
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  LinkFromSrc = false;
202  } else if (Result == Comdat::SelectionKind::Largest) {
203  LinkFromSrc = SrcSize > DstSize;
204  } else if (Result == Comdat::SelectionKind::SameSize) {
205  if (SrcSize != DstSize)
206  return emitError("Linking COMDATs named '" + ComdatName +
207  "': SameSize violated!");
208  LinkFromSrc = false;
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  bool &LinkFromSrc) {
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  LinkFromSrc = true;
231  Result = SSK;
232  return false;
233  }
234 
235  const Comdat *DstC = &DstCI->second;
237  return computeResultingSelectionKind(ComdatName, SSK, DSK, Result,
238  LinkFromSrc);
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()) {
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 
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  GlobalValue *DGV = getLinkedToGlobal(&GV);
331 
332  if (shouldLinkOnlyNeeded() && !(DGV && DGV->isDeclaration()))
333  return false;
334 
335  if (DGV && !GV.hasLocalLinkage() && !GV.hasAppendingLinkage()) {
336  auto *DGVar = dyn_cast<GlobalVariable>(DGV);
337  auto *SGVar = dyn_cast<GlobalVariable>(&GV);
338  if (DGVar && SGVar) {
339  if (DGVar->isDeclaration() && SGVar->isDeclaration() &&
340  (!DGVar->isConstant() || !SGVar->isConstant())) {
341  DGVar->setConstant(false);
342  SGVar->setConstant(false);
343  }
344  if (DGVar->hasCommonLinkage() && SGVar->hasCommonLinkage()) {
345  unsigned Align = std::max(DGVar->getAlignment(), SGVar->getAlignment());
346  SGVar->setAlignment(Align);
347  DGVar->setAlignment(Align);
348  }
349  }
350 
353  DGV->setVisibility(Visibility);
354  GV.setVisibility(Visibility);
355 
357  DGV->getUnnamedAddr(), GV.getUnnamedAddr());
358  DGV->setUnnamedAddr(UnnamedAddr);
359  GV.setUnnamedAddr(UnnamedAddr);
360  }
361 
362  if (!DGV && !shouldOverrideFromSrc() &&
363  (GV.hasLocalLinkage() || GV.hasLinkOnceLinkage() ||
365  return false;
366 
367  if (GV.isDeclaration())
368  return false;
369 
370  if (const Comdat *SC = GV.getComdat()) {
371  bool LinkFromSrc;
373  std::tie(SK, LinkFromSrc) = ComdatsChosen[SC];
374  if (!LinkFromSrc)
375  return false;
376  }
377 
378  bool LinkFromSrc = true;
379  if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, GV))
380  return true;
381  if (LinkFromSrc)
382  ValuesToLink.insert(&GV);
383  return false;
384 }
385 
386 void ModuleLinker::addLazyFor(GlobalValue &GV, const IRMover::ValueAdder &Add) {
387  // Add these to the internalize list
389  !shouldLinkOnlyNeeded())
390  return;
391 
392  if (InternalizeCallback)
393  Internalize.insert(GV.getName());
394  Add(GV);
395 
396  const Comdat *SC = GV.getComdat();
397  if (!SC)
398  return;
399  for (GlobalValue *GV2 : LazyComdatMembers[SC]) {
400  GlobalValue *DGV = getLinkedToGlobal(GV2);
401  bool LinkFromSrc = true;
402  if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, *GV2))
403  return;
404  if (!LinkFromSrc)
405  continue;
406  if (InternalizeCallback)
407  Internalize.insert(GV2->getName());
408  Add(*GV2);
409  }
410 }
411 
412 void ModuleLinker::dropReplacedComdat(
413  GlobalValue &GV, const DenseSet<const Comdat *> &ReplacedDstComdats) {
414  Comdat *C = GV.getComdat();
415  if (!C)
416  return;
417  if (!ReplacedDstComdats.count(C))
418  return;
419  if (GV.use_empty()) {
420  GV.eraseFromParent();
421  return;
422  }
423 
424  if (auto *F = dyn_cast<Function>(&GV)) {
425  F->deleteBody();
426  } else if (auto *Var = dyn_cast<GlobalVariable>(&GV)) {
427  Var->setInitializer(nullptr);
428  } else {
429  auto &Alias = cast<GlobalAlias>(GV);
430  Module &M = *Alias.getParent();
431  PointerType &Ty = *cast<PointerType>(Alias.getType());
432  GlobalValue *Declaration;
433  if (auto *FTy = dyn_cast<FunctionType>(Alias.getValueType())) {
434  Declaration = Function::Create(FTy, GlobalValue::ExternalLinkage, "", &M);
435  } else {
436  Declaration =
437  new GlobalVariable(M, Ty.getElementType(), /*isConstant*/ false,
439  /*Initializer*/ nullptr);
440  }
441  Declaration->takeName(&Alias);
442  Alias.replaceAllUsesWith(Declaration);
443  Alias.eraseFromParent();
444  }
445 }
446 
447 bool ModuleLinker::run() {
448  Module &DstM = Mover.getModule();
449  DenseSet<const Comdat *> ReplacedDstComdats;
450 
451  for (const auto &SMEC : SrcM->getComdatSymbolTable()) {
452  const Comdat &C = SMEC.getValue();
453  if (ComdatsChosen.count(&C))
454  continue;
456  bool LinkFromSrc;
457  if (getComdatResult(&C, SK, LinkFromSrc))
458  return true;
459  ComdatsChosen[&C] = std::make_pair(SK, LinkFromSrc);
460 
461  if (!LinkFromSrc)
462  continue;
463 
464  Module::ComdatSymTabType &ComdatSymTab = DstM.getComdatSymbolTable();
465  Module::ComdatSymTabType::iterator DstCI = ComdatSymTab.find(C.getName());
466  if (DstCI == ComdatSymTab.end())
467  continue;
468 
469  // The source comdat is replacing the dest one.
470  const Comdat *DstC = &DstCI->second;
471  ReplacedDstComdats.insert(DstC);
472  }
473 
474  // Alias have to go first, since we are not able to find their comdats
475  // otherwise.
476  for (auto I = DstM.alias_begin(), E = DstM.alias_end(); I != E;) {
477  GlobalAlias &GV = *I++;
478  dropReplacedComdat(GV, ReplacedDstComdats);
479  }
480 
481  for (auto I = DstM.global_begin(), E = DstM.global_end(); I != E;) {
482  GlobalVariable &GV = *I++;
483  dropReplacedComdat(GV, ReplacedDstComdats);
484  }
485 
486  for (auto I = DstM.begin(), E = DstM.end(); I != E;) {
487  Function &GV = *I++;
488  dropReplacedComdat(GV, ReplacedDstComdats);
489  }
490 
491  for (GlobalVariable &GV : SrcM->globals())
492  if (GV.hasLinkOnceLinkage())
493  if (const Comdat *SC = GV.getComdat())
494  LazyComdatMembers[SC].push_back(&GV);
495 
496  for (Function &SF : *SrcM)
497  if (SF.hasLinkOnceLinkage())
498  if (const Comdat *SC = SF.getComdat())
499  LazyComdatMembers[SC].push_back(&SF);
500 
501  for (GlobalAlias &GA : SrcM->aliases())
502  if (GA.hasLinkOnceLinkage())
503  if (const Comdat *SC = GA.getComdat())
504  LazyComdatMembers[SC].push_back(&GA);
505 
506  // Insert all of the globals in src into the DstM module... without linking
507  // initializers (which could refer to functions not yet mapped over).
508  for (GlobalVariable &GV : SrcM->globals())
509  if (linkIfNeeded(GV))
510  return true;
511 
512  for (Function &SF : *SrcM)
513  if (linkIfNeeded(SF))
514  return true;
515 
516  for (GlobalAlias &GA : SrcM->aliases())
517  if (linkIfNeeded(GA))
518  return true;
519 
520  for (unsigned I = 0; I < ValuesToLink.size(); ++I) {
521  GlobalValue *GV = ValuesToLink[I];
522  const Comdat *SC = GV->getComdat();
523  if (!SC)
524  continue;
525  for (GlobalValue *GV2 : LazyComdatMembers[SC]) {
526  GlobalValue *DGV = getLinkedToGlobal(GV2);
527  bool LinkFromSrc = true;
528  if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, *GV2))
529  return true;
530  if (LinkFromSrc)
531  ValuesToLink.insert(GV2);
532  }
533  }
534 
535  if (InternalizeCallback) {
536  for (GlobalValue *GV : ValuesToLink)
537  Internalize.insert(GV->getName());
538  }
539 
540  // FIXME: Propagate Errors through to the caller instead of emitting
541  // diagnostics.
542  bool HasErrors = false;
543  if (Error E = Mover.move(std::move(SrcM), ValuesToLink.getArrayRef(),
544  [this](GlobalValue &GV, IRMover::ValueAdder Add) {
545  addLazyFor(GV, Add);
546  },
547  /* IsPerformingImport */ false)) {
548  handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
550  HasErrors = true;
551  });
552  }
553  if (HasErrors)
554  return true;
555 
556  if (InternalizeCallback)
557  InternalizeCallback(DstM, Internalize);
558 
559  return false;
560 }
561 
562 Linker::Linker(Module &M) : Mover(M) {}
563 
565  std::unique_ptr<Module> Src, unsigned Flags,
566  std::function<void(Module &, const StringSet<> &)> InternalizeCallback) {
567  ModuleLinker ModLinker(Mover, std::move(Src), Flags,
568  std::move(InternalizeCallback));
569  return ModLinker.run();
570 }
571 
572 //===----------------------------------------------------------------------===//
573 // LinkModules entrypoint.
574 //===----------------------------------------------------------------------===//
575 
576 /// This function links two modules together, with the resulting Dest module
577 /// modified to be the composite of the two input modules. If an error occurs,
578 /// true is returned and ErrorMsg (if not null) is set to indicate the problem.
579 /// Upon failure, the Dest module could be in a modified state, and shouldn't be
580 /// relied on to be consistent.
582  Module &Dest, std::unique_ptr<Module> Src, unsigned Flags,
583  std::function<void(Module &, const StringSet<> &)> InternalizeCallback) {
584  Linker L(Dest);
585  return L.linkInModule(std::move(Src), Flags, std::move(InternalizeCallback));
586 }
587 
588 //===----------------------------------------------------------------------===//
589 // C API.
590 //===----------------------------------------------------------------------===//
591 
593  Module *D = unwrap(Dest);
594  std::unique_ptr<Module> M(unwrap(Src));
595  return Linker::linkModules(*D, std::move(M));
596 }
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:226
bool isDeclarationForLinker() const
Definition: GlobalValue.h:503
uint64_t CallInst * C
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
bool hasLocalLinkage() const
Definition: GlobalValue.h:416
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition: Types.h:62
ArrayRef< T > getArrayRef() const
Definition: SetVector.h:64
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:78
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
Implements a dense probed hash-table based set.
Definition: DenseSet.h:221
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:403
iterator find(StringRef Key)
Definition: StringMap.h:337
virtual std::string message() const
Return the error message as a string.
Definition: Error.h:55
Externally visible function.
Definition: GlobalValue.h:49
bool hasDLLImportStorageClass() const
Definition: GlobalValue.h:248
ELFYAML::ELF_STV Visibility
Definition: ELFYAML.cpp:694
bool hasExternalWeakLinkage() const
Definition: GlobalValue.h:417
Base class for error info classes.
Definition: Error.h:47
LLVMBool LLVMLinkModules2(LLVMModuleRef Dest, LLVMModuleRef Src)
static bool isLocalLinkage(LinkageTypes Linkage)
Definition: GlobalValue.h:301
Linker(Module &M)
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:361
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
Attribute unwrap(LLVMAttributeRef Attr)
Definition: Attributes.h:195
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module&#39;s symbol table for COMDATs (constant).
Definition: Module.h:547
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:237
UnnamedAddr getUnnamedAddr() const
Definition: GlobalValue.h:200
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...
bool hasCommonLinkage() const
Definition: GlobalValue.h:420
Module & getModule()
Definition: IRMover.h:79
global_iterator global_begin()
Definition: Module.h:555
bool hasExternalLinkage() const
Definition: GlobalValue.h:402
#define F(x, y, z)
Definition: MD5.cpp:55
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:142
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:1445
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition: GlobalValue.h:63
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
Definition: Module.cpp:112
This class provides the core functionality of linking in LLVM.
Definition: Linker.h:25
LinkageTypes getLinkage() const
Definition: GlobalValue.h:430
bool hasLinkOnceLinkage() const
Definition: GlobalValue.h:406
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:290
Class to represent pointers.
Definition: DerivedTypes.h:467
bool hasAppendingLinkage() const
Definition: GlobalValue.h:413
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
Definition: GlobalValue.h:350
StringRef getName() const
Definition: Comdat.cpp:24
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:220
alias_iterator alias_end()
Definition: Module.h:596
bool hasName() const
Definition: Value.h:251
#define A
Definition: LargeTest.cpp:12
static GlobalValue::VisibilityTypes getMinVisibility(GlobalValue::VisibilityTypes A, GlobalValue::VisibilityTypes B)
void setConstant(bool Val)
int LLVMBool
Definition: Types.h:29
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::pair< typename base::iterator, bool > insert(StringRef Key)
Definition: StringSet.h:38
bool hasWeakLinkage() const
Definition: GlobalValue.h:410
global_iterator global_end()
Definition: Module.h:557
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that it requires that all errors be handled by the given han...
Definition: Error.h:555
#define E
Definition: LargeTest.cpp:27
#define B
Definition: LargeTest.cpp:24
Module.h This file contains the declarations for the Module class.
CHAIN = SC CHAIN, Imm128 - System call.
alias_iterator alias_begin()
Definition: Module.h:594
const Comdat * getComdat() const
Definition: Globals.cpp:165
bool linkInModule(std::unique_ptr< Module > Src, unsigned Flags=Flags::None, std::function< void(Module &, const StringSet<> &)> InternalizeCallback={})
Link Src into the composite.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:405
static std::vector< std::string > Flags
Definition: FlagsTest.cpp:8
void eraseFromParent()
This method unlinks &#39;this&#39; from the containing module and deletes it.
Definition: Globals.cpp:84
iterator end()
Definition: Module.h:574
void setUnnamedAddr(UnnamedAddr Val)
Definition: GlobalValue.h:203
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:218
#define I(x, y, z)
Definition: MD5.cpp:58
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
iterator begin()
Definition: Module.h:572
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
Type * getValueType() const
Definition: GlobalValue.h:262
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:91
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:200
const GlobalObject * getBaseObject() const
Definition: Globals.cpp:255
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::function< void(GlobalValue &)> ValueAdder
Definition: IRMover.h:65
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:545
A vector that has set insertion semantics.
Definition: SetVector.h:41
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:28
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
Definition: Function.h:128
static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B)
Definition: GlobalValue.h:205
bool use_empty() const
Definition: Value.h:322
iterator end()
Definition: StringMap.h:322
#define D
Definition: LargeTest.cpp:26
Type * getElementType() const
Definition: DerivedTypes.h:486
SelectionKind getSelectionKind() const
Definition: Comdat.h:42