Skip to content

Revert "Mandatory SIL linker pass" #15940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions include/swift/SILOptimizer/PassManager/Passes.def
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,6 @@ PASS(LateReleaseHoisting, "late-release-hoisting",
"Late SIL release Hoisting Preserving Epilogues")
IRGEN_PASS(LoadableByAddress, "loadable-address",
"SIL Large Loadable type by-address lowering.")
PASS(MandatorySILLinker, "mandatory-linker",
"Deserialize all referenced SIL functions that are shared or transparent")
PASS(PerformanceSILLinker, "performance-linker",
"Deserialize all referenced SIL functions")
PASS(RemovePins, "remove-pins",
"Remove SIL pin/unpin pairs")
PASS(TempRValueOpt, "temp-rvalue-opt",
Expand All @@ -242,6 +238,8 @@ PASS(SILCombine, "sil-combine",
"Combine SIL Instructions via Peephole Optimization")
PASS(SILDebugInfoGenerator, "sil-debuginfo-gen",
"Generate Debug Information with Source Locations into Textual SIL")
PASS(SILLinker, "linker",
"Link all SIL Referenced within the Module via Deserialization")
PASS(SROA, "sroa",
"Scalar Replacement of Aggregate Stack Objects")
PASS(SROABBArgs, "sroa-bb-args",
Expand Down
16 changes: 1 addition & 15 deletions lib/SIL/Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,7 @@ void SILLinkerVisitor::maybeAddFunctionToWorklist(SILFunction *F) {
if (!F->isExternalDeclaration())
return;

// In the performance pipeline, we deserialize all reachable functions.
if (isLinkAll())
return addFunctionToWorklist(F);

// Otherwise, make sure to deserialize shared functions; we need to
// emit them into the client binary since they're not available
// externally.
if (hasSharedVisibility(F->getLinkage()))
return addFunctionToWorklist(F);

// Functions with PublicNonABI linkage are deserialized as having
// HiddenExternal linkage when they are declarations, then they
// become SharedExternal after the body has been deserialized.
// So try deserializing HiddenExternal functions too.
if (F->getLinkage() == SILLinkage::HiddenExternal)
if (isLinkAll() || hasSharedVisibility(F->getLinkage()))
return addFunctionToWorklist(F);
}

Expand Down
26 changes: 15 additions & 11 deletions lib/SILOptimizer/Mandatory/MandatoryInlining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,22 +404,17 @@ static SILFunction *getCalleeFunction(
return nullptr;
}

// If CalleeFunction is a declaration, see if we can load it. If we fail to
// load it, bail.
if (CalleeFunction->empty()
&& !AI.getModule().linkFunction(CalleeFunction, Mode))
return nullptr;

// If the CalleeFunction is a not-transparent definition, we can not process
// it.
if (CalleeFunction->isTransparent() == IsNotTransparent)
return nullptr;

// If CalleeFunction is a declaration, see if we can load it.
if (CalleeFunction->empty()) {
// FIXME: Remove 'Mode'
if (Mode != SILOptions::LinkingMode::LinkNone)
AI.getModule().loadFunction(CalleeFunction);
}

// If we fail to load it, bail.
if (CalleeFunction->empty())
return nullptr;

if (F->isSerialized() &&
!CalleeFunction->hasValidLinkageForFragileInline()) {
if (!CalleeFunction->hasValidLinkageForFragileRef()) {
Expand Down Expand Up @@ -658,6 +653,15 @@ class MandatoryInlining : public SILModuleTransform {
SetFactory, SetFactory.getEmptySet(), CHA);
}

// Make sure that we de-serialize all transparent functions,
// even if we didn't inline them for some reason.
// Transparent functions are not available externally, so we
// have to generate code for them.
for (auto &F : *M) {
if (F.isTransparent())
M->linkFunction(&F, Mode);
}

if (!ShouldCleanup)
return;

Expand Down
7 changes: 3 additions & 4 deletions lib/SILOptimizer/PassManager/PassPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ static void addMandatoryOptPipeline(SILPassPipelinePlan &P,
P.addDefiniteInitialization();
P.addOwnershipModelEliminator();
P.addMandatoryInlining();
P.addMandatorySILLinker();
P.addPredictableMemoryOptimizations();

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

static void addPerfDebugSerializationPipeline(SILPassPipelinePlan &P) {
P.startPipeline("Performance Debug Serialization");
P.addPerformanceSILLinker();
P.addSILLinker();
}

static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
Expand All @@ -325,7 +324,7 @@ static void addPerfEarlyModulePassPipeline(SILPassPipelinePlan &P) {
// we do not spend time optimizing them.
P.addDeadFunctionElimination();
// Start by cloning functions from stdlib.
P.addPerformanceSILLinker();
P.addSILLinker();

// Cleanup after SILGen: remove trivial copies to temporaries.
P.addTempRValueOpt();
Expand All @@ -345,7 +344,7 @@ static void addHighLevelEarlyLoopOptPipeline(SILPassPipelinePlan &P) {
static void addMidModulePassesStackPromotePassPipeline(SILPassPipelinePlan &P) {
P.startPipeline("MidModulePasses+StackPromote");
P.addDeadFunctionElimination();
P.addPerformanceSILLinker();
P.addSILLinker();
P.addDeadObjectElimination();
P.addGlobalPropertyOpt();

Expand Down
14 changes: 3 additions & 11 deletions lib/SILOptimizer/UtilityPasses/Link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,18 @@ namespace {
/// Copies code from the standard library into the user program to enable
/// optimizations.
class SILLinker : public SILModuleTransform {
SILModule::LinkingMode LinkMode;

public:
explicit SILLinker(SILModule::LinkingMode LinkMode) : LinkMode(LinkMode) {}

void run() override {
SILModule &M = *getModule();
for (auto &Fn : M)
if (M.linkFunction(&Fn, LinkMode))
if (M.linkFunction(&Fn, SILModule::LinkingMode::LinkAll))
invalidateAnalysis(&Fn, SILAnalysis::InvalidationKind::Everything);
}

};
} // end anonymous namespace


SILTransform *swift::createMandatorySILLinker() {
return new SILLinker(SILModule::LinkingMode::LinkNormal);
}

SILTransform *swift::createPerformanceSILLinker() {
return new SILLinker(SILModule::LinkingMode::LinkAll);
SILTransform *swift::createSILLinker() {
return new SILLinker();
}
2 changes: 1 addition & 1 deletion test/SIL/Serialization/deserialize_generic.sil
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

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

// Make sure that SILFunctionType with GenericSignature can match up with
// SILFunctionType deserialized from module.
Expand Down
2 changes: 1 addition & 1 deletion test/SIL/Serialization/deserialize_generic_marker.sil
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

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

// Make sure that SILFunctionType with GenericSignature can match up with
// SILFunctionType deserialized from module.
Expand Down
2 changes: 1 addition & 1 deletion test/SIL/Serialization/function_param_convention.sil
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// 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
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -I %t -performance-linker %s -o - | %FileCheck %s
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -I %t -linker %s -o - | %FileCheck %s

import Swift
import FunctionInput
Expand Down
2 changes: 1 addition & 1 deletion test/SIL/Serialization/public_non_abi.sil
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/def_public_non_abi.sil
// RUN: %target-sil-opt -performance-linker -I %t %s | %FileCheck %s
// RUN: %target-sil-opt -linker -I %t %s | %FileCheck %s

sil_stage raw

Expand Down
2 changes: 1 addition & 1 deletion test/SIL/Serialization/shared_function_serialization.sil
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// 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
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all -I %t -performance-linker -inline %s -o - | %FileCheck %s
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all -I %t -linker -inline %s -o - | %FileCheck %s

// CHECK: sil private @top_level_code
// CHECK: sil public_external [serialized] @$Ss1XVABycfC{{.*}}
Expand Down
5 changes: 2 additions & 3 deletions test/SIL/Serialization/vtable_deserialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ Class.firstMethod()
// The other two methods should not be deserialized in the mandatory
// pipeline.

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

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

// Make sure we deserialized the vtable.
Expand Down