[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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254802 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Teresa Johnson 2015-12-04 23:40:22 +00:00
parent 2174f151dc
commit 5143703795
2 changed files with 19 additions and 0 deletions

View 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

View 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.
//===----------------------------------------------------------------------===//