Skip to content

Commit 4fd4593

Browse files
committed
[sil-optimizer] At -Onone serialize when running the Onone optimization pipeline instead of after running SIL passes.
NOTE: This is not in the mandatory passes (which run before this). This will enable me to strip out ownership after we serialize without touching frontend code. It also makes Onone and O use the same code paths for serialization instead of one happening in the driver (Onone today) and the other in a SIL pass (-O, -Osize). The reason that I updated the sil-func-extractor test is that I found a bug in how we emit sib files, namely if you try to emit a sib file to stdout, the llvm-bcanalyzer flags it as malformed. If I output the .sib into a file rather than trying to use stdout, everything works.
1 parent 9c04037 commit 4fd4593

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,11 +1248,7 @@ static bool performCompileStepsPostSILGen(
12481248
return serializeSIB(SM.get(), PSPs, Instance.getASTContext(), MSF);
12491249

12501250
{
1251-
const bool haveModulePath = PSPs.haveModuleOrModuleDocOutputPaths();
1252-
if (haveModulePath && !SM->isSerialized())
1253-
SM->serialize();
1254-
1255-
if (haveModulePath) {
1251+
if (PSPs.haveModuleOrModuleDocOutputPaths()) {
12561252
if (Action == FrontendOptions::ActionType::MergeModules ||
12571253
Action == FrontendOptions::ActionType::EmitModuleOnly) {
12581254
// What if MSF is a module?

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,9 @@ SILPassPipelinePlan SILPassPipelinePlan::getOnonePassPipeline() {
635635
// Has only an effect if the -gsil option is specified.
636636
P.addSILDebugInfoGenerator();
637637

638+
// Finally serialize the SIL if we are asked to.
639+
P.addSerializeSILPass();
640+
638641
return P;
639642
}
640643

lib/SILOptimizer/UtilityPasses/SerializeSILPass.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ class SerializeSILPass : public SILModuleTransform {
5151
// to avoid linker errors, the object file of the current module should
5252
// contain all the symbols which were alive at the time of serialization.
5353
LLVM_DEBUG(llvm::dbgs() << "Serializing SILModule in SerializeSILPass\n");
54-
getModule()->serialize();
54+
M.serialize();
55+
56+
// If we are not optimizing, do not strip the [serialized] flag. We *could*
57+
// do this since after serializing [serialized] is irrelevent. But this
58+
// would incur an unnecessary compile time cost since if we are not
59+
// optimizing we are not going to perform any sort of DFE.
60+
if (!getOptions().shouldOptimize())
61+
return;
5562
removeSerializedFlagFromAllFunctions(M);
5663
}
5764
};

test/sil-func-extractor/basic.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
// Passing demangled name
22

3-
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o - | %target-sil-func-extractor -module-name basic -func="basic.foo" | %FileCheck %s -check-prefix=EXTRACT-FOO
4-
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o - | %target-sil-func-extractor -module-name basic -func="basic.X.test" | %FileCheck %s -check-prefix=EXTRACT-TEST
5-
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o - | %target-sil-func-extractor -module-name basic -func="basic.Vehicle.init" | %FileCheck %s -check-prefix=EXTRACT-INIT
6-
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o - | %target-sil-func-extractor -module-name basic -func="basic.Vehicle.now" | %FileCheck %s -check-prefix=EXTRACT-NOW
3+
// RUN: %empty-directory(%t)
4+
5+
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o %t/demangle-ext-foo.sib; %target-sil-func-extractor -module-name basic -func="basic.foo" %t/demangle-ext-foo.sib | %FileCheck %s -check-prefix=EXTRACT-FOO
6+
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o %t/demangle-ext-test.sib; %target-sil-func-extractor -module-name basic -func="basic.X.test" %t/demangle-ext-test.sib | %FileCheck %s -check-prefix=EXTRACT-TEST
7+
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o %t/demangle-ext-init.sib; %target-sil-func-extractor -module-name basic -func="basic.Vehicle.init" %t/demangle-ext-init.sib | %FileCheck %s -check-prefix=EXTRACT-INIT
8+
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o %t/demangle-ext-now.sib; %target-sil-func-extractor -module-name basic -func="basic.Vehicle.now" %t/demangle-ext-now.sib | %FileCheck %s -check-prefix=EXTRACT-NOW
79

810
// Passing mangled name
911

10-
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o - | %target-sil-func-extractor -module-name basic -func='$s5basic3fooSiyF' | %FileCheck %s -check-prefix=EXTRACT-FOO
11-
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o - | %target-sil-func-extractor -module-name basic -func='$s5basic1XV4testyyF' | %FileCheck %s -check-prefix=EXTRACT-TEST
12-
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o - | %target-sil-func-extractor -module-name basic -func='$s5basic7VehicleC1nACSi_tcfc' | %FileCheck %s -check-prefix=EXTRACT-INIT
13-
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o - | %target-sil-func-extractor -module-name basic -func='$s5basic7VehicleC3nowSiyF' | %FileCheck %s -check-prefix=EXTRACT-NOW
12+
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o %t/mangle-ext-foo.sib; %target-sil-func-extractor -module-name basic -func='$s5basic3fooSiyF' %t/mangle-ext-foo.sib | %FileCheck %s -check-prefix=EXTRACT-FOO
13+
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o %t/mangle-ext-test.sib; %target-sil-func-extractor -module-name basic -func='$s5basic1XV4testyyF' %t/mangle-ext-test.sib | %FileCheck %s -check-prefix=EXTRACT-TEST
14+
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o %t/mangle-ext-init.sib; %target-sil-func-extractor -module-name basic -func='$s5basic7VehicleC1nACSi_tcfc' %t/mangle-ext-init.sib | %FileCheck %s -check-prefix=EXTRACT-INIT
15+
// RUN: %target-swift-frontend %s -g -module-name basic -emit-sib -o %t/mangle-ext-now.sib; %target-sil-func-extractor -module-name basic -func='$s5basic7VehicleC3nowSiyF' %t/mangle-ext-now.sib | %FileCheck %s -check-prefix=EXTRACT-NOW
1416

1517

1618
// EXTRACT-FOO-NOT: sil hidden @$s5basic1XV4testyyF : $@convention(method) (X) -> () {

0 commit comments

Comments
 (0)