diff --git a/include/llvm/Linker/Linker.h b/include/llvm/Linker/Linker.h index f0c8ad979ab..aa430094294 100644 --- a/include/llvm/Linker/Linker.h +++ b/include/llvm/Linker/Linker.h @@ -99,6 +99,13 @@ private: DiagnosticHandlerFunction DiagnosticHandler; }; +/// Create a new module with exported local functions renamed and promoted +/// for ThinLTO. +std::unique_ptr +renameModuleForThinLTO(std::unique_ptr &M, + const FunctionInfoIndex *Index, + DiagnosticHandlerFunction DiagnosticHandler); + } // End llvm namespace #endif diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 88b8e443c48..627137ba3ab 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -2056,6 +2056,18 @@ bool Linker::linkModules(Module &Dest, Module &Src, return L.linkInModule(Src, Flags); } +std::unique_ptr +llvm::renameModuleForThinLTO(std::unique_ptr &M, + const FunctionInfoIndex *Index, + DiagnosticHandlerFunction DiagnosticHandler) { + std::unique_ptr RenamedModule( + new llvm::Module(M->getModuleIdentifier(), M->getContext())); + Linker L(*RenamedModule.get(), DiagnosticHandler); + if (L.linkInModule(*M.get(), llvm::Linker::Flags::None, Index)) + return nullptr; + return RenamedModule; +} + //===----------------------------------------------------------------------===// // C API. //===----------------------------------------------------------------------===//