[ThinLTO] Helper for performing renaming/promotion on a module
authorTeresa Johnson <tejohnson@google.com>
Fri, 4 Dec 2015 23:40:22 +0000 (23:40 +0000)
committerTeresa Johnson <tejohnson@google.com>
Fri, 4 Dec 2015 23:40:22 +0000 (23:40 +0000)
Creates a module and performs necessary renaming/promotion of locals
that may be exported to another module.

Split out of D15024.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254802 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Linker/Linker.h
lib/Linker/LinkModules.cpp

index f0c8ad979ab68e36de4f8f1cb91d160c4c5358de..aa4300942947b133db7a9ea98d27aeae4e966a57 100644 (file)
@@ -99,6 +99,13 @@ private:
   DiagnosticHandlerFunction DiagnosticHandler;
 };
 
+/// Create a new module with exported local functions renamed and promoted
+/// for ThinLTO.
+std::unique_ptr<Module>
+renameModuleForThinLTO(std::unique_ptr<Module> &M,
+                       const FunctionInfoIndex *Index,
+                       DiagnosticHandlerFunction DiagnosticHandler);
+
 } // End llvm namespace
 
 #endif
index 88b8e443c48930ad7c910ee67ef0a135edfd5a42..627137ba3abd82d2bad35a10bee2ea79f7a3d03c 100644 (file)
@@ -2056,6 +2056,18 @@ bool Linker::linkModules(Module &Dest, Module &Src,
   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.
 //===----------------------------------------------------------------------===//