@@ -204,13 +204,8 @@ bool swift::immediate::linkLLVMModules(llvm::Module *Module,
204
204
return !Failed;
205
205
}
206
206
207
- bool swift::immediate::IRGenImportedModules (
208
- CompilerInstance &CI, llvm::Module &Module,
209
- llvm::SmallPtrSetImpl<swift::ModuleDecl *> &ImportedModules,
210
- SmallVectorImpl<llvm::Function *> &InitFns, IRGenOptions &IRGenOpts,
211
- const SILOptions &SILOpts) {
212
- swift::ModuleDecl *M = CI.getMainModule ();
213
-
207
+ bool swift::immediate::autolinkImportedModules (ModuleDecl *M,
208
+ IRGenOptions &IRGenOpts) {
214
209
// Perform autolinking.
215
210
SmallVector<LinkLibrary, 4 > AllLinkLibraries (IRGenOpts.LinkLibraries );
216
211
auto addLinkLibrary = [&](LinkLibrary linkLib) {
@@ -219,63 +214,9 @@ bool swift::immediate::IRGenImportedModules(
219
214
220
215
M->collectLinkLibraries (addLinkLibrary);
221
216
222
- tryLoadLibraries (AllLinkLibraries, CI.getASTContext ().SearchPathOpts ,
223
- CI.getDiags ());
224
-
225
- ImportedModules.insert (M);
226
- if (!CI.hasSourceImport ())
227
- return false ;
228
-
229
- // IRGen the modules this module depends on. This is only really necessary
230
- // for imported source, but that's a very convenient thing to do in -i mode.
231
- // FIXME: Crawling all loaded modules is a hack.
232
- // FIXME: And re-doing SILGen, SIL-linking, SIL diagnostics, and IRGen is
233
- // expensive, because it's not properly being limited to new things right now.
234
- bool hadError = false ;
235
- for (auto &entry : CI.getASTContext ().LoadedModules ) {
236
- swift::ModuleDecl *import = entry.second ;
237
- if (!ImportedModules.insert (import ).second )
238
- continue ;
239
-
240
- std::unique_ptr<SILModule> SILMod = performSILGeneration (import ,
241
- CI.getSILOptions ());
242
- if (runSILDiagnosticPasses (*SILMod)) {
243
- hadError = true ;
244
- break ;
245
- }
246
- runSILLoweringPasses (*SILMod);
247
-
248
- const auto PSPs = CI.getPrimarySpecificPathsForAtMostOnePrimary ();
249
- // FIXME: We shouldn't need to use the global context here, but
250
- // something is persisting across calls to performIRGeneration.
251
- auto SubModule = performIRGeneration (
252
- IRGenOpts, import , std::move (SILMod), import ->getName ().str (), PSPs,
253
- getGlobalLLVMContext (), ArrayRef<std::string>());
254
-
255
- if (CI.getASTContext ().hadError ()) {
256
- hadError = true ;
257
- break ;
258
- }
259
-
260
- if (!linkLLVMModules (&Module, std::move (SubModule)
261
- // TODO: reactivate the linker mode if it is
262
- // supported in llvm again. Otherwise remove the
263
- // commented code completely.
264
- /* , llvm::Linker::DestroySource */ )) {
265
- hadError = true ;
266
- break ;
267
- }
268
-
269
- // FIXME: This is an ugly hack; need to figure out how this should
270
- // actually work.
271
- SmallVector<char , 20 > NameBuf;
272
- StringRef InitFnName = (import ->getName ().str () + " .init" ).toStringRef (NameBuf);
273
- llvm::Function *InitFn = Module.getFunction (InitFnName);
274
- if (InitFn)
275
- InitFns.push_back (InitFn);
276
- }
277
-
278
- return hadError;
217
+ tryLoadLibraries (AllLinkLibraries, M->getASTContext ().SearchPathOpts ,
218
+ M->getASTContext ().Diags );
219
+ return false ;
279
220
}
280
221
281
222
int swift::RunImmediately (CompilerInstance &CI, const ProcessCmdLine &CmdLine,
@@ -330,9 +271,7 @@ int swift::RunImmediately(CompilerInstance &CI, const ProcessCmdLine &CmdLine,
330
271
(*emplaceProcessArgs)(argBuf.data (), CmdLine.size ());
331
272
332
273
SmallVector<llvm::Function*, 8 > InitFns;
333
- llvm::SmallPtrSet<swift::ModuleDecl *, 8 > ImportedModules;
334
- if (IRGenImportedModules (CI, *Module, ImportedModules, InitFns,
335
- IRGenOpts, SILOpts))
274
+ if (autolinkImportedModules (swiftModule, IRGenOpts))
336
275
return -1 ;
337
276
338
277
llvm::PassManagerBuilder PMBuilder;
0 commit comments