[llvm] r288316 - LTO: Remove ModuleLoader, make loadModuleFromBuffer static and move into its only client, ThinLTOCodeGenerator.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 30 21:52:32 PST 2016


Author: pcc
Date: Wed Nov 30 23:52:32 2016
New Revision: 288316

URL: http://llvm.org/viewvc/llvm-project?rev=288316&view=rev
Log:
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

Modified:
    llvm/trunk/include/llvm/LTO/LTO.h
    llvm/trunk/lib/LTO/LTO.cpp
    llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp

Modified: llvm/trunk/include/llvm/LTO/LTO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTO.h?rev=288316&r1=288315&r2=288316&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTO.h (original)
+++ llvm/trunk/include/llvm/LTO/LTO.h Wed Nov 30 23:52:32 2016
@@ -38,31 +38,6 @@ class Module;
 class Target;
 class raw_pwrite_stream;
 
-/// Helper to load a module from bitcode.
-std::unique_ptr<Module> 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<MemoryBufferRef> &ModuleMap;
-
-public:
-  ModuleLoader(LLVMContext &Context, StringMap<MemoryBufferRef> &ModuleMap)
-      : Context(Context), ModuleMap(ModuleMap) {}
-
-  /// Load a module on demand.
-  std::unique_ptr<Module> 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.

Modified: llvm/trunk/lib/LTO/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTO.cpp?rev=288316&r1=288315&r2=288316&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTO.cpp (original)
+++ llvm/trunk/lib/LTO/LTO.cpp Wed Nov 30 23:52:32 2016
@@ -99,26 +99,6 @@ static void computeCacheKey(
   Key = toHex(Hasher.result());
 }
 
-// Simple helper to load a module from bitcode
-std::unique_ptr<Module>
-llvm::loadModuleFromBuffer(const MemoryBufferRef &Buffer, LLVMContext &Context,
-                           bool Lazy) {
-  SMDiagnostic Err;
-  Expected<std::unique_ptr<Module>> 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<GlobalValueSummary *> &GlobalInvolvedWithAlias,

Modified: llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp?rev=288316&r1=288315&r2=288316&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp Wed Nov 30 23:52:32 2016
@@ -162,11 +162,34 @@ static void promoteModule(Module &TheMod
     report_fatal_error("renameModuleForThinLTO failed");
 }
 
+static std::unique_ptr<Module>
+loadModuleFromBuffer(const MemoryBufferRef &Buffer, LLVMContext &Context,
+                     bool Lazy) {
+  SMDiagnostic Err;
+  Expected<std::unique_ptr<Module>> 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<MemoryBufferRef> &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");




More information about the llvm-commits mailing list