Skip to content

Commit b2e43f3

Browse files
committed
[embedded] Avoid a late VTableSpecializer pass in favor of disabling -O/-Osize passes that break embedded Swift assumptions
1 parent 16f6ca9 commit b2e43f3

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,16 @@ void addFunctionPasses(SILPassPipelinePlan &P,
469469
// makes a change we'll end up restarting the function passes on the
470470
// current function (after optimizing any new callees).
471471
P.addDevirtualizer();
472-
P.addGenericSpecializer();
473-
// Run devirtualizer after the specializer, because many
474-
// class_method/witness_method instructions may use concrete types now.
475-
P.addDevirtualizer();
472+
// MandatoryPerformanceOptimizations already took care of all specializations
473+
// in embedded Swift mode, running the generic specializer might introduce
474+
// more generic calls from non-generic functions, which breaks the assumptions
475+
// of embedded Swift.
476+
if (!P.getOptions().EmbeddedSwift) {
477+
P.addGenericSpecializer();
478+
// Run devirtualizer after the specializer, because many
479+
// class_method/witness_method instructions may use concrete types now.
480+
P.addDevirtualizer();
481+
}
476482
P.addARCSequenceOpts();
477483

478484
if (P.getOptions().EnableOSSAModules) {
@@ -754,8 +760,14 @@ static void addMidLevelFunctionPipeline(SILPassPipelinePlan &P) {
754760
static void addLowLevelPassPipeline(SILPassPipelinePlan &P) {
755761
P.startPipeline("LowLevel,Function", true /*isFunctionPassPipeline*/);
756762

757-
// Should be after FunctionSignatureOpts and before the last inliner.
758-
P.addReleaseDevirtualizer();
763+
// MandatoryPerformanceOptimizations already took care of all specializations
764+
// in embedded Swift mode, running the release devirtualizer might introduce
765+
// more generic calls from non-generic functions, which breaks the assumptions
766+
// of embedded Swift.
767+
if (!P.getOptions().EmbeddedSwift) {
768+
// Should be after FunctionSignatureOpts and before the last inliner.
769+
P.addReleaseDevirtualizer();
770+
}
759771

760772
addFunctionPasses(P, OptimizationLevelKind::LowLevel);
761773

@@ -967,13 +979,6 @@ SILPassPipelinePlan::getPerformancePassPipeline(const SILOptions &Options) {
967979
// Perform optimizations that specialize.
968980
addClosureSpecializePassPipeline(P);
969981

970-
// For embedded Swift: We need to re-run VTableSpecializer in case the
971-
// performance inliner and specializer ended up discovering new generic
972-
// classes.
973-
if (Options.EmbeddedSwift) {
974-
P.addVTableSpecializer();
975-
}
976-
977982
// Run another iteration of the SSA optimizations to optimize the
978983
// devirtualized inline caches and constants propagated into closures
979984
// (CapturePropagation).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-emit-ir -Osize %s -enable-experimental-feature Embedded | %FileCheck %s
2+
3+
public func foo() {
4+
bar([42])
5+
}
6+
7+
func bar(_: UnsafePointer<UInt?>) {
8+
}
9+
10+
// CHECK: define {{.*}}@main(

0 commit comments

Comments
 (0)