Skip to content

Commit 375c181

Browse files
authored
Merge pull request #10118 from swiftix/inliner-improvements2
[sil-inliner] Do not perform early performance inlining for function with certain @_semantics attributes
2 parents 837fb19 + abdee7f commit 375c181

File tree

2 files changed

+61
-17
lines changed

2 files changed

+61
-17
lines changed

lib/SILOptimizer/Utils/PerformanceInlinerUtils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,10 @@ static bool shouldSkipApplyDuringEarlyInlining(FullApplySite AI) {
608608
if (!Callee)
609609
return false;
610610

611+
if (Callee->hasSemanticsAttr("self_no_escaping_closure") ||
612+
Callee->hasSemanticsAttr("pair_no_escaping_closure"))
613+
return true;
614+
611615
// Add here the checks for any specific @_effects attributes that need
612616
// to be skipped during the early inlining pass.
613617
if (Callee->hasEffectsKind())

test/SILOptimizer/inline_semantics.sil

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import Swift
77

88
sil [_semantics "no_inline_plz"] @callee_func : $@convention(thin) () -> Int32 {
99
bb0:
10-
%0 = integer_literal $Builtin.Int32, 3 // user: %1
11-
%1 = struct $Int32 (%0 : $Builtin.Int32) // user: %2
12-
return %1 : $Int32 // id: %2
10+
%0 = integer_literal $Builtin.Int32, 3
11+
%1 = struct $Int32 (%0 : $Builtin.Int32)
12+
return %1 : $Int32
1313
}
1414

1515
//Not every @_semantics should be skipped during the early inlining pass, but
@@ -21,16 +21,16 @@ bb0:
2121
//CHECK: end sil function 'caller_func'
2222
sil @caller_func : $@convention(thin) () -> Int32 {
2323
bb0:
24-
%0 = function_ref @callee_func : $@convention(thin) () -> Int32 // user: %1
25-
%1 = apply %0() : $@convention(thin) () -> Int32 // user: %2
26-
return %1 : $Int32 // id: %2
24+
%0 = function_ref @callee_func : $@convention(thin) () -> Int32
25+
%1 = apply %0() : $@convention(thin) () -> Int32
26+
return %1 : $Int32
2727
}
2828

2929
sil [_semantics "array.make_mutable"] @callee_func_with_to_be_skipped_during_inlining_semantics : $@convention(method) (@inout Int32) -> Int32 {
3030
bb0(%self : $*Int32):
31-
%0 = integer_literal $Builtin.Int32, 3 // user: %1
32-
%1 = struct $Int32 (%0 : $Builtin.Int32) // user: %2
33-
return %1 : $Int32 // id: %2
31+
%0 = integer_literal $Builtin.Int32, 3
32+
%1 = struct $Int32 (%0 : $Builtin.Int32)
33+
return %1 : $Int32
3434
}
3535

3636
//Not every @_semantics should be skipped during the early inlining pass, but
@@ -44,17 +44,57 @@ sil @caller_func2 : $@convention(thin) () -> Int32 {
4444
bb0:
4545
%self = alloc_stack $Int32
4646
%0 = function_ref @callee_func_with_to_be_skipped_during_inlining_semantics : $@convention(method) (@inout Int32) -> Int32 // user: %1
47-
%1 = apply %0(%self) : $@convention(method) (@inout Int32) -> Int32 // user: %2
47+
%1 = apply %0(%self) : $@convention(method) (@inout Int32) -> Int32
4848
dealloc_stack %self : $*Int32
49-
return %1 : $Int32 // id: %2
49+
return %1 : $Int32
50+
}
51+
52+
sil [_semantics "pair_no_escaping_closure"] @callee_func_with_pair_no_escaping_closure_semantics : $@convention(method) (@inout Int32) -> Int32 {
53+
bb0(%self : $*Int32):
54+
%0 = integer_literal $Builtin.Int32, 3
55+
%1 = struct $Int32 (%0 : $Builtin.Int32)
56+
return %1 : $Int32
57+
}
58+
59+
//CHECK-LABEL: caller_func3
60+
//CHECK: function_ref
61+
//CHECK: apply
62+
//CHECK: end sil function 'caller_func3'
63+
sil @caller_func3 : $@convention(thin) () -> Int32 {
64+
bb0:
65+
%self = alloc_stack $Int32
66+
%0 = function_ref @callee_func_with_pair_no_escaping_closure_semantics : $@convention(method) (@inout Int32) -> Int32 // user: %1
67+
%1 = apply %0(%self) : $@convention(method) (@inout Int32) -> Int32
68+
dealloc_stack %self : $*Int32
69+
return %1 : $Int32
70+
}
71+
72+
sil [_semantics "self_no_escaping_closure"] @callee_func_with_self_no_escaping_closure_semantics : $@convention(method) (@inout Int32) -> Int32 {
73+
bb0(%self : $*Int32):
74+
%0 = integer_literal $Builtin.Int32, 3
75+
%1 = struct $Int32 (%0 : $Builtin.Int32)
76+
return %1 : $Int32
77+
}
78+
79+
//CHECK-LABEL: caller_func4
80+
//CHECK: function_ref
81+
//CHECK: apply
82+
//CHECK: end sil function 'caller_func4'
83+
sil @caller_func4 : $@convention(thin) () -> Int32 {
84+
bb0:
85+
%self = alloc_stack $Int32
86+
%0 = function_ref @callee_func_with_self_no_escaping_closure_semantics : $@convention(method) (@inout Int32) -> Int32 // user: %1
87+
%1 = apply %0(%self) : $@convention(method) (@inout Int32) -> Int32
88+
dealloc_stack %self : $*Int32
89+
return %1 : $Int32
5090
}
5191

5292
// A function annotated with the @effects(readonly) attribute.
5393
sil [readonly] @callee_func2 : $@convention(thin) () -> Int32 {
5494
bb0:
55-
%0 = integer_literal $Builtin.Int32, 3 // user: %1
56-
%1 = struct $Int32 (%0 : $Builtin.Int32) // user: %2
57-
return %1 : $Int32 // id: %2
95+
%0 = integer_literal $Builtin.Int32, 3
96+
%1 = struct $Int32 (%0 : $Builtin.Int32)
97+
return %1 : $Int32
5898
}
5999

60100
//CHECK-LABEL: caller_func1
@@ -63,8 +103,8 @@ bb0:
63103
//CHECK-NEXT: ret
64104
sil @caller_func1 : $@convention(thin) () -> Int32 {
65105
bb0:
66-
%0 = function_ref @callee_func2 : $@convention(thin) () -> Int32 // user: %1
67-
%1 = apply %0() : $@convention(thin) () -> Int32 // user: %2
68-
return %1 : $Int32 // id: %2
106+
%0 = function_ref @callee_func2 : $@convention(thin) () -> Int32
107+
%1 = apply %0() : $@convention(thin) () -> Int32
108+
return %1 : $Int32
69109
}
70110

0 commit comments

Comments
 (0)