Skip to content

Commit 39de8c7

Browse files
authored
Revert "Mandatory SIL linker pass"
1 parent 3124f6a commit 39de8c7

File tree

11 files changed

+31
-53
lines changed

11 files changed

+31
-53
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ PASS(LateReleaseHoisting, "late-release-hoisting",
226226
"Late SIL release Hoisting Preserving Epilogues")
227227
IRGEN_PASS(LoadableByAddress, "loadable-address",
228228
"SIL Large Loadable type by-address lowering.")
229-
PASS(MandatorySILLinker, "mandatory-linker",
230-
"Deserialize all referenced SIL functions that are shared or transparent")
231-
PASS(PerformanceSILLinker, "performance-linker",
232-
"Deserialize all referenced SIL functions")
233229
PASS(RemovePins, "remove-pins",
234230
"Remove SIL pin/unpin pairs")
235231
PASS(TempRValueOpt, "temp-rvalue-opt",
@@ -242,6 +238,8 @@ PASS(SILCombine, "sil-combine",
242238
"Combine SIL Instructions via Peephole Optimization")
243239
PASS(SILDebugInfoGenerator, "sil-debuginfo-gen",
244240
"Generate Debug Information with Source Locations into Textual SIL")
241+
PASS(SILLinker, "linker",
242+
"Link all SIL Referenced within the Module via Deserialization")
245243
PASS(SROA, "sroa",
246244
"Scalar Replacement of Aggregate Stack Objects")
247245
PASS(SROABBArgs, "sroa-bb-args",

lib/SIL/Linker.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,7 @@ void SILLinkerVisitor::maybeAddFunctionToWorklist(SILFunction *F) {
5555
if (!F->isExternalDeclaration())
5656
return;
5757

58-
// In the performance pipeline, we deserialize all reachable functions.
59-
if (isLinkAll())
60-
return addFunctionToWorklist(F);
61-
62-
// Otherwise, make sure to deserialize shared functions; we need to
63-
// emit them into the client binary since they're not available
64-
// externally.
65-
if (hasSharedVisibility(F->getLinkage()))
66-
return addFunctionToWorklist(F);
67-
68-
// Functions with PublicNonABI linkage are deserialized as having
69-
// HiddenExternal linkage when they are declarations, then they
70-
// become SharedExternal after the body has been deserialized.
71-
// So try deserializing HiddenExternal functions too.
72-
if (F->getLinkage() == SILLinkage::HiddenExternal)
58+
if (isLinkAll() || hasSharedVisibility(F->getLinkage()))
7359
return addFunctionToWorklist(F);
7460
}
7561

lib/SILOptimizer/Mandatory/MandatoryInlining.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -404,22 +404,17 @@ static SILFunction *getCalleeFunction(
404404
return nullptr;
405405
}
406406

407+
// If CalleeFunction is a declaration, see if we can load it. If we fail to
408+
// load it, bail.
409+
if (CalleeFunction->empty()
410+
&& !AI.getModule().linkFunction(CalleeFunction, Mode))
411+
return nullptr;
412+
407413
// If the CalleeFunction is a not-transparent definition, we can not process
408414
// it.
409415
if (CalleeFunction->isTransparent() == IsNotTransparent)
410416
return nullptr;
411417

412-
// If CalleeFunction is a declaration, see if we can load it.
413-
if (CalleeFunction->empty()) {
414-
// FIXME: Remove 'Mode'
415-
if (Mode != SILOptions::LinkingMode::LinkNone)
416-
AI.getModule().loadFunction(CalleeFunction);
417-
}
418-
419-
// If we fail to load it, bail.
420-
if (CalleeFunction->empty())
421-
return nullptr;
422-
423418
if (F->isSerialized() &&
424419
!CalleeFunction->hasValidLinkageForFragileInline()) {
425420
if (!CalleeFunction->hasValidLinkageForFragileRef()) {
@@ -658,6 +653,15 @@ class MandatoryInlining : public SILModuleTransform {
658653
SetFactory, SetFactory.getEmptySet(), CHA);
659654
}
660655

656+
// Make sure that we de-serialize all transparent functions,
657+
// even if we didn't inline them for some reason.
658+
// Transparent functions are not available externally, so we
659+
// have to generate code for them.
660+
for (auto &F : *M) {
661+
if (F.isTransparent())
662+
M->linkFunction(&F, Mode);
663+
}
664+
661665
if (!ShouldCleanup)
662666
return;
663667

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ static void addMandatoryOptPipeline(SILPassPipelinePlan &P,
9090
P.addDefiniteInitialization();
9191
P.addOwnershipModelEliminator();
9292
P.addMandatoryInlining();
93-
P.addMandatorySILLinker();
9493
P.addPredictableMemoryOptimizations();
9594

9695
// Diagnostic ConstantPropagation must be rerun on deserialized functions
@@ -315,7 +314,7 @@ void addSSAPasses(SILPassPipelinePlan &P, OptimizationLevelKind OpLevel) {
315314

316315
static void addPerfDebugSerializationPipeline(SILPassPipelinePlan &P) {
317316
P.startPipeline("Performance Debug Serialization");
318-
P.addPerformanceSILLinker();
317+
P.addSILLinker();
319318
}
320319

321320
static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
@@ -325,7 +324,7 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
325324
// we do not spend time optimizing them.
326325
P.addDeadFunctionElimination();
327326
// Start by cloning functions from stdlib.
328-
P.addPerformanceSILLinker();
327+
P.addSILLinker();
329328

330329
// Cleanup after SILGen: remove trivial copies to temporaries.
331330
P.addTempRValueOpt();
@@ -345,7 +344,7 @@ static void addHighLevelEarlyLoopOptPipeline(SILPassPipelinePlan &P) {
345344
static void addMidModulePassesStackPromotePassPipeline(SILPassPipelinePlan &P) {
346345
P.startPipeline("MidModulePasses+StackPromote");
347346
P.addDeadFunctionElimination();
348-
P.addPerformanceSILLinker();
347+
P.addSILLinker();
349348
P.addDeadObjectElimination();
350349
P.addGlobalPropertyOpt();
351350

lib/SILOptimizer/UtilityPasses/Link.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,18 @@ namespace {
2525
/// Copies code from the standard library into the user program to enable
2626
/// optimizations.
2727
class SILLinker : public SILModuleTransform {
28-
SILModule::LinkingMode LinkMode;
29-
30-
public:
31-
explicit SILLinker(SILModule::LinkingMode LinkMode) : LinkMode(LinkMode) {}
3228

3329
void run() override {
3430
SILModule &M = *getModule();
3531
for (auto &Fn : M)
36-
if (M.linkFunction(&Fn, LinkMode))
32+
if (M.linkFunction(&Fn, SILModule::LinkingMode::LinkAll))
3733
invalidateAnalysis(&Fn, SILAnalysis::InvalidationKind::Everything);
3834
}
3935

4036
};
4137
} // end anonymous namespace
4238

4339

44-
SILTransform *swift::createMandatorySILLinker() {
45-
return new SILLinker(SILModule::LinkingMode::LinkNormal);
46-
}
47-
48-
SILTransform *swift::createPerformanceSILLinker() {
49-
return new SILLinker(SILModule::LinkingMode::LinkAll);
40+
SILTransform *swift::createSILLinker() {
41+
return new SILLinker();
5042
}

test/SIL/Serialization/deserialize_generic.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
// RUN: %empty-directory(%t)
33
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/def_generic.swift
4-
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -performance-linker -I %t %s | %FileCheck %s
4+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -linker -I %t %s | %FileCheck %s
55

66
// Make sure that SILFunctionType with GenericSignature can match up with
77
// SILFunctionType deserialized from module.

test/SIL/Serialization/deserialize_generic_marker.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
// RUN: %empty-directory(%t)
33
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/def_generic_marker.swift
4-
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -performance-linker -I %t %s | %FileCheck %s
4+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -linker -I %t %s | %FileCheck %s
55

66
// Make sure that SILFunctionType with GenericSignature can match up with
77
// SILFunctionType deserialized from module.

test/SIL/Serialization/function_param_convention.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -parse-sil -sil-inline-threshold 0 %S/Inputs/function_param_convention_input.sil -o %t/FunctionInput.swiftmodule -emit-module -parse-as-library -parse-stdlib -module-name FunctionInput -O
3-
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -I %t -performance-linker %s -o - | %FileCheck %s
3+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -I %t -linker %s -o - | %FileCheck %s
44

55
import Swift
66
import FunctionInput

test/SIL/Serialization/public_non_abi.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/def_public_non_abi.sil
3-
// RUN: %target-sil-opt -performance-linker -I %t %s | %FileCheck %s
3+
// RUN: %target-sil-opt -linker -I %t %s | %FileCheck %s
44

55
sil_stage raw
66

test/SIL/Serialization/shared_function_serialization.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend %S/Inputs/shared_function_serialization_input.swift -o %t/Swift.swiftmodule -emit-module -parse-as-library -parse-stdlib -module-link-name swiftCore -module-name Swift -O
3-
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all -I %t -performance-linker -inline %s -o - | %FileCheck %s
3+
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all -I %t -linker -inline %s -o - | %FileCheck %s
44

55
// CHECK: sil private @top_level_code
66
// CHECK: sil public_external [serialized] @$Ss1XVABycfC{{.*}}

test/SIL/Serialization/vtable_deserialization.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ Class.firstMethod()
1919
// The other two methods should not be deserialized in the mandatory
2020
// pipeline.
2121

22-
// FIXME: Temporary regression
23-
// CHECK-LABEL: sil public_external [serialized] @$S28vtable_deserialization_input5ClassC12secondMethodyyFZ : $@convention(method) (@thick Class.Type) -> () {
22+
// CHECK-LABEL: sil [serialized] @$S28vtable_deserialization_input5ClassC12secondMethodyyFZ : $@convention(method) (@thick Class.Type) -> (){{$}}
2423
// OPT-LABEL: sil public_external @$S28vtable_deserialization_input5ClassC12secondMethodyyFZ : $@convention(method) (@thick Class.Type) -> () {
2524

26-
// CHECK-LABEL: sil public_external [serialized] @$S28vtable_deserialization_input5ClassC11thirdMethodyyFZ : $@convention(method) (@thick Class.Type) -> () {
25+
// CHECK-LABEL: sil [serialized] @$S28vtable_deserialization_input5ClassC11thirdMethodyyFZ : $@convention(method) (@thick Class.Type) -> (){{$}}
2726
// OPT-LABEL: sil public_external @$S28vtable_deserialization_input5ClassC11thirdMethodyyFZ : $@convention(method) (@thick Class.Type) -> () {
2827

2928
// Make sure we deserialized the vtable.

0 commit comments

Comments
 (0)