From 7f0f3ad816db29dfffd25f642b2f09403e93cab0 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Thu, 1 Dec 2016 05:52:32 +0000 Subject: [PATCH] LTO: Remove ModuleLoader, make loadModuleFromBuffer static and move into its only client, ThinLTOCodeGenerator. This is no longer the recommended way to load modules for importing, so it should not be public API. Differential Revision: https://reviews.llvm.org/D27292 llvm-svn: 288316 --- include/llvm/LTO/LTO.h | 25 ------------------------- lib/LTO/LTO.cpp | 20 -------------------- lib/LTO/ThinLTOCodeGenerator.cpp | 25 ++++++++++++++++++++++++- 3 files changed, 24 insertions(+), 46 deletions(-) diff --git a/include/llvm/LTO/LTO.h b/include/llvm/LTO/LTO.h index 6309632e257..ef152aad33a 100644 --- a/include/llvm/LTO/LTO.h +++ b/include/llvm/LTO/LTO.h @@ -38,31 +38,6 @@ class Module; class Target; class raw_pwrite_stream; -/// Helper to load a module from bitcode. -std::unique_ptr loadModuleFromBuffer(const MemoryBufferRef &Buffer, - LLVMContext &Context, bool Lazy); - -/// Provide a "loader" for the FunctionImporter to access function from other -/// modules. -class ModuleLoader { - /// The context that will be used for importing. - LLVMContext &Context; - - /// Map from Module identifier to MemoryBuffer. Used by clients like the - /// FunctionImported to request loading a Module. - StringMap &ModuleMap; - -public: - ModuleLoader(LLVMContext &Context, StringMap &ModuleMap) - : Context(Context), ModuleMap(ModuleMap) {} - - /// Load a module on demand. - std::unique_ptr operator()(StringRef Identifier) { - return loadModuleFromBuffer(ModuleMap[Identifier], Context, /*Lazy*/ true); - } -}; - - /// Resolve Weak and LinkOnce values in the \p Index. Linkage changes recorded /// in the index and the ThinLTO backends must apply the changes to the Module /// via thinLTOResolveWeakForLinkerModule. diff --git a/lib/LTO/LTO.cpp b/lib/LTO/LTO.cpp index 4256704f906..c8587465e4b 100644 --- a/lib/LTO/LTO.cpp +++ b/lib/LTO/LTO.cpp @@ -99,26 +99,6 @@ static void computeCacheKey( Key = toHex(Hasher.result()); } -// Simple helper to load a module from bitcode -std::unique_ptr -llvm::loadModuleFromBuffer(const MemoryBufferRef &Buffer, LLVMContext &Context, - bool Lazy) { - SMDiagnostic Err; - Expected> ModuleOrErr = - Lazy ? getLazyBitcodeModule(Buffer, Context, - /* ShouldLazyLoadMetadata */ true) - : parseBitcodeFile(Buffer, Context); - if (!ModuleOrErr) { - handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) { - SMDiagnostic Err = SMDiagnostic(Buffer.getBufferIdentifier(), - SourceMgr::DK_Error, EIB.message()); - Err.print("ThinLTO", errs()); - }); - report_fatal_error("Can't load module, abort."); - } - return std::move(ModuleOrErr.get()); -} - static void thinLTOResolveWeakForLinkerGUID( GlobalValueSummaryList &GVSummaryList, GlobalValue::GUID GUID, DenseSet &GlobalInvolvedWithAlias, diff --git a/lib/LTO/ThinLTOCodeGenerator.cpp b/lib/LTO/ThinLTOCodeGenerator.cpp index fdb54ee3eb8..2a75b8bbef7 100644 --- a/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/lib/LTO/ThinLTOCodeGenerator.cpp @@ -162,11 +162,34 @@ static void promoteModule(Module &TheModule, const ModuleSummaryIndex &Index) { report_fatal_error("renameModuleForThinLTO failed"); } +static std::unique_ptr +loadModuleFromBuffer(const MemoryBufferRef &Buffer, LLVMContext &Context, + bool Lazy) { + SMDiagnostic Err; + Expected> ModuleOrErr = + Lazy ? getLazyBitcodeModule(Buffer, Context, + /* ShouldLazyLoadMetadata */ true) + : parseBitcodeFile(Buffer, Context); + if (!ModuleOrErr) { + handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) { + SMDiagnostic Err = SMDiagnostic(Buffer.getBufferIdentifier(), + SourceMgr::DK_Error, EIB.message()); + Err.print("ThinLTO", errs()); + }); + report_fatal_error("Can't load module, abort."); + } + return std::move(ModuleOrErr.get()); +} + static void crossImportIntoModule(Module &TheModule, const ModuleSummaryIndex &Index, StringMap &ModuleMap, const FunctionImporter::ImportMapTy &ImportList) { - ModuleLoader Loader(TheModule.getContext(), ModuleMap); + auto Loader = [&](StringRef Identifier) { + return loadModuleFromBuffer(ModuleMap[Identifier], TheModule.getContext(), + /*Lazy=*/true); + }; + FunctionImporter Importer(Index, Loader); if (!Importer.importFunctions(TheModule, ImportList)) report_fatal_error("importFunctions failed");