llvm.org GIT mirror llvm / 11a8ec6
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288316 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 4 years ago
3 changed file(s) with 24 addition(s) and 46 deletion(s). Raw diff Collapse all Expand all
3636 class Module;
3737 class Target;
3838 class raw_pwrite_stream;
39
40 /// Helper to load a module from bitcode.
41 std::unique_ptr loadModuleFromBuffer(const MemoryBufferRef &Buffer,
42 LLVMContext &Context, bool Lazy);
43
44 /// Provide a "loader" for the FunctionImporter to access function from other
45 /// modules.
46 class ModuleLoader {
47 /// The context that will be used for importing.
48 LLVMContext &Context;
49
50 /// Map from Module identifier to MemoryBuffer. Used by clients like the
51 /// FunctionImported to request loading a Module.
52 StringMap &ModuleMap;
53
54 public:
55 ModuleLoader(LLVMContext &Context, StringMap &ModuleMap)
56 : Context(Context), ModuleMap(ModuleMap) {}
57
58 /// Load a module on demand.
59 std::unique_ptr operator()(StringRef Identifier) {
60 return loadModuleFromBuffer(ModuleMap[Identifier], Context, /*Lazy*/ true);
61 }
62 };
63
6439
6540 /// Resolve Weak and LinkOnce values in the \p Index. Linkage changes recorded
6641 /// in the index and the ThinLTO backends must apply the changes to the Module
9696 }
9797
9898 Key = toHex(Hasher.result());
99 }
100
101 // Simple helper to load a module from bitcode
102 std::unique_ptr
103 llvm::loadModuleFromBuffer(const MemoryBufferRef &Buffer, LLVMContext &Context,
104 bool Lazy) {
105 SMDiagnostic Err;
106 Expected> ModuleOrErr =
107 Lazy ? getLazyBitcodeModule(Buffer, Context,
108 /* ShouldLazyLoadMetadata */ true)
109 : parseBitcodeFile(Buffer, Context);
110 if (!ModuleOrErr) {
111 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
112 SMDiagnostic Err = SMDiagnostic(Buffer.getBufferIdentifier(),
113 SourceMgr::DK_Error, EIB.message());
114 Err.print("ThinLTO", errs());
115 });
116 report_fatal_error("Can't load module, abort.");
117 }
118 return std::move(ModuleOrErr.get());
11999 }
120100
121101 static void thinLTOResolveWeakForLinkerGUID(
161161 report_fatal_error("renameModuleForThinLTO failed");
162162 }
163163
164 static std::unique_ptr
165 loadModuleFromBuffer(const MemoryBufferRef &Buffer, LLVMContext &Context,
166 bool Lazy) {
167 SMDiagnostic Err;
168 Expected> ModuleOrErr =
169 Lazy ? getLazyBitcodeModule(Buffer, Context,
170 /* ShouldLazyLoadMetadata */ true)
171 : parseBitcodeFile(Buffer, Context);
172 if (!ModuleOrErr) {
173 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
174 SMDiagnostic Err = SMDiagnostic(Buffer.getBufferIdentifier(),
175 SourceMgr::DK_Error, EIB.message());
176 Err.print("ThinLTO", errs());
177 });
178 report_fatal_error("Can't load module, abort.");
179 }
180 return std::move(ModuleOrErr.get());
181 }
182
164183 static void
165184 crossImportIntoModule(Module &TheModule, const ModuleSummaryIndex &Index,
166185 StringMap &ModuleMap,
167186 const FunctionImporter::ImportMapTy &ImportList) {
168 ModuleLoader Loader(TheModule.getContext(), ModuleMap);
187 auto Loader = [&](StringRef Identifier) {
188 return loadModuleFromBuffer(ModuleMap[Identifier], TheModule.getContext(),
189 /*Lazy=*/true);
190 };
191
169192 FunctionImporter Importer(Index, Loader);
170193 if (!Importer.importFunctions(TheModule, ImportList))
171194 report_fatal_error("importFunctions failed");