Skip to content

Commit dac43b4

Browse files
committedDec 1, 2016
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
1 parent cf2750a commit dac43b4

File tree

3 files changed

+24
-46
lines changed

3 files changed

+24
-46
lines changed
 

‎llvm/include/llvm/LTO/LTO.h

-25
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,6 @@ class Module;
3838
class Target;
3939
class raw_pwrite_stream;
4040

41-
/// Helper to load a module from bitcode.
42-
std::unique_ptr<Module> loadModuleFromBuffer(const MemoryBufferRef &Buffer,
43-
LLVMContext &Context, bool Lazy);
44-
45-
/// Provide a "loader" for the FunctionImporter to access function from other
46-
/// modules.
47-
class ModuleLoader {
48-
/// The context that will be used for importing.
49-
LLVMContext &Context;
50-
51-
/// Map from Module identifier to MemoryBuffer. Used by clients like the
52-
/// FunctionImported to request loading a Module.
53-
StringMap<MemoryBufferRef> &ModuleMap;
54-
55-
public:
56-
ModuleLoader(LLVMContext &Context, StringMap<MemoryBufferRef> &ModuleMap)
57-
: Context(Context), ModuleMap(ModuleMap) {}
58-
59-
/// Load a module on demand.
60-
std::unique_ptr<Module> operator()(StringRef Identifier) {
61-
return loadModuleFromBuffer(ModuleMap[Identifier], Context, /*Lazy*/ true);
62-
}
63-
};
64-
65-
6641
/// Resolve Weak and LinkOnce values in the \p Index. Linkage changes recorded
6742
/// in the index and the ThinLTO backends must apply the changes to the Module
6843
/// via thinLTOResolveWeakForLinkerModule.

‎llvm/lib/LTO/LTO.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,6 @@ static void computeCacheKey(
9999
Key = toHex(Hasher.result());
100100
}
101101

102-
// Simple helper to load a module from bitcode
103-
std::unique_ptr<Module>
104-
llvm::loadModuleFromBuffer(const MemoryBufferRef &Buffer, LLVMContext &Context,
105-
bool Lazy) {
106-
SMDiagnostic Err;
107-
Expected<std::unique_ptr<Module>> ModuleOrErr =
108-
Lazy ? getLazyBitcodeModule(Buffer, Context,
109-
/* ShouldLazyLoadMetadata */ true)
110-
: parseBitcodeFile(Buffer, Context);
111-
if (!ModuleOrErr) {
112-
handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
113-
SMDiagnostic Err = SMDiagnostic(Buffer.getBufferIdentifier(),
114-
SourceMgr::DK_Error, EIB.message());
115-
Err.print("ThinLTO", errs());
116-
});
117-
report_fatal_error("Can't load module, abort.");
118-
}
119-
return std::move(ModuleOrErr.get());
120-
}
121-
122102
static void thinLTOResolveWeakForLinkerGUID(
123103
GlobalValueSummaryList &GVSummaryList, GlobalValue::GUID GUID,
124104
DenseSet<GlobalValueSummary *> &GlobalInvolvedWithAlias,

‎llvm/lib/LTO/ThinLTOCodeGenerator.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,34 @@ static void promoteModule(Module &TheModule, const ModuleSummaryIndex &Index) {
162162
report_fatal_error("renameModuleForThinLTO failed");
163163
}
164164

165+
static std::unique_ptr<Module>
166+
loadModuleFromBuffer(const MemoryBufferRef &Buffer, LLVMContext &Context,
167+
bool Lazy) {
168+
SMDiagnostic Err;
169+
Expected<std::unique_ptr<Module>> ModuleOrErr =
170+
Lazy ? getLazyBitcodeModule(Buffer, Context,
171+
/* ShouldLazyLoadMetadata */ true)
172+
: parseBitcodeFile(Buffer, Context);
173+
if (!ModuleOrErr) {
174+
handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
175+
SMDiagnostic Err = SMDiagnostic(Buffer.getBufferIdentifier(),
176+
SourceMgr::DK_Error, EIB.message());
177+
Err.print("ThinLTO", errs());
178+
});
179+
report_fatal_error("Can't load module, abort.");
180+
}
181+
return std::move(ModuleOrErr.get());
182+
}
183+
165184
static void
166185
crossImportIntoModule(Module &TheModule, const ModuleSummaryIndex &Index,
167186
StringMap<MemoryBufferRef> &ModuleMap,
168187
const FunctionImporter::ImportMapTy &ImportList) {
169-
ModuleLoader Loader(TheModule.getContext(), ModuleMap);
188+
auto Loader = [&](StringRef Identifier) {
189+
return loadModuleFromBuffer(ModuleMap[Identifier], TheModule.getContext(),
190+
/*Lazy=*/true);
191+
};
192+
170193
FunctionImporter Importer(Index, Loader);
171194
if (!Importer.importFunctions(TheModule, ImportList))
172195
report_fatal_error("importFunctions failed");

0 commit comments

Comments
 (0)
Please sign in to comment.