File: forwarding_utils.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 (283 lines) | stat: -rw-r--r-- 11,631 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
// RUN: %target-sil-opt -test-runner -enable-sil-opaque-values %s -o /dev/null 2>&1 | %FileCheck %s

// REQUIRES: swift_in_compiler

sil_stage raw

import Builtin

class C {
  init()
}

struct CPair {
  var a: C
  var b: C
}

public enum OptionalC {
  case none
  case some(C)
}

// Test all the basic singleForwarededOperand implementations.
//
// CHECK-LABEL: begin running test 1 of 2 on forwardingTest: forwarding_def_use_test with: %0
// CHECK: USE: operand #0 of   destroy_value %{{.*}} : $(OptionalC, C)
// CHECK-LABEL: end running test 1 of 2 on forwardingTest: forwarding_def_use_test with: %0
//
// CHECK-LABEL: begin running test 2 of 2 on forwardingTest: forwarding_use_def_test with: %final
// CHECK: INTRODUCER: %0 = argument of bb0 : $C
// CHECK: INTRODUCER: %1 = argument of bb0 : $C
// CHECK-LABEL: end running test 2 of 2 on forwardingTest: forwarding_use_def_test with: %final
sil [ossa] @forwardingTest : $@convention(thin) (@owned C, @owned C) -> () {
entry(%0 : @owned $C, %1 : @owned $C):
  %word0 = integer_literal $Builtin.Word, 0
  %word1 = integer_literal $Builtin.Word, 1
  %bridge = ref_to_bridge_object %0: $C, %word0: $Builtin.Word
  %ref = bridge_object_to_ref %bridge: $Builtin.BridgeObject to $C
  %dependence = mark_dependence %ref: $C on %1: $C
  %cast = unchecked_ref_cast %dependence: $C to $C
  %pair1 = struct $CPair (%cast: $C, %1: $C)
  (%pair_a, %pair_b) = destructure_struct %pair1: $CPair
  %optional = enum $OptionalC, #OptionalC.some!enumelt, %pair_a: $C
  %final = tuple (%optional: $OptionalC, %pair_b: $C)

  specify_test "forwarding_def_use_test %0"
  specify_test "forwarding_use_def_test %final"

  destroy_value %final: $(OptionalC, C)
  %void = tuple()
  return %void : $()
}

// In opaque SIL values mode, handle the tuple_pack_extract forwaded operand.
//
// CHECK-LABEL: begin running test 1 of 2 on tuplePackExtractTest: forwarding_def_use_test with: %tuple
// CHECK: USE: operand #0 of   end_borrow %1 : $(repeat each T)
// CHECK: USE: operand #0 of   %{{.*}} = copy_value %{{.*}} : $@pack_element("00000000-0000-0000-0000-000000000002") each U_1
// CHECK-LABEL: end running test 1 of 2 on tuplePackExtractTest: forwarding_def_use_test with: %tuple
//
// CHECK-LABEL: begin running test 2 of 2 on tuplePackExtractTest: forwarding_use_def_test with: %final
// CHECK: INTRODUCER: %1 = load_borrow %0 : $*(repeat each T)
// CHECK-LABEL: end running test 2 of 2 on tuplePackExtractTest: forwarding_use_def_test with: %final
sil [ossa] @tuplePackExtractTest : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> () {
entry(%tuple_addr : $*(repeat each T)):
  %tuple = load_borrow %tuple_addr : $*(repeat each T)
  %zero = integer_literal $Builtin.Word, 0
  %index = dynamic_pack_index %zero of $Pack{repeat each T}
  %opened = open_pack_element %index of <each U_1> at <Pack{repeat each T}>, shape $U_1, uuid "00000000-0000-0000-0000-000000000002"
  %final = tuple_pack_extract %index of %tuple : $(repeat each T) as $@pack_element("00000000-0000-0000-0000-000000000002") U_1

  specify_test "forwarding_def_use_test %tuple"
  specify_test "forwarding_use_def_test %final"

  %copy = copy_value %final : $@pack_element("00000000-0000-0000-0000-000000000002") U_1
  end_borrow %tuple : $(repeat each T)
  destroy_value %copy : $@pack_element("00000000-0000-0000-0000-000000000002") U_1
  %retval = tuple ()
  return %retval : $()
}

// Handle forwaded guaranteed values.
//
// CHECK-LABEL: begin running test 1 of 2 on forwardingGuaranteedTest: forwarding_def_use_test with: %0
// CHECK: USE: dead value:   %5 = tuple (%3 : $C, %4 : $C)
// CHECK-LABEL: end running test 1 of 2 on forwardingGuaranteedTest: forwarding_def_use_test with: %0
//
// CHECK-LABEL: begin running test 2 of 2 on forwardingGuaranteedTest: forwarding_use_def_test with: %t1
// CHECK: INTRODUCER: %0 = argument of bb0 : $C
// CHECK: INTRODUCER: %1 = argument of bb0 : $C
// CHECK-LABEL: end running test 2 of 2 on forwardingGuaranteedTest: forwarding_use_def_test with: %t1
sil [ossa] @forwardingGuaranteedTest : $@convention(thin) (@guaranteed C, @guaranteed C) -> () {
entry(%0 : @guaranteed $C, %1 : @guaranteed $C):
  %t0 = tuple (%0: $C, %1: $C)
  %t00 = tuple_extract %t0: $(C, C), 0
  %t01 = tuple_extract %t0: $(C, C), 1
  %t1 = tuple (%t00: $C, %t01: $C)

  specify_test "forwarding_def_use_test %0"
  specify_test "forwarding_use_def_test %t1"

  %void = tuple()
  return %void : $()
}

// A borrow scope currently intoduces a lifetime.
//
// CHECK-LABEL: begin running test 1 of 2 on forwardingBorrowTest: forwarding_def_use_test with: %0
// CHECK: USE: operand #0 of   destroy_value %0 : $CPair
// CHECK: USE: operand #0 of   %{{.*}} = begin_borrow %0 : $CPair
// CHECK-LABEL: end running test 1 of 2 on forwardingBorrowTest: forwarding_def_use_test with: %0
//
// CHECK-LABEL: begin running test 2 of 2 on forwardingBorrowTest: forwarding_use_def_test with: %field
// CHECK: INTRODUCER:   %{{.*}} = begin_borrow %0 : $CPair
// CHECK-LABEL: end running test 2 of 2 on forwardingBorrowTest: forwarding_use_def_test with: %field
sil [ossa] @forwardingBorrowTest : $@convention(thin) (@owned CPair) -> () {
entry(%0 : @owned $CPair):
  %borrow = begin_borrow %0 : $CPair
  %field = struct_extract %borrow: $CPair, #CPair.a

  specify_test "forwarding_def_use_test %0"
  specify_test "forwarding_use_def_test %field"

  end_borrow %borrow : $CPair
  destroy_value %0: $CPair  
  %void = tuple()
  return %void : $()
}  

// Test forwarding switch_enum.
//
// CHECK-LABEL: begin running test 1 of 2 on forwardingSwitchTest: forwarding_def_use_test with: %0
// CHECK: USE: operand #0 of   destroy_value %{{.*}} : $C
// CHECK-LABEL: end running test 1 of 2 on forwardingSwitchTest: forwarding_def_use_test with: %0
//
// CHECK-LABEL: begin running test 2 of 2 on forwardingSwitchTest: forwarding_use_def_test with: %result
// CHECK: INTRODUCER: %0 = argument of bb0 : $OptionalC
// CHECK-LABEL: end running test 2 of 2 on forwardingSwitchTest: forwarding_use_def_test with: %result
sil [ossa] @forwardingSwitchTest : $@convention(thin) (@owned OptionalC) -> () {
entry(%0 : @owned $OptionalC):
  specify_test "forwarding_def_use_test %0"
  switch_enum %0 : $OptionalC, case #OptionalC.some: bbSome, default bbNone

bbSome(%result: @owned $C):
  specify_test "forwarding_use_def_test %result"
  destroy_value %result: $C
  br bbExit

bbNone:
  br bbExit

bbExit:
  %void = tuple()
  return %void : $()
}

// Test forwarding checked_cast_br.
//
// CHECK-LABEL: begin running test 1 of 2 on forwardingCheckedCastTest: forwarding_def_use_test with: %0
// CHECK: USE: operand #0 of   destroy_value %{{.*}} : $C
// CHECK: USE: operand #0 of   destroy_value %{{.*}} : $C
// CHECK-LABEL: end running test 1 of 2 on forwardingCheckedCastTest: forwarding_def_use_test with: %0
//
// CHECK-LABEL: begin running test 2 of 2 on forwardingCheckedCastTest: forwarding_use_def_test with: %passResult
// CHECK: INTRODUCER: %0 = argument of bb0 : $C
// CHECK-LABEL: end running test 2 of 2 on forwardingCheckedCastTest: forwarding_use_def_test with: %passResult
sil [ossa] @forwardingCheckedCastTest : $@convention(thin) (@owned C) -> () {
entry(%0 : @owned $C):
  specify_test "forwarding_def_use_test %0"
  checked_cast_br C in %0 : $C to C, bbPass, bbFail

bbPass(%passResult: @owned $C):
  specify_test "forwarding_use_def_test %passResult"
  destroy_value %passResult: $C
  br bbExit

bbFail(%failResult: @owned $C):
  destroy_value %failResult: $C
  br bbExit

bbExit:
  %void = tuple()
  return %void : $()
}

// Test forwarding phis.
//
// CHECK-LABEL: begin running test 1 of 2 on forwardingPhiTest: forwarding_def_use_test with: %0
// CHECK: USE: operand #0 of   destroy_value %{{.*}} : $C
// CHECK-LABEL: end running test 1 of 2 on forwardingPhiTest: forwarding_def_use_test with: %0
//
// CHECK-LABEL: begin running test 2 of 2 on forwardingPhiTest: forwarding_use_def_test with: %cast
// CHECK: INTRODUCER: %0 = argument of bb0 : $C
// CHECK-LABEL: end running test 2 of 2 on forwardingPhiTest: forwarding_use_def_test with: %cast
sil [ossa] @forwardingPhiTest : $@convention(thin) (@owned C) -> () {
entry(%0 : @owned $C):
  specify_test "forwarding_def_use_test %0"
  br bbLoop(%0 : $C)

bbLoop(%loop : @owned $C):
  %cast = unchecked_ref_cast %loop: $C to $C
  cond_br undef, bbTail, bbExit

bbTail:
  br bbLoop(%cast: $C)

bbExit:
  specify_test "forwarding_use_def_test %cast"
  destroy_value %cast: $C
  %void = tuple()
  return %void : $()
}

// Chain of owned values. Needs to resolve in a resonable amount of time.
//
// CHECK-LABEL: begin running test 1 of 2 on forwardingTuplesTest: forwarding_def_use_test with: %0
// CHECK: USE: operand #0 of   destroy_value %{{.*}} : $(C, C)
// CHECK-LABEL: end running test 1 of 2 on forwardingTuplesTest: forwarding_def_use_test with: %0
//
// CHECK-LABEL: begin running test 2 of 2 on forwardingTuplesTest: forwarding_use_def_test with: %final
// CHECK: INTRODUCER: %0 = argument of bb0 : $C
// CHECK: INTRODUCER: %1 = argument of bb0 : $C
// CHECK-LABEL: end running test 2 of 2 on forwardingTuplesTest: forwarding_use_def_test with: %final
sil [ossa] @forwardingTuplesTest : $@convention(thin) (@owned C, @owned C) -> () {
entry(%0 : @owned $C, %1 : @owned $C):
  specify_test "forwarding_def_use_test %0"

  %t0 = tuple (%0: $C, %1: $C)
  (%t1_0, %t1_1) = destructure_tuple %t0: $(C, C)
  %t1 = tuple (%t1_0: $C, %t1_1: $C)
  (%t2_0, %t2_1) = destructure_tuple %t1: $(C, C)
  %t2 = tuple (%t2_0: $C, %t2_1: $C)
  (%t3_0, %t3_1) = destructure_tuple %t2: $(C, C)
  %t3 = tuple (%t3_0: $C, %t3_1: $C)
  (%t4_0, %t4_1) = destructure_tuple %t3: $(C, C)
  %t4 = tuple (%t4_0: $C, %t4_1: $C)
  (%t5_0, %t5_1) = destructure_tuple %t4: $(C, C)
  %t5 = tuple (%t5_0: $C, %t5_1: $C)
  (%t6_0, %t6_1) = destructure_tuple %t5: $(C, C)
  %t6 = tuple (%t6_0: $C, %t6_1: $C)
  (%t7_0, %t7_1) = destructure_tuple %t6: $(C, C)
  %t7 = tuple (%t7_0: $C, %t7_1: $C)
  (%t8_0, %t8_1) = destructure_tuple %t7: $(C, C)
  %t8 = tuple (%t8_0: $C, %t8_1: $C)
  (%t9_0, %t9_1) = destructure_tuple %t8: $(C, C)
  %t9 = tuple (%t9_0: $C, %t9_1: $C)
  (%t10_0, %t10_1) = destructure_tuple %t9: $(C, C)
  %t10 = tuple (%t10_0: $C, %t10_1: $C)
  (%t11_0, %t11_1) = destructure_tuple %t10: $(C, C)
  %t11 = tuple (%t11_0: $C, %t11_1: $C)
  (%t12_0, %t12_1) = destructure_tuple %t11: $(C, C)
  %t12 = tuple (%t12_0: $C, %t12_1: $C)
  (%t13_0, %t13_1) = destructure_tuple %t12: $(C, C)
  %t13 = tuple (%t13_0: $C, %t13_1: $C)
  (%t14_0, %t14_1) = destructure_tuple %t13: $(C, C)
  %t14 = tuple (%t14_0: $C, %t14_1: $C)
  (%t15_0, %t15_1) = destructure_tuple %t14: $(C, C)
  %t15 = tuple (%t15_0: $C, %t15_1: $C)
  (%t16_0, %t16_1) = destructure_tuple %t15: $(C, C)
  %t16 = tuple (%t16_0: $C, %t16_1: $C)
  (%t17_0, %t17_1) = destructure_tuple %t16: $(C, C)
  %t17 = tuple (%t17_0: $C, %t17_1: $C)
  (%t18_0, %t18_1) = destructure_tuple %t17: $(C, C)
  %t18 = tuple (%t18_0: $C, %t18_1: $C)
  (%t19_0, %t19_1) = destructure_tuple %t18: $(C, C)
  %t19 = tuple (%t19_0: $C, %t19_1: $C)
  (%t20_0, %t20_1) = destructure_tuple %t19: $(C, C)
  %t20 = tuple (%t20_0: $C, %t20_1: $C)
  (%t21_0, %t21_1) = destructure_tuple %t20: $(C, C)
  %t21 = tuple (%t21_0: $C, %t21_1: $C)
  (%t22_0, %t22_1) = destructure_tuple %t21: $(C, C)
  %t22 = tuple (%t22_0: $C, %t22_1: $C)
  (%t23_0, %t23_1) = destructure_tuple %t22: $(C, C)
  %t23 = tuple (%t23_0: $C, %t23_1: $C)
  (%t24_0, %t24_1) = destructure_tuple %t23: $(C, C)
  %final = tuple (%t24_0: $C, %t24_1: $C)

  specify_test "forwarding_use_def_test %final"

  destroy_value %final: $(C, C)
  %void = tuple()
  return %void : $()
}