Skip to content

Commit 95a17b5

Browse files
author
Harlan Haskins
committed
[ParseableInterface] Optimize parseable modules
This turns on optimization for speed for modules compiled from interfaces during module loading.
1 parent f5cf517 commit 95a17b5

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

lib/Frontend/ParseableInterfaceSupport.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ static bool buildSwiftModuleFromSwiftInterface(
307307
return;
308308
}
309309

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+
310314
// Build the .swiftmodule; this is a _very_ abridged version of the logic in
311315
// performCompile in libFrontendTool, specialized, to just the one
312316
// module-serialization task we're trying to do here.
@@ -334,17 +338,14 @@ static bool buildSwiftModuleFromSwiftInterface(
334338
SILOptions &SILOpts = SubInvocation.getSILOptions();
335339
auto Mod = SubInstance.getMainModule();
336340
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;
345345
}
346346

347-
LLVM_DEBUG(llvm::dbgs() << "Serializing " << OutPath << "\n");
347+
// Setup the callbacks for serialization, which can occur during the
348+
// optimization pipeline.
348349
FrontendOptions &FEOpts = SubInvocation.getFrontendOptions();
349350
SerializationOptions SerializationOpts;
350351
std::string OutPathStr = OutPath;
@@ -359,9 +360,16 @@ static bool buildSwiftModuleFromSwiftInterface(
359360
}
360361
SerializationOpts.Dependencies = Deps;
361362
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+
365373
SubError = Diags.hadAnyError();
366374
});
367375
return !RunSuccess || SubError;

test/ParseableInterface/ModuleCache/module-cache-init.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
// RUN: llvm-bcanalyzer -dump %t/modulecache/LeafModule-*.swiftmodule | %FileCheck %s -check-prefix=CHECK-LEAFMODULE
2626
// CHECK-LEAFMODULE: {{MODULE_NAME.*blob data = 'LeafModule'}}
2727
// CHECK-LEAFMODULE: {{FILE_DEPENDENCY.*Swift.swiftmodule'}}
28-
// CHECK-LEAFMODULE: {{FILE_DEPENDENCY.*SwiftOnoneSupport.swiftmodule'}}
2928
// CHECK-LEAFMODULE: {{FILE_DEPENDENCY.*LeafModule.swiftinterface'}}
3029
// CHECK-LEAFMODULE: FUNC_DECL
3130
//
@@ -39,7 +38,6 @@
3938
// RUN: llvm-bcanalyzer -dump %t/modulecache/OtherModule-*.swiftmodule | %FileCheck %s -check-prefix=CHECK-OTHERMODULE
4039
// CHECK-OTHERMODULE: {{MODULE_NAME.*blob data = 'OtherModule'}}
4140
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*Swift.swiftmodule'}}
42-
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*SwiftOnoneSupport.swiftmodule'}}
4341
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*LeafModule.swiftinterface'}}
4442
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*LeafModule-.*.swiftmodule'}}
4543
// CHECK-OTHERMODULE: {{FILE_DEPENDENCY.*OtherModule.swiftinterface'}}

0 commit comments

Comments
 (0)