File: templvalueopt_ossa.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 (336 lines) | stat: -rw-r--r-- 12,814 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
// RUN: %target-sil-opt -enable-sil-verify-all %s -temp-lvalue-opt | %FileCheck %s

// REQUIRES: swift_in_compiler

import Swift
import Builtin

// CHECK-LABEL: sil [ossa] @test_enum_with_initialize :
// CHECK:      bb0(%0 : $*Optional<Any>, %1 : $*Any):
// CHECK-NEXT:   [[E:%[0-9]+]] = init_enum_data_addr %0
// CHECK-NEXT:   copy_addr [take] %1 to [init] [[E]]
// CHECK-NEXT:   inject_enum_addr %0 : $*Optional<Any>, #Optional.some!enumelt
// CHECK-NOT:    copy_addr
// CHECK: } // end sil function 'test_enum_with_initialize'
sil [ossa] @test_enum_with_initialize : $@convention(thin) (@in Any) -> @out Optional<Any> {
bb0(%0 : $*Optional<Any>, %1 : $*Any):
  %2 = alloc_stack $Optional<Any>
  %3 = init_enum_data_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  copy_addr [take] %1 to [init] %3 : $*Any
  inject_enum_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  copy_addr [take] %2 to [init] %0 : $*Optional<Any>
  dealloc_stack %2 : $*Optional<Any>
  %6 = tuple ()
  return %6 : $()
}

// CHECK-LABEL: sil [ossa] @test_enum_without_initialize :
// CHECK:      bb0(%0 : $*Optional<Any>, %1 : $*Any):
// CHECK-NEXT:   destroy_addr %0
// CHECK-NEXT:   [[E:%[0-9]+]] = init_enum_data_addr %0
// CHECK-NEXT:   copy_addr [take] %1 to [init] [[E]]
// CHECK-NEXT:   inject_enum_addr %0 : $*Optional<Any>, #Optional.some!enumelt
// CHECK-NOT:    copy_addr
// CHECK: } // end sil function 'test_enum_without_initialize'
sil [ossa] @test_enum_without_initialize : $@convention(thin) (@inout Optional<Any>, @in Any) -> () {
bb0(%0 : $*Optional<Any>, %1 : $*Any):
  %2 = alloc_stack $Optional<Any>
  %3 = init_enum_data_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  copy_addr [take] %1 to [init] %3 : $*Any
  inject_enum_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  copy_addr [take] %2 to %0 : $*Optional<Any>
  dealloc_stack %2 : $*Optional<Any>
  %6 = tuple ()
  return %6 : $()
}

protocol Proto {}

struct ConformingStruct : Proto {
  @_hasStorage let a: Any
}

// CHECK-LABEL: sil [ossa] @test_existential :
// CHECK:      bb0(%0 : $*any Proto, %1 : $*ConformingStruct):
// CHECK-NEXT:   [[E:%[0-9]+]] = init_existential_addr %0
// CHECK-NEXT:   copy_addr [take] %1 to [init] [[E]]
// CHECK-NOT:    copy_addr
// CHECK: } // end sil function 'test_existential'
sil [ossa] @test_existential : $@convention(thin) (@in ConformingStruct) -> @out Proto {
bb0(%0 : $*Proto, %1 : $*ConformingStruct):
  %2 = alloc_stack $Proto
  %3 = init_existential_addr %2 : $*Proto, $ConformingStruct
  copy_addr [take] %1 to [init] %3 : $*ConformingStruct
  copy_addr [take] %2 to [init] %0 : $*Proto
  dealloc_stack %2 : $*Proto
  %6 = tuple ()
  return %6 : $()
}

enum Either<Left, Right> {
  case left(Left), right(Right)
}

public struct TestStruct {
  @_hasStorage var e: Either<AddressOnlyPayload, Int>
}

struct AddressOnlyPayload {
  @_hasStorage let a: Any
  @_hasStorage let i: Int
}

// There should only be a single copy_addr after optimization.
//
// CHECK-LABEL: sil [ossa] @test_initialize_struct :
// CHECK:      bb0(%0 : $*TestStruct, %1 : $*Any, %2 : $Int):
// CHECK-NEXT:   [[E:%[0-9]+]] = struct_element_addr %0
// CHECK-NEXT:   [[LEFT:%[0-9]+]] = init_enum_data_addr [[E]]
// CHECK-NEXT:   [[A:%[0-9]+]] = struct_element_addr [[LEFT]]
// CHECK-NEXT:   copy_addr [take] %1 to [init] [[A]]
// CHECK-NEXT:   [[I:%[0-9]+]] = struct_element_addr [[LEFT]]
// CHECK-NEXT:   store %2 to [trivial] [[I]]
// CHECK-NEXT:   inject_enum_addr [[E]]
// CHECK-NOT:    copy_addr
// CHECK: } // end sil function 'test_initialize_struct'
sil [ossa] @test_initialize_struct : $@convention(method) (@in Any, Int) -> @out TestStruct {
bb0(%0 : $*TestStruct, %1 : $*Any, %2 : $Int):
  %3 = alloc_stack $TestStruct
  %4 = alloc_stack $Either<AddressOnlyPayload, Int>
  %5 = alloc_stack $AddressOnlyPayload
  %6 = struct_element_addr %5 : $*AddressOnlyPayload, #AddressOnlyPayload.a
  copy_addr [take] %1 to [init] %6 : $*Any
  %8 = struct_element_addr %5 : $*AddressOnlyPayload, #AddressOnlyPayload.i
  store %2 to [trivial] %8 : $*Int
  %10 = init_enum_data_addr %4 : $*Either<AddressOnlyPayload, Int>, #Either.left!enumelt
  copy_addr [take] %5 to [init] %10 : $*AddressOnlyPayload
  inject_enum_addr %4 : $*Either<AddressOnlyPayload, Int>, #Either.left!enumelt
  dealloc_stack %5 : $*AddressOnlyPayload
  %14 = struct_element_addr %3 : $*TestStruct, #TestStruct.e
  copy_addr [take] %4 to [init] %14 : $*Either<AddressOnlyPayload, Int>
  dealloc_stack %4 : $*Either<AddressOnlyPayload, Int>
  copy_addr %3 to [init] %0 : $*TestStruct
  destroy_addr %3 : $*TestStruct
  dealloc_stack %3 : $*TestStruct
  %20 = tuple ()
  return %20 : $()
}

// CHECK-LABEL: sil [ossa] @bail_on_write_to_dest :
// CHECK:   alloc_stack
// CHECK:   copy_addr
// CHECK:   copy_addr
// CHECK: } // end sil function 'bail_on_write_to_dest'
sil [ossa] @bail_on_write_to_dest : $@convention(thin) (@inout Optional<Any>, @in Any) -> () {
bb0(%0 : $*Optional<Any>, %1 : $*Any):
  %2 = alloc_stack $Optional<Any>
  %3 = init_enum_data_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  copy_addr [take] %1 to [init] %3 : $*Any
  inject_enum_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  destroy_addr %0 : $*Optional<Any>
  copy_addr [take] %2 to [init] %0 : $*Optional<Any>
  dealloc_stack %2 : $*Optional<Any>
  %6 = tuple ()
  return %6 : $()
}

// CHECK-LABEL: sil [ossa] @write_to_dest_ok_if_before_liferange :
// CHECK:      bb0(%0 : $*Optional<Any>, %1 : $*Any):
// CHECK-NEXT:   destroy_addr
// CHECK-NEXT:   init_enum_data_addr
// CHECK-NEXT:   copy_addr
// CHECK-NEXT:   inject_enum_addr
// CHECK-NOT:    copy_addr
// CHECK: } // end sil function 'write_to_dest_ok_if_before_liferange'
sil [ossa] @write_to_dest_ok_if_before_liferange : $@convention(thin) (@inout Optional<Any>, @in Any) -> () {
bb0(%0 : $*Optional<Any>, %1 : $*Any):
  %2 = alloc_stack $Optional<Any>
  destroy_addr %0 : $*Optional<Any>
  %3 = init_enum_data_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  copy_addr [take] %1 to [init] %3 : $*Any
  inject_enum_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  copy_addr [take] %2 to [init] %0 : $*Optional<Any>
  dealloc_stack %2 : $*Optional<Any>
  %6 = tuple ()
  return %6 : $()
}

enum Enum {
  case A(Optional<Any>), B
}

struct StructWithEnum : Proto {
  @_hasStorage let e: Enum
}

// CHECK-LABEL: sil [ossa] @move_projections :
// CHECK:      bb0(%0 : $*any Proto, %1 : $*Any):
// CHECK-NEXT:   [[S:%[0-9]+]] = init_existential_addr %0 : $*any Proto, $StructWithEnum
// CHECK-NEXT:   [[E:%[0-9]+]] = struct_element_addr [[S]] : $*StructWithEnum, #StructWithEnum.e
// CHECK-NEXT:   [[ENUMA:%[0-9]+]] = init_enum_data_addr [[E]] : $*Enum, #Enum.A!enumelt
// CHECK-NEXT:   [[OPTIONAL:%[0-9]+]] = init_enum_data_addr [[ENUMA]] : $*Optional<Any>, #Optional.some!enumelt
// CHECK-NEXT:   copy_addr [take] %1 to [init] [[OPTIONAL]] : $*Any
// CHECK-NEXT:   inject_enum_addr [[ENUMA]] : $*Optional<Any>, #Optional.some!enumelt
// CHECK-NEXT:   inject_enum_addr [[E]] : $*Enum, #Enum.A!enumelt
// CHECK-NOT:    copy_addr
// CHECK: } // end sil function 'move_projections'
sil [ossa] @move_projections : $@convention(thin) (@in Any) -> @out Proto {
bb0(%0 : $*Proto, %1 : $*Any):
  %2 = alloc_stack $Optional<Any>
  %3 = init_enum_data_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  copy_addr [take] %1 to [init] %3 : $*Any
  inject_enum_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  %4 = init_existential_addr %0 : $*Proto, $StructWithEnum
  %5 = struct_element_addr %4 : $*StructWithEnum, #StructWithEnum.e
  %6 = init_enum_data_addr %5 : $*Enum, #Enum.A!enumelt
  copy_addr [take] %2 to [init] %6 : $*Optional<Any>
  inject_enum_addr %5 : $*Enum, #Enum.A!enumelt
  dealloc_stack %2 : $*Optional<Any>
  %10 = tuple ()
  return %10 : $()
}

// CHECK-LABEL: sil [ossa] @cant_move_projections :
// CHECK:   alloc_stack
// CHECK:   copy_addr
// CHECK:   load
// CHECK:   copy_addr
// CHECK: } // end sil function 'cant_move_projections'
sil [ossa] @cant_move_projections : $@convention(thin) (@in Any, @in_guaranteed Builtin.RawPointer) -> () {
bb0(%0 : $*Any, %1 : $*Builtin.RawPointer):
  %2 = alloc_stack $Optional<Any>
  %3 = init_enum_data_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  copy_addr [take] %0 to [init] %3 : $*Any
  inject_enum_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  %4 = load [trivial] %1 : $*Builtin.RawPointer
  %5 = pointer_to_address %4 : $Builtin.RawPointer to $*Optional<Any>
  copy_addr [take] %2 to [init] %5 : $*Optional<Any>
  dealloc_stack %2 : $*Optional<Any>
  %10 = tuple ()
  return %10 : $()
}

sil [ossa] @init_optional : $@convention(thin) () -> @out Optional<Any>

// CHECK-LABEL: sil [ossa] @instructions_after_copy_addr :
// CHECK:   alloc_stack
// CHECK:   copy_addr
// CHECK:   copy_addr
// CHECK:   apply
// CHECK: } // end sil function 'instructions_after_copy_addr'
sil [ossa] @instructions_after_copy_addr : $@convention(thin) (@in Any) -> @out Optional<Any> {
bb0(%0 : $*Optional<Any>, %1 : $*Any):
  %2 = alloc_stack $Optional<Any>
  %3 = init_enum_data_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  copy_addr [take] %1 to [init] %3 : $*Any
  inject_enum_addr %2 : $*Optional<Any>, #Optional.some!enumelt
  copy_addr [take] %2 to [init] %0 : $*Optional<Any>
  %4 = function_ref @init_optional : $@convention(thin) () -> @out Optional<Any>
  %5 = apply %4(%2) : $@convention(thin) () -> @out Optional<Any>
  destroy_addr %2 : $*Optional<Any>
  dealloc_stack %2 : $*Optional<Any>
  %6 = tuple ()
  return %6 : $()
}

// CHECK-LABEL: sil [ossa] @dont_optimize_swap :
// CHECK:   alloc_stack
// CHECK:   copy_addr
// CHECK:   copy_addr
// CHECK:   copy_addr
// CHECK:   dealloc_stack
// CHECK: } // end sil function 'dont_optimize_swap'
sil [ossa] @dont_optimize_swap : $@convention(thin) <T> (@inout T, @inout T) -> () {
bb0(%0 : $*T, %1 : $*T):
  %2 = alloc_stack $T
  copy_addr [take] %0 to [init] %2 : $*T
  copy_addr [take] %1 to [init] %0 : $*T
  copy_addr [take] %2 to [init] %1 : $*T
  dealloc_stack %2 : $*T
  %78 = tuple ()
  return %78 : $()
}

class Child { }

struct Parent {
  var c : Child
}

sil @gen_child : $@convention(thin) () -> @out Child

// Check that alias analysis is invalidated correctly and that the pass does
// not produce invalid SIL (which would trigger a MemoryLifetime failure).
//
// CHECK-LABEL: sil [ossa] @invalidateAliasAnalysis :
// CHECK:   copy_addr
// CHECK: } // end sil function 'invalidateAliasAnalysis'
sil [ossa] @invalidateAliasAnalysis : $@convention(thin) (@owned Child) -> () {
bb0(%0 :@owned  $Child):
  %2 = alloc_stack $Parent 
  %4 = alloc_stack $Child
  store %0 to [init] %4 : $*Child
  %7 = alloc_stack $Child 
  %func = function_ref @gen_child : $@convention(thin) () -> @out Child
  %10 = apply %func(%7) : $@convention(thin)() -> @out Child
  %11 = struct_element_addr %2 : $*Parent, #Parent.c
  copy_addr [take] %7 to [init] %11 : $*Child
  dealloc_stack %7 : $*Child
  copy_addr [take] %4 to %11 : $*Child
  %17 = tuple ()
  dealloc_stack %4 : $*Child
  destroy_addr %2 : $*Parent
  dealloc_stack %2 : $*Parent
  %res = tuple ()
  return %res : $()
}

// CHECK-LABEL: sil [ossa] @cleanup_debuginsts :
// CHECK:   copy_addr [take]
// CHECK-NOT: debug_value {{.*}} expr op_deref
// CHECK-LABEL: } // end sil function 'cleanup_debuginsts'
sil [ossa] @cleanup_debuginsts : $@convention(thin) <T> (@in T) -> () {
bb0(%0 : $*T):
  %2 = alloc_stack $T
  debug_value %0 : $*T, expr op_deref
  copy_addr %0 to [init] %2 : $*T
  debug_value %0 : $*T, expr op_deref
  destroy_addr %0 : $*T
  destroy_addr %2 : $*T
  dealloc_stack %2 : $*T
  %78 = tuple ()
  return %78 : $()
}

sil @createAny : $@convention(thin) () -> @out Any
sil @createAny_no_barrier : $@convention(thin) () -> @out Any {
 [global:]
}

// CHECK-LABEL: sil [ossa] @test_deinit_barrier :
// CHECK:         copy_addr [take]
// CHECK-LABEL: } // end sil function 'test_deinit_barrier'
sil [ossa] @test_deinit_barrier : $@convention(thin) (@guaranteed Any, @inout Any) -> () {
bb0(%0 : @guaranteed $Any, %1 : $*Any):
  %2 = alloc_stack $Any
  %4 = function_ref @createAny : $@convention(thin) () -> @out Any
  %5 = apply %4(%2) : $@convention(thin) () -> @out Any
  copy_addr [take] %2 to %1 : $*Any
  dealloc_stack %2 : $*Any
  %11 = tuple ()
  return %11 : $()
}

// CHECK-LABEL: sil [ossa] @test_no_deinit_barrier :
// CHECK-NOT:     copy_addr
// CHECK-LABEL: } // end sil function 'test_no_deinit_barrier'
sil [ossa] @test_no_deinit_barrier : $@convention(thin) (@guaranteed Any, @inout Any) -> () {
bb0(%0 : @guaranteed $Any, %1 : $*Any):
  %2 = alloc_stack $Any
  %4 = function_ref @createAny_no_barrier : $@convention(thin) () -> @out Any
  %5 = apply %4(%2) : $@convention(thin) () -> @out Any
  copy_addr [take] %2 to %1 : $*Any
  dealloc_stack %2 : $*Any
  %11 = tuple ()
  return %11 : $()
}