File: mandatory_performance_optimizations.sil

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (276 lines) | stat: -rw-r--r-- 13,505 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// RUN: %target-sil-opt -enable-sil-verify-all %s -mandatory-performance-optimizations | %FileCheck %s

// REQUIRES: swift_in_compiler

sil_stage canonical

import Builtin
import Swift
import SwiftShims

sil_global [let] @g1 : $Int32
sil_global [let] @g2 : $Int32

sil @paable : $@convention(thin) (Builtin.Int64) -> ()
sil @moved_pai_callee : $@convention(thin) (@inout_aliasable Builtin.Int64) -> ()
sil @use_closure : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()

sil [ossa] [transparent] @partial_apply_on_stack_nesting_violator : $@convention(thin) <T> () -> () {
    %paable = function_ref @paable : $@convention(thin) (Builtin.Int64) -> ()
    %one = integer_literal $Builtin.Int64, 1
    %first = partial_apply [callee_guaranteed] [on_stack] %paable(%one) : $@convention(thin) (Builtin.Int64) -> ()
    %two = integer_literal $Builtin.Int64, 2
    %second = partial_apply [callee_guaranteed] [on_stack] %paable(%two) : $@convention(thin) (Builtin.Int64) -> ()
    %f = function_ref @use_closure : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
    apply %f(%first) : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
    apply %f(%second) : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
    // Note that the destroy_values do not occur in an order which coincides
    // with stack disciplined dealloc_stacks.
    destroy_value %first : $@noescape @callee_guaranteed () -> ()
    destroy_value %second : $@noescape @callee_guaranteed () -> ()
    %retval = tuple ()
    return %retval : $()
}

// Verify that when inlining partial_apply_on_stack_nesting_violator, the stack
// nesting of the on_stack closures is fixed.
// CHECK-LABEL: sil [no_locks] [perf_constraint] @test_inline_stack_violating_ossa_func : {{.*}} {
// CHECK:         [[PAABLE:%[^,]+]] = function_ref @paable
// CHECK:         [[FIRST:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] [[PAABLE]]
// CHECK:         [[SECOND:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] [[PAABLE]]
// CHECK:         dealloc_stack [[SECOND]]
// CHECK:         dealloc_stack [[FIRST]]
// CHECK-LABEL: } // end sil function 'test_inline_stack_violating_ossa_func'
sil [no_locks] @test_inline_stack_violating_ossa_func : $@convention(thin) () -> () {
    %callee = function_ref @partial_apply_on_stack_nesting_violator : $@convention(thin) <T> () -> ()
    apply %callee<Builtin.Int64>() : $@convention(thin) <T> () -> ()
    %retval = tuple ()
    return %retval : $()
}

// CHECK-LABEL: sil hidden [no_allocation] [perf_constraint] [ossa] @moved_pai : {{.*}} {
// CHECK-NOT:     partial_apply
// CHECK-LABEL: } // end sil function 'moved_pai'
sil hidden [no_allocation] [ossa] @moved_pai : $@convention(thin) () -> Builtin.Int64 {
bb0:
  %addr = alloc_stack $Builtin.Int64
  %42 = integer_literal $Builtin.Int64, 42
  store %42 to [trivial] %addr : $*Builtin.Int64
  %callee = function_ref @moved_pai_callee : $@convention(thin) (@inout_aliasable Builtin.Int64) -> ()
  %closure = partial_apply [callee_guaranteed] %callee(%addr) : $@convention(thin) (@inout_aliasable Builtin.Int64) -> ()
  %closure_lifetime = move_value [lexical] %closure : $@callee_guaranteed () -> ()
  debug_value %closure_lifetime : $@callee_guaranteed () -> ()
  %copy = copy_value %closure_lifetime : $@callee_guaranteed () -> ()
  apply %copy() : $@callee_guaranteed () -> ()
  destroy_value %copy : $@callee_guaranteed () -> ()
  %retval = load [trivial] %addr : $*Builtin.Int64
  destroy_value %closure_lifetime : $@callee_guaranteed () -> ()
  dealloc_stack %addr : $*Builtin.Int64
  return %retval : $Builtin.Int64
}

// CHECK-LABEL: sil [no_allocation] [perf_constraint] @deserialize_and_inline_after_devirtualize
// CHECK-NOT:     apply
// CHECK:       } // end sil function 'deserialize_and_inline_after_devirtualize'
sil [no_allocation] @deserialize_and_inline_after_devirtualize : $@convention(thin) (@in Int) -> () {
bb0(%0 : $*Int):
  %1 = metatype $@thick Int.Type
  %2 = witness_method $Int, #Comparable."<" : <Self where Self : Comparable> (Self.Type) -> (Self, Self) -> Bool : $@convention(witness_method: Comparable) <τ_0_0 where τ_0_0 : Comparable> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> Bool
  %3 = apply %2<Int>(%0, %0, %1) : $@convention(witness_method: Comparable) <τ_0_0 where τ_0_0 : Comparable> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> Bool
  %4 = tuple()
  return %4 : $()
}

// CHECK-LABEL: sil [no_allocation] [perf_constraint] [ossa] @memopt_and_dead_alloc
// CHECK-NOT:         alloc_stack
// CHECK-NOT:     load
// CHECK:         return %0
// CHECK:       } // end sil function 'memopt_and_dead_alloc'
sil [no_allocation] [ossa] @memopt_and_dead_alloc : $@convention(thin) (Builtin.Int32) -> Builtin.Int32 {
bb0(%0 : $Builtin.Int32):
  %1 = alloc_stack $Builtin.Int32
  store %0 to [trivial] %1 : $*Builtin.Int32
  %2 = load [trivial] %1 : $*Builtin.Int32
  dealloc_stack %1 : $*Builtin.Int32
  return %2 : $Builtin.Int32
}

// CHECK-LABEL: sil [no_allocation] [perf_constraint] @dont_do_dead_alloc_elimination_on_non_ossa
// CHECK:         alloc_stack
// CHECK-NOT:     load
// CHECK:         return %0
// CHECK:       } // end sil function 'dont_do_dead_alloc_elimination_on_non_ossa'
sil [no_allocation] @dont_do_dead_alloc_elimination_on_non_ossa : $@convention(thin) (Builtin.Int32) -> Builtin.Int32 {
bb0(%0 : $Builtin.Int32):
  %1 = alloc_stack $Builtin.Int32
  store %0 to %1 : $*Builtin.Int32
  %2 = load %1 : $*Builtin.Int32
  dealloc_stack %1 : $*Builtin.Int32
  return %2 : $Builtin.Int32
}

// CHECK-LABEL: sil [no_allocation] [perf_constraint] @dead_metatype :
// CHECK-NOT:     metatype
// CHECK-NOT:     debug_value
// CHECK:       } // end sil function 'dead_metatype'
sil [no_allocation] @dead_metatype : $@convention(thin) () -> () {
bb0:
  %0 = metatype $@thick Int.Type
  debug_value %0 : $@thick Int.Type
  %2 = tuple ()
  return %2 : $()
}
sil shared [transparent] [serialized] [thunk] [canonical] @$sSiSLsSL1loiySbx_xtFZTW : $@convention(witness_method: Comparable) (@in_guaranteed Int, @in_guaranteed Int, @thick Int.Type) -> Bool {
bb0(%0 : $*Int, %1 : $*Int, %2 : $@thick Int.Type):
  %3 = integer_literal $Builtin.Int1, 0
  %4 = struct $Bool (%3 : $Builtin.Int1)
  return %4 : $Bool
}

sil_witness_table public_external [serialized] Int: Comparable module Swift {
  base_protocol Equatable: Int: Equatable module Swift
  method #Comparable."<": <Self where Self : Comparable> (Self.Type) -> (Self, Self) -> Bool : @$sSiSLsSL1loiySbx_xtFZTW
}

sil @get_int_value : $@convention(thin) () -> Int32 {
bb0:
  %0 = integer_literal $Builtin.Int32, 10
  %1 = struct $Int32 (%0 : $Builtin.Int32)
  return %1 : $Int32
}

// CHECK-LABEL: sil [global_init_once_fn] [no_locks] [perf_constraint] @globalinit_inline_into_init :
// CHECK-NOT:     apply
// CHECK:       } // end sil function 'globalinit_inline_into_init'
sil [global_init_once_fn] [no_locks] @globalinit_inline_into_init : $@convention(c) () -> () {
bb0:
  alloc_global @g1
  %1 = global_addr @g1 : $*Int32
  %2 = function_ref @get_int_value : $@convention(thin) () -> Int32
  %3 = apply %2() : $@convention(thin) () -> Int32
  store %3 to %1 : $*Int32
  %6 = tuple ()
  return %6 : $()
}

// CHECK-LABEL: sil [serialized] [global_init_once_fn] [no_locks] [perf_constraint] @globalinit_dont_inline_non_inlinable_into_inlinable :
// CHECK:         apply
// CHECK:       } // end sil function 'globalinit_dont_inline_non_inlinable_into_inlinable'
sil [serialized] [global_init_once_fn] [no_locks] @globalinit_dont_inline_non_inlinable_into_inlinable : $@convention(c) () -> () {
bb0:
  alloc_global @g2
  %1 = global_addr @g2 : $*Int32
  %2 = function_ref @get_int_value : $@convention(thin) () -> Int32
  %3 = apply %2() : $@convention(thin) () -> Int32
  store %3 to %1 : $*Int32
  %6 = tuple ()
  return %6 : $()
}

// Check that we don't crash on global init-once declarations.

// CHECK-LABEL: sil [global_init_once_fn] [no_locks] @external_global_init_once : $@convention(c) () -> ()
sil [global_init_once_fn] [no_locks] @external_global_init_once : $@convention(c) () -> ()

sil @yield_int_value : $@convention(thin) @yield_once () -> (@yields Int32) {
bb0:
  %0 = integer_literal $Builtin.Int32, 10
  %1 = struct $Int32 (%0 : $Builtin.Int32)
  yield %1 : $Int32, resume bb1, unwind bb2
bb1:
  %3 = tuple ()
  return %3 : $()
bb2:
  unwind
}

// CHECK-LABEL: sil [no_locks] [perf_constraint] @inline_begin_apply :
// CHECK-NOT:     begin_apply
// CHECK:       } // end sil function 'inline_begin_apply'
sil [no_locks] @inline_begin_apply : $@convention(thin) () -> Int32 {
bb0:
  %0 = function_ref @yield_int_value : $@convention(thin) @yield_once () -> (@yields Int32)
  (%1, %2) = begin_apply %0() : $@convention(thin) @yield_once () -> (@yields Int32)
  end_apply %2
  return %1 : $Int32
}

// CHECK-LABEL: sil [no_locks] [perf_constraint] @dont_inline_begin_apply :
// CHECK:         begin_apply
// CHECK:       } // end sil function 'dont_inline_begin_apply'
sil [no_locks] @dont_inline_begin_apply : $@convention(thin) () -> Int32 {
bb0:
  %0 = function_ref @yield_int_value : $@convention(thin) @yield_once () -> (@yields Int32)
  (%1, %2) = begin_apply %0() : $@convention(thin) @yield_once () -> (@yields Int32)
  cond_br undef, bb1, bb2
bb1:
  end_apply %2
  br bb3
bb2:
  end_apply %2
  br bb3
bb3:
  return %1 : $Int32
}

// CHECK-LABEL: sil [no_locks] [perf_constraint] [ossa] @remove_metatype_arg :
// CHECK:         [[F:%.*]] = function_ref @$s12metatype_argTf4dnn_n : $@convention(thin) (Int, @owned Builtin.NativeObject) -> @owned Builtin.NativeObject
// CHECK:         [[A:%.*]] = apply [[F]](%0, %1) : $@convention(thin) (Int, @owned Builtin.NativeObject) -> @owned Builtin.NativeObject
// CHECK:         return [[A]]
// CHECK:       } // end sil function 'remove_metatype_arg'
sil [no_locks] [ossa] @remove_metatype_arg : $@convention(thin) (Int, @owned Builtin.NativeObject) -> @owned Builtin.NativeObject {
bb0(%0 : $Int, %1 : @owned $Builtin.NativeObject):
  %3 = metatype $@thick Int.Type
  %7 = function_ref @metatype_arg : $@convention(thin) (Int, @thick Int.Type, @owned Builtin.NativeObject) -> @owned Builtin.NativeObject
  %8 = apply %7(%0, %3, %1) : $@convention(thin) (Int, @thick Int.Type, @owned Builtin.NativeObject) -> @owned Builtin.NativeObject
  return %8 : $Builtin.NativeObject
}

// CHECK-LABEL: sil [signature_optimized_thunk] [ossa] @metatype_arg :
sil [ossa] @metatype_arg : $@convention(thin) (Int, @thick Int.Type, @owned Builtin.NativeObject) -> @owned Builtin.NativeObject {
bb0(%0 : $Int, %1 : $@thick Int.Type, %2 : @owned $Builtin.NativeObject):
  fix_lifetime %1 : $@thick Int.Type
  return %2 : $Builtin.NativeObject
}

// CHECK-LABEL: sil [no_locks] [perf_constraint] [ossa] @remove_metatype_arg_throws :
// CHECK:         [[F:%.*]] = function_ref @$s19metatype_arg_throwsTf4dnn_n : $@convention(thin) (Int, @owned Builtin.NativeObject) -> (@owned Builtin.NativeObject, @error any Error)
// CHECK:         try_apply [[F]](%0, %1) : $@convention(thin) (Int, @owned Builtin.NativeObject) -> (@owned Builtin.NativeObject, @error any Error), normal bb1, error bb2
// CHECK:       bb1([[R:%.*]] : @owned $Builtin.NativeObject):
// CHECK:         return [[R]]
// CHECK:       bb2([[E:%.*]] : @owned $any Error):
// CHECK:         throw [[E]] : $any Error  
// CHECK:       } // end sil function 'remove_metatype_arg_throws'
sil [no_locks] [ossa] @remove_metatype_arg_throws : $@convention(thin) (Int, @owned Builtin.NativeObject) -> (@owned Builtin.NativeObject, @error any Error) {
bb0(%0 : $Int, %1 : @owned $Builtin.NativeObject):
  %3 = metatype $@thick Int.Type
  %4 = function_ref @metatype_arg_throws : $@convention(thin) (Int, @thick Int.Type, @owned Builtin.NativeObject) -> (@owned Builtin.NativeObject, @error any Error)
  try_apply %4(%0, %3, %1) : $@convention(thin) (Int, @thick Int.Type, @owned Builtin.NativeObject) -> (@owned Builtin.NativeObject, @error any Error), normal bb1, error bb2

bb1(%10 : @owned $Builtin.NativeObject):
  return %10 : $Builtin.NativeObject

bb2(%13 : @owned $any Error):
  throw %13 : $any Error
}

// CHECK-LABEL: sil [signature_optimized_thunk] [ossa] @metatype_arg_throws :
sil [ossa] @metatype_arg_throws : $@convention(thin) (Int, @thick Int.Type, @owned Builtin.NativeObject) -> (@owned Builtin.NativeObject, @error any Error) {
bb0(%0 : $Int, %1 : $@thick Int.Type, %2 : @owned $Builtin.NativeObject):
  fix_lifetime %1 : $@thick Int.Type
  return %2 : $Builtin.NativeObject
}

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

// CHECK-LABEL: sil [perf_constraint] [ossa] @$s19metatype_arg_throwsTf4dnn_n : $@convention(thin) (Int, @owned Builtin.NativeObject) -> (@owned Builtin.NativeObject, @error any Error) {
// CHECK:       bb0(%0 : $Int, %1 : @owned $Builtin.NativeObject):
// CHECK:         %2 = metatype $@thick Int.Type
// CHECK:         fix_lifetime %2 : $@thick Int.Type
// CHECK:         return %1 : $Builtin.NativeObject
// CHECK:       } // end sil function '$s19metatype_arg_throwsTf4dnn_n'