File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,9 @@ class SILPerformanceInliner {
120120 // / call overhead itself.
121121 RemovedCallBenefit = 20 ,
122122
123+ // / The benefit of inlining a `begin_apply`.
124+ RemovedCoroutineCallBenefit = 300 ,
125+
123126 // / The benefit if the operand of an apply gets constant, e.g. if a closure
124127 // / is passed to an apply instruction in the callee.
125128 RemovedClosureBenefit = RemovedCallBenefit + 50 ,
@@ -373,7 +376,8 @@ bool SILPerformanceInliner::isProfitableToInline(
373376 bool IsGeneric = AI.hasSubstitutions ();
374377
375378 // Start with a base benefit.
376- int BaseBenefit = RemovedCallBenefit;
379+ int BaseBenefit = isa<BeginApplyInst>(AI) ? RemovedCoroutineCallBenefit
380+ : RemovedCallBenefit;
377381
378382 // Osize heuristic.
379383 //
Original file line number Diff line number Diff line change 1+ // RUN: %target-swift-frontend -primary-file %s -parse-as-library -module-name=test -emit-sil -O | %FileCheck %s
2+
3+ // Check that co-routines are inlined, even if the yielded value is something non-trivial.
4+
5+ struct S {
6+ var i : Int64
7+ var s : String
8+ }
9+
10+ public struct Foo {
11+ final class Box {
12+ var value = S ( i: 0 , s: " " )
13+ }
14+
15+ var storage : Box = . init( )
16+
17+ var value : S {
18+ get {
19+ storage. value
20+ }
21+ _modify {
22+ var value = storage. value
23+ defer { storage. value = value }
24+ yield & value
25+ }
26+ }
27+ }
28+
29+ // CHECK-LABEL: sil hidden @$s4test6testit1x3boxys5Int64V_AA3FooVztF :
30+ // CHECK-NOT: begin_apply
31+ // CHECK: } // end sil function '$s4test6testit1x3boxys5Int64V_AA3FooVztF'
32+ func testit( x: Int64 , box: inout Foo ) {
33+ box. value. i ^= x
34+ }
35+
You can’t perform that action at this time.
0 commit comments