[ThinLTO] Helper for performing renaming/promotion on a module
Creates a module and performs necessary renaming/promotion of locals
that may be exported to another module.
Split out of D15024.
llvm-svn: 254802
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index 88b8e44..627137b 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -2056,6 +2056,18 @@
return L.linkInModule(Src, Flags);
}
+std::unique_ptr<Module>
+llvm::renameModuleForThinLTO(std::unique_ptr<Module> &M,
+ const FunctionInfoIndex *Index,
+ DiagnosticHandlerFunction DiagnosticHandler) {
+ std::unique_ptr<llvm::Module> 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.
//===----------------------------------------------------------------------===//