Skip to content

Commit 38bfc03

Browse files
committed
MandatoryPerformanceOptimizations: set the [perf_constraint] flag on functions with performance constraints
1 parent 4c37223 commit 38bfc03

File tree

6 files changed

+38
-25
lines changed

6 files changed

+38
-25
lines changed

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ private func optimizeFunctionsTopDown(using worklist: inout FunctionWorklist,
5050
return
5151
}
5252

53+
// It's not required to set the perf_constraint flag on all functions in embedded mode.
54+
// Embedded mode already implies that flag.
55+
if !moduleContext.options.enableEmbeddedSwift {
56+
f.set(isPerformanceConstraint: true, context)
57+
}
58+
5359
optimize(function: f, context, &worklist)
5460
}
5561

test/IRGen/section.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ struct MyStruct {
2727
// SIL: @_section("__DATA,__mysection") @_hasStorage @_hasInitialValue static var static0: Int { get set }
2828
// SIL: @_section("__TEXT,__mysection") func foo()
2929

30-
// SIL: sil private [global_init_once_fn] @$s7section2g0_WZ : $@convention(c)
30+
// SIL: sil private [global_init_once_fn] [perf_constraint] @$s7section2g0_WZ : $@convention(c)
3131
// SIL: sil hidden [global_init] @$s7section2g0Sivau : $@convention(thin)
32-
// SIL: sil private [global_init_once_fn] @$s7section2g1_WZ : $@convention(c)
32+
// SIL: sil private [global_init_once_fn] [perf_constraint] @$s7section2g1_WZ : $@convention(c)
3333
// SIL: sil hidden [global_init] @$s7section2g1Si_Sitvau : $@convention(thin)
34-
// SIL: sil private [global_init_once_fn] @$s7section2g2_WZ : $@convention(c)
34+
// SIL: sil private [global_init_once_fn] [perf_constraint] @$s7section2g2_WZ : $@convention(c)
3535
// SIL: sil hidden [global_init] @$s7section2g2Sbvau : $@convention(thin)
36-
// SIL: sil private [global_init_once_fn] @$s7section2g3_WZ : $@convention(c)
36+
// SIL: sil private [global_init_once_fn] [perf_constraint] @$s7section2g3_WZ : $@convention(c)
3737
// SIL: sil [global_init] @$s7section2g3Sbvau : $@convention(thin)
38-
// SIL: sil private [global_init_once_fn] @$s7section2g4_WZ : $@convention(c)
38+
// SIL: sil private [global_init_once_fn] [perf_constraint] @$s7section2g4_WZ : $@convention(c)
3939
// SIL: sil hidden [global_init] @$s7section2g4SpySiGSgvau : $@convention(thin)
40-
// SIL: sil private [global_init_once_fn] @$s7section2g5_WZ : $@convention(c)
40+
// SIL: sil private [global_init_once_fn] [perf_constraint] @$s7section2g5_WZ : $@convention(c)
4141
// SIL: sil hidden [global_init] @$s7section2g5SpySiGSgvau : $@convention(thin)
4242
// SIL: sil hidden [section "__TEXT,__mysection"] @$s7section3fooyyF : $@convention(thin)
43-
// SIL: sil private [global_init_once_fn] @$s7section8MyStructV7static0_WZ : $@convention(c)
43+
// SIL: sil private [global_init_once_fn] [perf_constraint] @$s7section8MyStructV7static0_WZ : $@convention(c)
4444
// SIL: sil hidden [global_init] @$s7section8MyStructV7static0Sivau : $@convention(thin)
4545
// SIL: sil hidden [section "__TEXT,__mysection"] @$s7section8MyStructV3fooyyF : $@convention(method)
4646

test/SIL/Parser/attributes.sil

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ bb0:
2020
return %1 : $()
2121
}
2222

23+
// CHECK-LABEL: sil [perf_constraint] [ossa] @test_perf_constraint : $@convention(thin) () -> () {
24+
sil [perf_constraint] [ossa] @test_perf_constraint : $@convention(thin) () -> () {
25+
bb0:
26+
%1 = tuple ()
27+
return %1 : $()
28+
}
29+
2330
// Make sure we don't try to parse the Swift decl as '@owned() func baz()'.
2431
sil @bar : $@convention(thin) () -> @owned ()
2532
func baz()

test/SILOptimizer/mandatory_performance_optimizations.sil

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ sil [ossa] [transparent] @partial_apply_on_stack_nesting_violator : $@convention
3434

3535
// Verify that when inlining partial_apply_on_stack_nesting_violator, the stack
3636
// nesting of the on_stack closures is fixed.
37-
// CHECK-LABEL: sil [no_locks] @test_inline_stack_violating_ossa_func : {{.*}} {
37+
// CHECK-LABEL: sil [no_locks] [perf_constraint] @test_inline_stack_violating_ossa_func : {{.*}} {
3838
// CHECK: [[PAABLE:%[^,]+]] = function_ref @paable
3939
// CHECK: [[FIRST:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] [[PAABLE]]
4040
// CHECK: [[SECOND:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] [[PAABLE]]
@@ -48,7 +48,7 @@ sil [no_locks] @test_inline_stack_violating_ossa_func : $@convention(thin) () ->
4848
return %retval : $()
4949
}
5050

51-
// CHECK-LABEL: sil hidden [no_allocation] [ossa] @moved_pai : {{.*}} {
51+
// CHECK-LABEL: sil hidden [no_allocation] [perf_constraint] [ossa] @moved_pai : {{.*}} {
5252
// CHECK-NOT: partial_apply
5353
// CHECK-LABEL: } // end sil function 'moved_pai'
5454
sil hidden [no_allocation] [ossa] @moved_pai : $@convention(thin) () -> Builtin.Int64 {
@@ -69,7 +69,7 @@ bb0:
6969
return %retval : $Builtin.Int64
7070
}
7171

72-
// CHECK-LABEL: sil [no_allocation] @deserialize_and_inline_after_devirtualize
72+
// CHECK-LABEL: sil [no_allocation] [perf_constraint] @deserialize_and_inline_after_devirtualize
7373
// CHECK-NOT: apply
7474
// CHECK: } // end sil function 'deserialize_and_inline_after_devirtualize'
7575
sil [no_allocation] @deserialize_and_inline_after_devirtualize : $@convention(thin) (@in Int) -> () {
@@ -81,7 +81,7 @@ bb0(%0 : $*Int):
8181
return %4 : $()
8282
}
8383

84-
// CHECK-LABEL: sil [no_allocation] [ossa] @memopt_and_dead_alloc
84+
// CHECK-LABEL: sil [no_allocation] [perf_constraint] [ossa] @memopt_and_dead_alloc
8585
// CHECK-NOT: alloc_stack
8686
// CHECK-NOT: load
8787
// CHECK: return %0
@@ -95,7 +95,7 @@ bb0(%0 : $Builtin.Int32):
9595
return %2 : $Builtin.Int32
9696
}
9797

98-
// CHECK-LABEL: sil [no_allocation] @dont_do_dead_alloc_elimination_on_non_ossa
98+
// CHECK-LABEL: sil [no_allocation] [perf_constraint] @dont_do_dead_alloc_elimination_on_non_ossa
9999
// CHECK: alloc_stack
100100
// CHECK-NOT: load
101101
// CHECK: return %0
@@ -109,7 +109,7 @@ bb0(%0 : $Builtin.Int32):
109109
return %2 : $Builtin.Int32
110110
}
111111

112-
// CHECK-LABEL: sil [no_allocation] @dead_metatype :
112+
// CHECK-LABEL: sil [no_allocation] [perf_constraint] @dead_metatype :
113113
// CHECK-NOT: metatype
114114
// CHECK-NOT: debug_value
115115
// CHECK: } // end sil function 'dead_metatype'
@@ -139,7 +139,7 @@ bb0:
139139
return %1 : $Int32
140140
}
141141

142-
// CHECK-LABEL: sil [global_init_once_fn] [no_locks] @globalinit_inline_into_init :
142+
// CHECK-LABEL: sil [global_init_once_fn] [no_locks] [perf_constraint] @globalinit_inline_into_init :
143143
// CHECK-NOT: apply
144144
// CHECK: } // end sil function 'globalinit_inline_into_init'
145145
sil [global_init_once_fn] [no_locks] @globalinit_inline_into_init : $@convention(c) () -> () {
@@ -153,7 +153,7 @@ bb0:
153153
return %6 : $()
154154
}
155155

156-
// CHECK-LABEL: sil [serialized] [global_init_once_fn] [no_locks] @globalinit_dont_inline_non_inlinable_into_inlinable :
156+
// CHECK-LABEL: sil [serialized] [global_init_once_fn] [no_locks] [perf_constraint] @globalinit_dont_inline_non_inlinable_into_inlinable :
157157
// CHECK: apply
158158
// CHECK: } // end sil function 'globalinit_dont_inline_non_inlinable_into_inlinable'
159159
sil [serialized] [global_init_once_fn] [no_locks] @globalinit_dont_inline_non_inlinable_into_inlinable : $@convention(c) () -> () {
@@ -179,7 +179,7 @@ bb2:
179179
unwind
180180
}
181181

182-
// CHECK-LABEL: sil [no_locks] @inline_begin_apply :
182+
// CHECK-LABEL: sil [no_locks] [perf_constraint] @inline_begin_apply :
183183
// CHECK-NOT: begin_apply
184184
// CHECK: } // end sil function 'inline_begin_apply'
185185
sil [no_locks] @inline_begin_apply : $@convention(thin) () -> Int32 {
@@ -190,7 +190,7 @@ bb0:
190190
return %1 : $Int32
191191
}
192192

193-
// CHECK-LABEL: sil [no_locks] @dont_inline_begin_apply :
193+
// CHECK-LABEL: sil [no_locks] [perf_constraint] @dont_inline_begin_apply :
194194
// CHECK: begin_apply
195195
// CHECK: } // end sil function 'dont_inline_begin_apply'
196196
sil [no_locks] @dont_inline_begin_apply : $@convention(thin) () -> Int32 {
@@ -208,7 +208,7 @@ bb3:
208208
return %1 : $Int32
209209
}
210210

211-
// CHECK-LABEL: sil [no_locks] [ossa] @remove_metatype_arg :
211+
// CHECK-LABEL: sil [no_locks] [perf_constraint] [ossa] @remove_metatype_arg :
212212
// CHECK: [[F:%.*]] = function_ref @$s12metatype_argTf4dnn_n : $@convention(thin) (Int, @owned Builtin.NativeObject) -> @owned Builtin.NativeObject
213213
// CHECK: [[A:%.*]] = apply [[F]](%0, %1) : $@convention(thin) (Int, @owned Builtin.NativeObject) -> @owned Builtin.NativeObject
214214
// CHECK: return [[A]]
@@ -228,7 +228,7 @@ bb0(%0 : $Int, %1 : $@thick Int.Type, %2 : @owned $Builtin.NativeObject):
228228
return %2 : $Builtin.NativeObject
229229
}
230230

231-
// CHECK-LABEL: sil [no_locks] [ossa] @remove_metatype_arg_throws :
231+
// CHECK-LABEL: sil [no_locks] [perf_constraint] [ossa] @remove_metatype_arg_throws :
232232
// CHECK: [[F:%.*]] = function_ref @$s19metatype_arg_throwsTf4dnn_n : $@convention(thin) (Int, @owned Builtin.NativeObject) -> (@owned Builtin.NativeObject, @error any Error)
233233
// CHECK: try_apply [[F]](%0, %1) : $@convention(thin) (Int, @owned Builtin.NativeObject) -> (@owned Builtin.NativeObject, @error any Error), normal bb1, error bb2
234234
// CHECK: bb1([[R:%.*]] : @owned $Builtin.NativeObject):
@@ -256,14 +256,14 @@ bb0(%0 : $Int, %1 : $@thick Int.Type, %2 : @owned $Builtin.NativeObject):
256256
return %2 : $Builtin.NativeObject
257257
}
258258

259-
// CHECK-LABEL: sil [ossa] @$s12metatype_argTf4dnn_n : $@convention(thin) (Int, @owned Builtin.NativeObject) -> @owned Builtin.NativeObject {
259+
// CHECK-LABEL: sil [perf_constraint] [ossa] @$s12metatype_argTf4dnn_n : $@convention(thin) (Int, @owned Builtin.NativeObject) -> @owned Builtin.NativeObject {
260260
// CHECK: bb0(%0 : $Int, %1 : @owned $Builtin.NativeObject):
261261
// CHECK: %2 = metatype $@thick Int.Type
262262
// CHECK: fix_lifetime %2 : $@thick Int.Type
263263
// CHECK: return %1 : $Builtin.NativeObject
264264
// CHECK: } // end sil function '$s12metatype_argTf4dnn_n'
265265

266-
// CHECK-LABEL: sil [ossa] @$s19metatype_arg_throwsTf4dnn_n : $@convention(thin) (Int, @owned Builtin.NativeObject) -> (@owned Builtin.NativeObject, @error any Error) {
266+
// CHECK-LABEL: sil [perf_constraint] [ossa] @$s19metatype_arg_throwsTf4dnn_n : $@convention(thin) (Int, @owned Builtin.NativeObject) -> (@owned Builtin.NativeObject, @error any Error) {
267267
// CHECK: bb0(%0 : $Int, %1 : @owned $Builtin.NativeObject):
268268
// CHECK: %2 = metatype $@thick Int.Type
269269
// CHECK: fix_lifetime %2 : $@thick Int.Type

test/SILOptimizer/memory-layout.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Check that constant propagation of MemoryLayout is also done at -Onone to ensure that
66
// no metadata is created at runtime - which would violate the performance annotation.
77

8-
// CHECK-LABEL: sil [no_locks] @$s4test7getSizeSiyF
8+
// CHECK-LABEL: sil [no_locks] [perf_constraint] @$s4test7getSizeSiyF
99
// CHECK: [[I:%[0-9]+]] = integer_literal {{.*}}, 4
1010
// CHECK: [[S:%[0-9]+]] = struct {{.*}}([[I]]
1111
// CHECK: return [[S]]
@@ -15,7 +15,7 @@ public func getSize() -> Int {
1515
return MemoryLayout<Int32>.size
1616
}
1717

18-
// CHECK-LABEL: sil [no_locks] @$s4test12getAlignmentSiyF
18+
// CHECK-LABEL: sil [no_locks] [perf_constraint] @$s4test12getAlignmentSiyF
1919
// CHECK: [[I:%[0-9]+]] = integer_literal {{.*}}, 4
2020
// CHECK: [[S:%[0-9]+]] = struct {{.*}}([[I]]
2121
// CHECK: return [[S]]
@@ -25,7 +25,7 @@ public func getAlignment() -> Int {
2525
return MemoryLayout<Int32>.alignment
2626
}
2727

28-
// CHECK-LABEL: sil [no_locks] @$s4test9getStrideSiyF
28+
// CHECK-LABEL: sil [no_locks] [perf_constraint] @$s4test9getStrideSiyF
2929
// CHECK: [[I:%[0-9]+]] = integer_literal {{.*}}, 4
3030
// CHECK: [[S:%[0-9]+]] = struct {{.*}}([[I]]
3131
// CHECK: return [[S]]

test/SILOptimizer/performance-annotations2.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public struct Stack<T> {
77
var size = 42
88
}
99

10-
// CHECK-LABEL: sil [no_allocation] @$s4test11createStackyyF :
10+
// CHECK-LABEL: sil [no_allocation] [perf_constraint] @$s4test11createStackyyF :
1111
// CHECK: [[F:%[0-9]+]] = function_ref @$s4test5StackVACyxGycfCSi_Tgm5
1212
// CHECK: [[S:%[0-9]+]] = apply [[F]]()
1313
// CHECK: debug_value [[S]]

0 commit comments

Comments
 (0)