diff options
Diffstat (limited to 'llvm/lib/Linker/LinkModules.cpp')
-rw-r--r-- | llvm/lib/Linker/LinkModules.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index 9c9c0ef321f..556251092a2 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/lib/Linker/LinkModules.cpp @@ -48,6 +48,11 @@ class ModuleLinker { /// as part of a different backend compilation process. bool HasExportedFunctions = false; + /// Association between metadata value id and temporary metadata that + /// remains unmapped after function importing. Saved during function + /// importing and consumed during the metadata linking postpass. + DenseMap<unsigned, MDNode *> *ValIDToTempMDMap; + /// Used as the callback for lazy linking. /// The mover has just hit GV and we have to decide if it, and other members /// of the same comdat, should be linked. Every member to be linked is passed @@ -150,9 +155,10 @@ class ModuleLinker { public: ModuleLinker(IRMover &Mover, Module &SrcM, unsigned Flags, const FunctionInfoIndex *Index = nullptr, - DenseSet<const GlobalValue *> *FunctionsToImport = nullptr) + DenseSet<const GlobalValue *> *FunctionsToImport = nullptr, + DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr) : Mover(Mover), SrcM(SrcM), Flags(Flags), ImportIndex(Index), - ImportFunction(FunctionsToImport) { + ImportFunction(FunctionsToImport), ValIDToTempMDMap(ValIDToTempMDMap) { assert((ImportIndex || !ImportFunction) && "Expect a FunctionInfoIndex when importing"); // If we have a FunctionInfoIndex but no function to import, @@ -161,6 +167,8 @@ public: // may be exported to another backend compilation. if (ImportIndex && !ImportFunction) HasExportedFunctions = ImportIndex->hasExportedFunctions(SrcM); + assert((ValIDToTempMDMap || !ImportFunction) && + "Function importing must provide a ValIDToTempMDMap"); } bool run(); @@ -502,6 +510,7 @@ bool ModuleLinker::getComdatResult(const Comdat *SrcC, bool ModuleLinker::shouldLinkFromSource(bool &LinkFromSrc, const GlobalValue &Dest, const GlobalValue &Src) { + // Should we unconditionally use the Src? if (shouldOverrideFromSrc()) { LinkFromSrc = true; @@ -776,7 +785,8 @@ bool ModuleLinker::run() { if (Mover.move(SrcM, ValuesToLink.getArrayRef(), [this](GlobalValue &GV, IRMover::ValueAdder Add) { addLazyFor(GV, Add); - })) + }, + ValIDToTempMDMap, false)) return true; Module &DstM = Mover.getModule(); for (auto &P : Internalize) { @@ -791,8 +801,10 @@ Linker::Linker(Module &M) : Mover(M) {} bool Linker::linkInModule(std::unique_ptr<Module> Src, unsigned Flags, const FunctionInfoIndex *Index, - DenseSet<const GlobalValue *> *FunctionsToImport) { - ModuleLinker TheLinker(Mover, *Src, Flags, Index, FunctionsToImport); + DenseSet<const GlobalValue *> *FunctionsToImport, + DenseMap<unsigned, MDNode *> *ValIDToTempMDMap) { + ModuleLinker TheLinker(Mover, *Src, Flags, Index, FunctionsToImport, + ValIDToTempMDMap); return TheLinker.run(); } @@ -801,6 +813,17 @@ bool Linker::linkInModuleForCAPI(Module &Src) { return TheLinker.run(); } +bool Linker::linkInMetadata(Module &Src, + DenseMap<unsigned, MDNode *> *ValIDToTempMDMap) { + SetVector<GlobalValue *> ValuesToLink; + if (Mover.move( + Src, ValuesToLink.getArrayRef(), + [this](GlobalValue &GV, IRMover::ValueAdder Add) { assert(false); }, + ValIDToTempMDMap, true)) + return true; + return false; +} + //===----------------------------------------------------------------------===// // LinkModules entrypoint. //===----------------------------------------------------------------------===// |