From e5a619173274bf2a9033ea1c8b2346f1bee2766b Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Thu, 17 Dec 2015 17:14:09 +0000 Subject: [ThinLTO] Metadata linking for imported functions Summary: Second patch split out from http://reviews.llvm.org/D14752. Maps metadata as a post-pass from each module when importing complete, suturing up final metadata to the temporary metadata left on the imported instructions. This entails saving the mapping from bitcode value id to temporary metadata in the importing pass, and from bitcode value id to final metadata during the metadata linking postpass. Depends on D14825. Reviewers: dexonsmith, joker.eph Subscribers: davidxl, llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D14838 llvm-svn: 255909 --- llvm/lib/Linker/LinkModules.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Linker/LinkModules.cpp') 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 *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 *FunctionsToImport = nullptr) + DenseSet *FunctionsToImport = nullptr, + DenseMap *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 Src, unsigned Flags, const FunctionInfoIndex *Index, - DenseSet *FunctionsToImport) { - ModuleLinker TheLinker(Mover, *Src, Flags, Index, FunctionsToImport); + DenseSet *FunctionsToImport, + DenseMap *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 *ValIDToTempMDMap) { + SetVector ValuesToLink; + if (Mover.move( + Src, ValuesToLink.getArrayRef(), + [this](GlobalValue &GV, IRMover::ValueAdder Add) { assert(false); }, + ValIDToTempMDMap, true)) + return true; + return false; +} + //===----------------------------------------------------------------------===// // LinkModules entrypoint. //===----------------------------------------------------------------------===// -- cgit v1.2.3