LLVM 23.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"
22using namespace llvm;
23
24namespace {
25
26enum class LinkFrom { Dst, Src, Both };
27
28/// This is an implementation class for the LinkModules function, which is the
29/// entrypoint for this file.
30class 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,
71 LinkFrom &From);
72 DenseMap<const Comdat *, std::pair<Comdat::SelectionKind, LinkFrom>>
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.
77 DenseMap<const Comdat *, std::vector<GlobalValue *>> LazyComdatMembers;
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
109public:
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
130
131bool 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
143 if (!GVar)
144 return emitError(
145 "Linking COMDATs named '" + ComdatName +
146 "': GlobalVariable required for data dependent selection!");
147
148 return false;
149}
150
151bool 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
168 Result = Comdat::SelectionKind::Any;
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) {
177 case Comdat::SelectionKind::Any:
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 = DstGV->getGlobalSize(DstDL);
196 uint64_t SrcSize = SrcGV->getGlobalSize(SrcDL);
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
219bool 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
240bool 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.getDataLayout();
295 // Functions and aliases may not have common linkage, so both must be
296 // GlobalVariables here
297 uint64_t DestSize = cast<GlobalVariable>(Dest).getGlobalSize(DL);
298 uint64_t SrcSize = cast<GlobalVariable>(Src).getGlobalSize(DL);
299 LinkFromSrc = SrcSize > DestSize;
300 return false;
301 }
302
303 if (Src.isWeakForLinker()) {
306
307 if (Dest.hasLinkOnceLinkage() && Src.hasWeakLinkage()) {
308 LinkFromSrc = true;
309 return false;
310 }
311
312 LinkFromSrc = false;
313 return false;
314 }
315
316 if (Dest.isWeakForLinker()) {
317 assert(Src.hasExternalLinkage());
318 LinkFromSrc = true;
319 return false;
320 }
321
322 assert(!Src.hasExternalWeakLinkage());
324 assert(Dest.hasExternalLinkage() && Src.hasExternalLinkage() &&
325 "Unexpected linkage type!");
326 return emitError("Linking globals named '" + Src.getName() +
327 "': symbol multiply defined!");
328}
329
330bool ModuleLinker::linkIfNeeded(GlobalValue &GV,
331 SmallVectorImpl<GlobalValue *> &GVToClone) {
332 GlobalValue *DGV = getLinkedToGlobal(&GV);
333
334 if (shouldLinkOnlyNeeded()) {
335 // Always import variables with appending linkage.
336 if (!GV.hasAppendingLinkage()) {
337 // Don't import globals unless they are referenced by the destination
338 // module.
339 if (!DGV)
340 return false;
341 // Don't import globals that are already defined in the destination module
342 if (!DGV->isDeclaration())
343 return false;
344 }
345 }
346
347 if (DGV && !GV.hasLocalLinkage() && !GV.hasAppendingLinkage()) {
348 auto *DGVar = dyn_cast<GlobalVariable>(DGV);
349 auto *SGVar = dyn_cast<GlobalVariable>(&GV);
350 if (DGVar && SGVar) {
351 if (DGVar->isDeclaration() && SGVar->isDeclaration() &&
352 (!DGVar->isConstant() || !SGVar->isConstant())) {
353 DGVar->setConstant(false);
354 SGVar->setConstant(false);
355 }
356 if (DGVar->hasCommonLinkage() && SGVar->hasCommonLinkage()) {
357 MaybeAlign DAlign = DGVar->getAlign();
358 MaybeAlign SAlign = SGVar->getAlign();
359 MaybeAlign Align = std::nullopt;
360 if (DAlign || SAlign)
361 Align = std::max(DAlign.valueOrOne(), SAlign.valueOrOne());
362
363 SGVar->setAlignment(Align);
364 DGVar->setAlignment(Align);
365 }
366 }
367
370 DGV->setVisibility(Visibility);
371 GV.setVisibility(Visibility);
372
374 DGV->getUnnamedAddr(), GV.getUnnamedAddr());
375 DGV->setUnnamedAddr(UnnamedAddr);
376 GV.setUnnamedAddr(UnnamedAddr);
377 }
378
379 if (!DGV && !shouldOverrideFromSrc() &&
380 (GV.hasLocalLinkage() || GV.hasLinkOnceLinkage() ||
382 return false;
383
384 if (GV.isDeclaration())
385 return false;
386
387 LinkFrom ComdatFrom = LinkFrom::Dst;
388 if (const Comdat *SC = GV.getComdat()) {
389 std::tie(std::ignore, ComdatFrom) = ComdatsChosen[SC];
390 if (ComdatFrom == LinkFrom::Dst)
391 return false;
392 }
393
394 bool LinkFromSrc = true;
395 if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, GV))
396 return true;
397 if (DGV && ComdatFrom == LinkFrom::Both)
398 GVToClone.push_back(LinkFromSrc ? DGV : &GV);
399 if (LinkFromSrc)
400 ValuesToLink.insert(&GV);
401 return false;
402}
403
404void ModuleLinker::addLazyFor(GlobalValue &GV, const IRMover::ValueAdder &Add) {
405 // Add these to the internalize list
407 !shouldLinkOnlyNeeded())
408 return;
409
410 if (InternalizeCallback)
411 Internalize.insert(GV.getName());
412 Add(GV);
413
414 const Comdat *SC = GV.getComdat();
415 if (!SC)
416 return;
417 for (GlobalValue *GV2 : LazyComdatMembers[SC]) {
418 GlobalValue *DGV = getLinkedToGlobal(GV2);
419 bool LinkFromSrc = true;
420 if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, *GV2))
421 return;
422 if (!LinkFromSrc)
423 continue;
424 if (InternalizeCallback)
425 Internalize.insert(GV2->getName());
426 Add(*GV2);
427 }
428}
429
430void ModuleLinker::dropReplacedComdat(
431 GlobalValue &GV, const DenseSet<const Comdat *> &ReplacedDstComdats) {
432 Comdat *C = GV.getComdat();
433 if (!C)
434 return;
435 if (!ReplacedDstComdats.count(C))
436 return;
437 if (GV.use_empty()) {
438 GV.eraseFromParent();
439 return;
440 }
441
442 if (auto *F = dyn_cast<Function>(&GV)) {
443 F->deleteBody();
444 } else if (auto *Var = dyn_cast<GlobalVariable>(&GV)) {
445 Var->setInitializer(nullptr);
446 } else {
447 auto &Alias = cast<GlobalAlias>(GV);
448 Module &M = *Alias.getParent();
449 GlobalValue *Declaration;
450 if (auto *FTy = dyn_cast<FunctionType>(Alias.getValueType())) {
451 Declaration = Function::Create(FTy, GlobalValue::ExternalLinkage, "", &M);
452 } else {
453 Declaration =
454 new GlobalVariable(M, Alias.getValueType(), /*isConstant*/ false,
456 /*Initializer*/ nullptr);
457 }
458 Declaration->takeName(&Alias);
459 Alias.replaceAllUsesWith(Declaration);
460 Alias.eraseFromParent();
461 }
462}
463
464bool ModuleLinker::run() {
465 Module &DstM = Mover.getModule();
466 DenseSet<const Comdat *> ReplacedDstComdats;
467 DenseSet<const Comdat *> NonPrevailingComdats;
468
469 for (const auto &SMEC : SrcM->getComdatSymbolTable()) {
470 const Comdat &C = SMEC.getValue();
471 if (ComdatsChosen.count(&C))
472 continue;
474 LinkFrom From;
475 if (getComdatResult(&C, SK, From))
476 return true;
477 ComdatsChosen[&C] = std::make_pair(SK, From);
478
479 if (From == LinkFrom::Dst)
480 NonPrevailingComdats.insert(&C);
481
482 if (From != LinkFrom::Src)
483 continue;
484
485 Module::ComdatSymTabType &ComdatSymTab = DstM.getComdatSymbolTable();
486 Module::ComdatSymTabType::iterator DstCI = ComdatSymTab.find(C.getName());
487 if (DstCI == ComdatSymTab.end())
488 continue;
489
490 // The source comdat is replacing the dest one.
491 const Comdat *DstC = &DstCI->second;
492 ReplacedDstComdats.insert(DstC);
493 }
494
495 // Alias have to go first, since we are not able to find their comdats
496 // otherwise.
497 for (GlobalAlias &GV : llvm::make_early_inc_range(DstM.aliases()))
498 dropReplacedComdat(GV, ReplacedDstComdats);
499
500 for (GlobalVariable &GV : llvm::make_early_inc_range(DstM.globals()))
501 dropReplacedComdat(GV, ReplacedDstComdats);
502
503 for (Function &GV : llvm::make_early_inc_range(DstM))
504 dropReplacedComdat(GV, ReplacedDstComdats);
505
506 if (!NonPrevailingComdats.empty()) {
507 DenseSet<GlobalObject *> AliasedGlobals;
508 for (auto &GA : SrcM->aliases())
509 if (GlobalObject *GO = GA.getAliaseeObject(); GO && GO->getComdat())
510 AliasedGlobals.insert(GO);
511 for (const Comdat *C : NonPrevailingComdats) {
513 for (GlobalObject *GO : C->getUsers())
514 if (GO->hasPrivateLinkage() && !AliasedGlobals.contains(GO))
515 ToUpdate.push_back(GO);
516 for (GlobalObject *GO : ToUpdate) {
518 GO->setComdat(nullptr);
519 }
520 }
521 }
522
523 for (GlobalVariable &GV : SrcM->globals())
524 if (GV.hasLinkOnceLinkage())
525 if (const Comdat *SC = GV.getComdat())
526 LazyComdatMembers[SC].push_back(&GV);
527
528 for (Function &SF : *SrcM)
529 if (SF.hasLinkOnceLinkage())
530 if (const Comdat *SC = SF.getComdat())
531 LazyComdatMembers[SC].push_back(&SF);
532
533 for (GlobalAlias &GA : SrcM->aliases())
534 if (GA.hasLinkOnceLinkage())
535 if (const Comdat *SC = GA.getComdat())
536 LazyComdatMembers[SC].push_back(&GA);
537
538 // Insert all of the globals in src into the DstM module... without linking
539 // initializers (which could refer to functions not yet mapped over).
541 for (GlobalVariable &GV : SrcM->globals())
542 if (linkIfNeeded(GV, GVToClone))
543 return true;
544
545 for (Function &SF : *SrcM)
546 if (linkIfNeeded(SF, GVToClone))
547 return true;
548
549 for (GlobalAlias &GA : SrcM->aliases())
550 if (linkIfNeeded(GA, GVToClone))
551 return true;
552
553 for (GlobalIFunc &GI : SrcM->ifuncs())
554 if (linkIfNeeded(GI, GVToClone))
555 return true;
556
557 // For a variable in a comdat nodeduplicate, its initializer should be
558 // preserved (its content may be implicitly used by other members) even if
559 // symbol resolution does not pick it. Clone it into an unnamed private
560 // variable.
561 for (GlobalValue *GV : GVToClone) {
562 if (auto *Var = dyn_cast<GlobalVariable>(GV)) {
563 auto *NewVar = new GlobalVariable(*Var->getParent(), Var->getValueType(),
564 Var->isConstant(), Var->getLinkage(),
565 Var->getInitializer());
566 NewVar->copyAttributesFrom(Var);
567 NewVar->setVisibility(GlobalValue::DefaultVisibility);
568 NewVar->setLinkage(GlobalValue::PrivateLinkage);
569 NewVar->setDSOLocal(true);
570 NewVar->setComdat(Var->getComdat());
571 if (Var->getParent() != &Mover.getModule())
572 ValuesToLink.insert(NewVar);
573 } else {
574 emitError("linking '" + GV->getName() +
575 "': non-variables in comdat nodeduplicate are not handled");
576 }
577 }
578
579 for (unsigned I = 0; I < ValuesToLink.size(); ++I) {
580 GlobalValue *GV = ValuesToLink[I];
581 const Comdat *SC = GV->getComdat();
582 if (!SC)
583 continue;
584 for (GlobalValue *GV2 : LazyComdatMembers[SC]) {
585 GlobalValue *DGV = getLinkedToGlobal(GV2);
586 bool LinkFromSrc = true;
587 if (DGV && shouldLinkFromSource(LinkFromSrc, *DGV, *GV2))
588 return true;
589 if (LinkFromSrc)
590 ValuesToLink.insert(GV2);
591 }
592 }
593
594 if (InternalizeCallback) {
595 for (GlobalValue *GV : ValuesToLink)
596 Internalize.insert(GV->getName());
597 }
598
599 // FIXME: Propagate Errors through to the caller instead of emitting
600 // diagnostics.
601 bool HasErrors = false;
602 if (Error E =
603 Mover.move(std::move(SrcM), ValuesToLink.getArrayRef(),
605 [this](GlobalValue &GV, IRMover::ValueAdder Add) {
606 addLazyFor(GV, Add);
607 }),
608 /* IsPerformingImport */ false)) {
609 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
610 DstM.getContext().diagnose(LinkDiagnosticInfo(DS_Error, EIB.message()));
611 HasErrors = true;
612 });
613 }
614 if (HasErrors)
615 return true;
616
617 if (InternalizeCallback)
618 InternalizeCallback(DstM, Internalize);
619
620 return false;
621}
622
623Linker::Linker(Module &M) : Mover(M) {}
624
626 std::unique_ptr<Module> Src, unsigned Flags,
627 std::function<void(Module &, const StringSet<> &)> InternalizeCallback) {
628 ModuleLinker ModLinker(Mover, std::move(Src), Flags,
629 std::move(InternalizeCallback));
630 return ModLinker.run();
631}
632
633//===----------------------------------------------------------------------===//
634// LinkModules entrypoint.
635//===----------------------------------------------------------------------===//
636
637/// This function links two modules together, with the resulting Dest module
638/// modified to be the composite of the two input modules. If an error occurs,
639/// true is returned and ErrorMsg (if not null) is set to indicate the problem.
640/// Upon failure, the Dest module could be in a modified state, and shouldn't be
641/// relied on to be consistent.
643 Module &Dest, std::unique_ptr<Module> Src, unsigned Flags,
644 std::function<void(Module &, const StringSet<> &)> InternalizeCallback) {
645 Linker L(Dest);
646 return L.linkInModule(std::move(Src), Flags, std::move(InternalizeCallback));
647}
648
649//===----------------------------------------------------------------------===//
650// C API.
651//===----------------------------------------------------------------------===//
652
654 Module *D = unwrap(Dest);
655 std::unique_ptr<Module> M(unwrap(Src));
656 return Linker::linkModules(*D, std::move(M));
657}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Module.h This file contains the declarations for the Module class.
static GlobalValue::VisibilityTypes getMinVisibility(GlobalValue::VisibilityTypes A, GlobalValue::VisibilityTypes B)
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Machine Check Debug Module
This file implements a set that has insertion order iteration characteristics.
LLVM_ABI StringRef getName() const
Definition Comdat.cpp:28
SelectionKind getSelectionKind() const
Definition Comdat.h:47
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:174
virtual std::string message() const
Return the error message as a string.
Definition Error.h:52
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition Function.h:166
bool hasLinkOnceLinkage() const
bool hasExternalLinkage() const
VisibilityTypes getVisibility() const
static bool isLocalLinkage(LinkageTypes Linkage)
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition Globals.cpp:329
LinkageTypes getLinkage() const
void setUnnamedAddr(UnnamedAddr Val)
bool hasLocalLinkage() const
LLVM_ABI const Comdat * getComdat() const
Definition Globals.cpp:202
bool hasExternalWeakLinkage() const
bool isDeclarationForLinker() const
static UnnamedAddr getMinUnnamedAddr(UnnamedAddr A, UnnamedAddr B)
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition Globals.cpp:442
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition Globals.cpp:94
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition GlobalValue.h:67
@ DefaultVisibility
The GV is visible.
Definition GlobalValue.h:68
@ HiddenVisibility
The GV is hidden.
Definition GlobalValue.h:69
@ ProtectedVisibility
The GV is protected.
Definition GlobalValue.h:70
void setVisibility(VisibilityTypes V)
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
Definition Globals.cpp:133
bool hasWeakLinkage() const
bool hasCommonLinkage() const
UnnamedAddr getUnnamedAddr() const
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
bool hasAppendingLinkage() const
bool hasAvailableExternallyLinkage() const
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition GlobalValue.h:61
@ ExternalLinkage
Externally visible function.
Definition GlobalValue.h:53
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition GlobalValue.h:54
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
LLVM_ABI uint64_t getGlobalSize(const DataLayout &DL) const
Get the size of this global variable in bytes.
Definition Globals.cpp:561
LLVM_ABI 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:1699
Module & getModule()
Definition IRMover.h:90
std::function< void(GlobalValue &)> ValueAdder
Definition IRMover.h:70
llvm::unique_function< void(GlobalValue &GV, ValueAdder Add)> LazyCallback
Definition IRMover.h:71
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
@ OverrideFromSrc
Have symbols from Src shadow those in the Dest.
Definition Linker.h:30
@ LinkOnlyNeeded
Definition Linker.h:31
LLVM_ABI bool linkInModule(std::unique_ptr< Module > Src, unsigned Flags=Flags::None, std::function< void(Module &, const StringSet<> &)> InternalizeCallback={})
Link Src into the composite.
static LLVM_ABI 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...
LLVM_ABI Linker(Module &M)
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
LLVMContext & getContext() const
Get the global data context.
Definition Module.h:285
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
Definition Module.h:669
iterator_range< alias_iterator > aliases()
Definition Module.h:735
iterator_range< global_iterator > globals()
Definition Module.h:684
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
Definition Module.cpp:177
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition Module.h:278
size_type size() const
Determine the number of elements in the SetVector.
Definition SetVector.h:103
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:151
void push_back(const T &Elt)
iterator end()
Definition StringMap.h:224
iterator find(StringRef Key)
Definition StringMap.h:237
StringMapIterBase< Comdat, false > iterator
Definition StringMap.h:221
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition StringSet.h:25
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition StringSet.h:39
bool use_empty() const
Definition Value.h:346
bool hasName() const
Definition Value.h:262
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:322
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
Definition Value.cpp:403
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:202
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition DenseSet.h:175
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:180
LLVM_C_ABI LLVMBool LLVMLinkModules2(LLVMModuleRef Dest, LLVMModuleRef Src)
int LLVMBool
Definition Types.h:28
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Definition Types.h:61
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
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:990
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:632
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
Attribute unwrap(LLVMAttributeRef Attr)
Definition Attributes.h:392
@ Add
Sum of integers.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1915
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Definition Alignment.h:130