Skip to content

Commit ee2924f

Browse files
committed
Inliner: don't distinguish between the "mid-level" and "late" inliner
Now that we handle inlined global initializers in LICM, CSE and the StringOptimization, we don't need to have a separate mid-level inliner pass, which treats global accessors specially.
1 parent 19b828b commit ee2924f

File tree

9 files changed

+19
-39
lines changed

9 files changed

+19
-39
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ PASS(OnonePrespecializations, "onone-prespecializer",
210210
"Pre specialization via @_specialize")
211211
PASS(EarlyCodeMotion, "early-codemotion",
212212
"Early Code Motion without Release Hoisting")
213-
PASS(EarlyInliner, "early-inline",
213+
PASS(EarlyPerfInliner, "early-inline",
214214
"Early Inlining Preserving Semantic Functions")
215215
PASS(EmitDFDiagnostics, "dataflow-diagnostics",
216216
"Emit SIL Diagnostics")
@@ -283,8 +283,6 @@ PASS(LateCodeMotion, "late-codemotion",
283283
"Late Code Motion with Release Hoisting")
284284
PASS(LateDeadFunctionAndGlobalElimination, "late-deadfuncelim",
285285
"Late Dead Function and Global Elimination")
286-
PASS(LateInliner, "late-inline",
287-
"Late Function Inlining")
288286
PASS(LoopCanonicalizer, "loop-canonicalizer",
289287
"Loop Canonicalization")
290288
PASS(LoopInfoPrinter, "loop-info-printer",

include/swift/SILOptimizer/Utils/PerformanceInlinerUtils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ class BasicCalleeAnalysis;
3434
// global_init attributes.
3535
enum class InlineSelection {
3636
Everything,
37-
NoGlobalInit, // and no availability semantics calls
38-
NoSemanticsAndGlobalInit,
37+
NoSemanticsAndEffects,
3938
OnlyInlineAlways,
4039
};
4140

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,17 +485,13 @@ void addFunctionPasses(SILPassPipelinePlan &P,
485485

486486
switch (OpLevel) {
487487
case OptimizationLevelKind::HighLevel:
488-
// Does not inline functions with defined semantics.
489-
P.addEarlyInliner();
488+
// Does not inline functions with defined semantics or effects.
489+
P.addEarlyPerfInliner();
490490
break;
491491
case OptimizationLevelKind::MidLevel:
492-
// Does inline semantics-functions (except "availability"), but not
493-
// global-init functions.
494-
P.addPerfInliner();
495-
break;
496492
case OptimizationLevelKind::LowLevel:
497493
// Inlines everything
498-
P.addLateInliner();
494+
P.addPerfInliner();
499495
break;
500496
}
501497

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ bool SILPerformanceInliner::isProfitableToInline(
360360
// Bail out if this is a generic call of a `@_specialize(exported:)` function
361361
// and we are in the early inliner. We want to give the generic specializer
362362
// the opportunity to see specialized call sites.
363-
if (IsGeneric && WhatToInline == InlineSelection::NoSemanticsAndGlobalInit &&
363+
if (IsGeneric && WhatToInline == InlineSelection::NoSemanticsAndEffects &&
364364
Callee->hasPrespecialization()) {
365365
return false;
366366
}
@@ -1141,9 +1141,7 @@ class SILPerformanceInlinerPass : public SILFunctionTransform {
11411141

11421142
public:
11431143
SILPerformanceInlinerPass(InlineSelection WhatToInline, StringRef LevelName):
1144-
WhatToInline(WhatToInline), PassName(LevelName) {
1145-
PassName.append(" Performance Inliner");
1146-
}
1144+
WhatToInline(WhatToInline), PassName(LevelName) {}
11471145

11481146
void run() override {
11491147
DominanceAnalysis *DA = PM->getAnalysis<DominanceAnalysis>();
@@ -1180,24 +1178,19 @@ class SILPerformanceInlinerPass : public SILFunctionTransform {
11801178

11811179
SILTransform *swift::createAlwaysInlineInliner() {
11821180
return new SILPerformanceInlinerPass(InlineSelection::OnlyInlineAlways,
1183-
"InlineAlways");
1181+
"InlineAlways Performance Inliner");
11841182
}
11851183

11861184
/// Create an inliner pass that does not inline functions that are marked with
1187-
/// the @_semantics, @_effects or global_init attributes.
1188-
SILTransform *swift::createEarlyInliner() {
1185+
/// the @_semantics or @_effects attributes.
1186+
SILTransform *swift::createEarlyPerfInliner() {
11891187
return new SILPerformanceInlinerPass(
1190-
InlineSelection::NoSemanticsAndGlobalInit, "Early");
1191-
}
1192-
1193-
/// Create an inliner pass that does not inline functions that are marked with
1194-
/// the global_init attribute or have an "availability" semantics attribute.
1195-
SILTransform *swift::createPerfInliner() {
1196-
return new SILPerformanceInlinerPass(InlineSelection::NoGlobalInit, "Middle");
1188+
InlineSelection::NoSemanticsAndEffects, "Early Performance Inliner");
11971189
}
11981190

11991191
/// Create an inliner pass that inlines all functions that are marked with
12001192
/// the @_semantics, @_effects or global_init attributes.
1201-
SILTransform *swift::createLateInliner() {
1202-
return new SILPerformanceInlinerPass(InlineSelection::Everything, "Late");
1193+
SILTransform *swift::createPerfInliner() {
1194+
return new SILPerformanceInlinerPass(
1195+
InlineSelection::Everything, "Performance Inliner");
12031196
}

lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ SILFunction *swift::getEligibleFunction(FullApplySite AI,
753753
// Don't inline functions that are marked with the @_semantics or @_effects
754754
// attribute if the inliner is asked not to inline them.
755755
if (Callee->hasSemanticsAttrs() || Callee->hasEffectsKind()) {
756-
if (WhatToInline >= InlineSelection::NoSemanticsAndGlobalInit) {
756+
if (WhatToInline >= InlineSelection::NoSemanticsAndEffects) {
757757
// TODO: for stable optimization of semantics, prevent inlining whenever
758758
// isOptimizableSemanticFunction(Callee) is true.
759759
if (getSemanticFunctionLevel(Callee) == SemanticFunctionLevel::Fundamental
@@ -776,11 +776,6 @@ SILFunction *swift::getEligibleFunction(FullApplySite AI,
776776
return nullptr;
777777
}
778778
}
779-
780-
} else if (Callee->isGlobalInit()) {
781-
if (WhatToInline != InlineSelection::Everything) {
782-
return nullptr;
783-
}
784779
}
785780

786781
// We can't inline external declarations.

test/SILOptimizer/cast_folding.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %target-swift-frontend -O -emit-sil %s | %FileCheck %s
2-
// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xllvm -sil-disable-pass=PerfInliner -O -emit-sil %s | %FileCheck %s
32

43
// We want to check two things here:
54
// - Correctness

test/SILOptimizer/cast_folding_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -O -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xllvm -sil-disable-pass=PerfInliner -emit-sil %s | %FileCheck %s
1+
// RUN: %target-swift-frontend -O -Xllvm -sil-disable-pass=FunctionSignatureOpts -emit-sil %s | %FileCheck %s
22

33
// We want to check two things here:
44
// - Correctness

test/SILOptimizer/inline_late.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-sil-opt -enable-sil-verify-all %s -early-inline -sil-inline-threshold=50 | %FileCheck %s
2-
// RUN: %target-sil-opt -enable-sil-verify-all %s -late-inline -sil-inline-threshold=50 | %FileCheck %s --check-prefix=LATE
3-
// RUN: %target-sil-opt -enable-sil-verify-all %s -late-inline -sil-inline-threshold=50 -module-name Swift | %FileCheck %s --check-prefix=STDLIBLATE
2+
// RUN: %target-sil-opt -enable-sil-verify-all %s -inline -sil-inline-threshold=50 | %FileCheck %s --check-prefix=LATE
3+
// RUN: %target-sil-opt -enable-sil-verify-all %s -inline -sil-inline-threshold=50 -module-name Swift | %FileCheck %s --check-prefix=STDLIBLATE
44

55
sil_stage canonical
66

test/SILOptimizer/sil_combiner_concrete_prop_all_args.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-sil-opt -wmo -enable-sil-verify-all %s -inline -sil-combine -generic-specializer -allocbox-to-stack -copy-forwarding -lower-aggregate-instrs -mem2reg -devirtualizer -late-inline -dead-arg-signature-opt -dce | %FileCheck %s
1+
// RUN: %target-sil-opt -wmo -enable-sil-verify-all %s -inline -sil-combine -generic-specializer -allocbox-to-stack -copy-forwarding -lower-aggregate-instrs -mem2reg -devirtualizer -inline -dead-arg-signature-opt -dce | %FileCheck %s
22
import Builtin
33
import Swift
44
import SwiftShims

0 commit comments

Comments
 (0)