@@ -307,6 +307,10 @@ static bool buildSwiftModuleFromSwiftInterface(
307
307
return ;
308
308
}
309
309
310
+ // Optimize emitted modules. This has to happen after we parse arguments,
311
+ // because parseSILOpts would override the current optimization mode.
312
+ SubInvocation.getSILOptions ().OptMode = OptimizationMode::ForSpeed;
313
+
310
314
// Build the .swiftmodule; this is a _very_ abridged version of the logic in
311
315
// performCompile in libFrontendTool, specialized, to just the one
312
316
// module-serialization task we're trying to do here.
@@ -334,17 +338,14 @@ static bool buildSwiftModuleFromSwiftInterface(
334
338
SILOptions &SILOpts = SubInvocation.getSILOptions ();
335
339
auto Mod = SubInstance.getMainModule ();
336
340
auto SILMod = performSILGeneration (Mod, SILOpts);
337
- if (SILMod) {
338
- LLVM_DEBUG (llvm::dbgs () << " Running SIL diagnostic passes\n " );
339
- if (runSILDiagnosticPasses (*SILMod)) {
340
- LLVM_DEBUG (llvm::dbgs () << " encountered errors\n " );
341
- SubError = true ;
342
- return ;
343
- }
344
- SILMod->verify ();
341
+ if (!SILMod) {
342
+ LLVM_DEBUG (llvm::dbgs () << " SILGen did not produce a module\n " );
343
+ SubError = true ;
344
+ return ;
345
345
}
346
346
347
- LLVM_DEBUG (llvm::dbgs () << " Serializing " << OutPath << " \n " );
347
+ // Setup the callbacks for serialization, which can occur during the
348
+ // optimization pipeline.
348
349
FrontendOptions &FEOpts = SubInvocation.getFrontendOptions ();
349
350
SerializationOptions SerializationOpts;
350
351
std::string OutPathStr = OutPath;
@@ -359,9 +360,16 @@ static bool buildSwiftModuleFromSwiftInterface(
359
360
}
360
361
SerializationOpts.Dependencies = Deps;
361
362
SILMod->setSerializeSILAction ([&]() {
362
- serialize (Mod, SerializationOpts, SILMod.get ());
363
- });
364
- SILMod->serialize ();
363
+ serialize (Mod, SerializationOpts, SILMod.get ());
364
+ });
365
+
366
+ LLVM_DEBUG (llvm::dbgs () << " Running SIL processing passes\n " );
367
+ if (SubInstance.performSILProcessing (SILMod.get ())) {
368
+ LLVM_DEBUG (llvm::dbgs () << " encountered errors\n " );
369
+ SubError = true ;
370
+ return ;
371
+ }
372
+
365
373
SubError = Diags.hadAnyError ();
366
374
});
367
375
return !RunSuccess || SubError;
0 commit comments