File: enclosing_def_unit.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 (320 lines) | stat: -rw-r--r-- 12,674 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
// RUN: %target-sil-opt -test-runner %s -o /dev/null 2>&1 | %FileCheck %s
//
// REQUIRES: swift_in_compiler

sil_stage raw

import Builtin

struct Trivial {
  var value: Builtin.Int32
}

enum FakeOptional<T> {
case none
case some(T)
}

struct PairC {
  var first: C
  var second: C
}

class C {
  var field: C
}

class D : C {}

// These introducers have no enclosing def.

// CHECK-LABEL: enclosing_def_empty: find-enclosing-defs with: %0
// CHECK: } // end sil function 'enclosing_def_empty'
// CHECK: Enclosing Defs:
// CHECK-NEXT: enclosing_def_empty: find-enclosing-defs with: %0

// CHECK-LABEL: enclosing_def_empty: enclosing_values with: %0
// CHECK: } // end sil function 'enclosing_def_empty'
// CHECK: Enclosing values for:  %0 = argument of bb0 : $C
// CHECK-NEXT: enclosing_def_empty: enclosing_values with: %0

// CHECK-LABEL: enclosing_def_empty: find-enclosing-defs with: %borrow1
// CHECK: } // end sil function 'enclosing_def_empty'
// CHECK: Enclosing Defs:
// CHECK-NEXT: enclosing_def_empty: find-enclosing-defs with: %borrow1

// CHECK-LABEL: enclosing_def_empty: enclosing_values with: %borrow1
// CHECK: } // end sil function 'enclosing_def_empty'
// CHECK: Enclosing values for: %{{.*}} = load_borrow %1 : $*C
// CHECK-NEXT: enclosing_def_empty: enclosing_values with: %borrow1
sil [ossa] @enclosing_def_empty : $@convention(thin) (@guaranteed C, @in C) -> () {
entry(%0 : @guaranteed $C, %1 : $*C):
  specify_test "find-enclosing-defs %0"
  specify_test "enclosing_values %0"
  %borrow1 = load_borrow %1 : $*C
  specify_test "find-enclosing-defs %borrow1"
  specify_test "enclosing_values %borrow1"
  end_borrow %borrow1 : $C
  destroy_addr %1 : $*C
  %retval = tuple ()
  return %retval : $()
}

// There is no introducer if the guaranteed value is produced from a
// trivial value.

// CHECK-LABEL: enclosing_def_trivial: find-enclosing-defs with: %phi
// CHECK: } // end sil function 'enclosing_def_trivial'
// CHECK: Enclosing Defs:
// CHECK-NEXT: enclosing_def_trivial: find-enclosing-defs with: %phi

// CHECK-LABEL: enclosing_def_trivial: enclosing_values with: %phi
// CHECK: } // end sil function 'enclosing_def_trivial'
// CHECK: Enclosing values for: %{{.*}} = argument of bb1 : $FakeOptional<C>
// CHECK-NEXT: enclosing_def_trivial: enclosing_values with: %phi
sil [ossa] @enclosing_def_trivial : $@convention(thin) () -> () {
entry:
  %trivial = enum $FakeOptional<C>, #FakeOptional.none!enumelt
  br none(%trivial : $FakeOptional<C>)

none(%phi : @guaranteed $FakeOptional<C>):
  specify_test "find-enclosing-defs %phi"
  specify_test "enclosing_values %phi"
  %retval = tuple ()
  return %retval : $()
}

// There is an introducer but no enclosing def if the guaranteed value
// is produced from a an unreachable loop.

// CHECK-LABEL: enclosing_def_unreachable: find-enclosing-defs with: %phiCycle
// CHECK: } // end sil function 'enclosing_def_unreachable'
// CHECK: Enclosing Defs:
// CHECK-NEXT: enclosing_def_unreachable: find-enclosing-defs with: %phiCycle

// CHECK-LABEL: enclosing_def_unreachable: enclosing_values with: %phiCycle
// CHECK: } // end sil function 'enclosing_def_unreachable'
// CHECK: Enclosing values for: %{{.*}} = argument of bb1 : $C
// CHECK-NEXT: enclosing_def_unreachable: enclosing_values with: %phiCycle
sil [ossa] @enclosing_def_unreachable : $@convention(thin) () ->() {
entry:
  br exit

unreachable_loop(%phiCycle : @guaranteed $C):
  specify_test "find-enclosing-defs %phiCycle"
  specify_test "enclosing_values %phiCycle"
  br unreachable_loop(%phiCycle : $C)

exit:
  %retval = tuple ()
  return %retval : $()
}

// All data flow paths through phis and aggregates originate from the
// same borrow scope. This is the same as finding the introducer.

// CHECK-LABEL: enclosing_def_single_introducer: find-enclosing-defs with: %aggregate2
// CHECK: sil [ossa] @enclosing_def_single_introducer
// CHECK: Enclosing Defs:
// CHECK:   begin_borrow %0 : $C
// CHECK-NEXT: enclosing_def_single_introducer: find-enclosing-defs with: %aggregate2

// CHECK-LABEL: enclosing_def_single_introducer: enclosing_values with: %aggregate2
// CHECK: sil [ossa] @enclosing_def_single_introducer
// CHECK: Enclosing values for: %{{.*}} = struct $PairC (%10 : $C, %11 : $C)
// CHECK:   begin_borrow %0 : $C
// CHECK-NEXT: enclosing_def_single_introducer: enclosing_values with: %aggregate2
sil [ossa] @enclosing_def_single_introducer : $@convention(thin) (@guaranteed C) -> () {
entry(%0 : @guaranteed $C):
  %borrow = begin_borrow %0 : $C
  %cast = unconditional_checked_cast %borrow : $C to D
  %some = enum $FakeOptional<D>, #FakeOptional.some!enumelt, %cast : $D
  br switch(%some : $FakeOptional<D>)

switch(%somePhi : @guaranteed $FakeOptional<D>):
  switch_enum %somePhi : $FakeOptional<D>, case #FakeOptional.some!enumelt: bb1, case #FakeOptional.none!enumelt: bb2

bb1(%payload : @guaranteed $D):
  %upcast = upcast %payload : $D to $C
  %aggregate = struct $PairC(%upcast : $C, %borrow : $C)
  %first = struct_extract %aggregate : $PairC, #PairC.first
  %second = struct_extract %aggregate : $PairC, #PairC.second
  %aggregate2 = struct $PairC(%first : $C, %second : $C)
  specify_test "find-enclosing-defs %aggregate2"
  specify_test "enclosing_values %aggregate2"
  br exit

bb2:
  br exit

exit:
  end_borrow %borrow : $C
  %retval = tuple ()
  return %retval : $()
}

// All reborrows original from the same dominating borrow scope.

// CHECK: enclosing_def_single_outer: find-enclosing-defs with: %reborrow3
// CHECK: } // end sil function 'enclosing_def_single_outer'
// CHECK: Enclosing Defs:
// CHECK-NEXT: %0 = argument of bb0 : $C
// CHECK-NEXT: enclosing_def_single_outer: find-enclosing-defs with: %reborrow3

// CHECK: enclosing_def_single_outer: enclosing_values with: %reborrow3
// CHECK: } // end sil function 'enclosing_def_single_outer'
// CHECK: Enclosing values for:  %{{.*}} = argument of bb2 : $C
// CHECK-NEXT: %0 = argument of bb0 : $C
// CHECK-NEXT: enclosing_def_single_outer: enclosing_values with: %reborrow3

sil [ossa] @enclosing_def_single_outer : $@convention(thin) (@guaranteed C) -> () {
entry(%0 : @guaranteed $C):
  %borrow = begin_borrow %0 : $C
  br bb2(%borrow : $C)

bb2(%reborrow2 : @guaranteed $C):
  br bb3(%reborrow2 : $C)

bb3(%reborrow3 : @guaranteed $C):
  specify_test "find-enclosing-defs %reborrow3"
  specify_test "enclosing_values %reborrow3"
  end_borrow %reborrow3 : $C
  %retval = tuple ()
  return %retval : $()
}

// Find the outer enclosingreborrow.

// CHECK-LABEL: enclosing_def_reborrow: find-enclosing-defs with: %reborrow_inner3
// CHECK: sil [ossa] @enclosing_def_reborrow : $@convention(thin) (@guaranteed C) -> () {
// CHECK: bb1([[REBORROW:%.*]] : @reborrow @guaranteed $C, %{{.*}} : @reborrow @guaranteed $C):
// CHECK: } // end sil function 'enclosing_def_reborrow'
// CHECK: Enclosing Defs:
// CHECK-NEXT: [[REBORROW]] = argument of bb1 : $C
// CHECK-NEXT: enclosing_def_reborrow: find-enclosing-defs with: %reborrow_inner3

// CHECK-LABEL: enclosing_def_reborrow: enclosing_values with: %reborrow_inner3
// CHECK: sil [ossa] @enclosing_def_reborrow : $@convention(thin) (@guaranteed C) -> () {
// CHECK: bb1([[REBORROW:%.*]] : @reborrow @guaranteed $C, %{{.*}} : @reborrow @guaranteed $C):
// CHECK: } // end sil function 'enclosing_def_reborrow'
// CHECK: Enclosing values for: %{{.*}} = argument of bb2 : $C
// CHECK-NEXT: [[REBORROW]] = argument of bb1 : $C
// CHECK-NEXT: enclosing_def_reborrow: enclosing_values with: %reborrow_inner3
sil [ossa] @enclosing_def_reborrow : $@convention(thin) (@guaranteed C) -> () {
entry(%0 : @guaranteed $C):
  %borrow_outer = begin_borrow %0 : $C
  %borrow_inner = begin_borrow %borrow_outer : $C
  br bb2(%borrow_outer : $C, %borrow_inner : $C)

bb2(%reborrow_outer : @guaranteed $C, %reborrow_inner : @guaranteed $C):
  br bb3(%reborrow_inner : $C)

bb3(%reborrow_inner3 : @guaranteed $C):
  specify_test "find-enclosing-defs %reborrow_inner3"
  specify_test "enclosing_values %reborrow_inner3"
  end_borrow %reborrow_inner3 : $C
  end_borrow %reborrow_outer : $C
  %retval = tuple ()
  return %retval : $()
}

// The enclosing def of a forwarding phi cycle is the reborrow phi cycle.

// CHECK-LABEL: enclosing_def_cycle: find-enclosing-defs with: %forward
// CHECK: sil [ossa] @enclosing_def_cycle : $@convention(thin) (@guaranteed C) -> () {
// CHECK: bb1([[REBORROW:%.*]] : @reborrow @guaranteed $C,
// CHECK: } // end sil function 'enclosing_def_cycle'
// CHECK: Enclosing Defs:
// CHECK-NEXT: [[REBORROW]] = argument of bb1 : $C
// CHECK-NEXT: enclosing_def_cycle: find-enclosing-defs with: %forward

// CHECK-LABEL: enclosing_def_cycle: enclosing_values with: %forward
// CHECK: sil [ossa] @enclosing_def_cycle : $@convention(thin) (@guaranteed C) -> () {
// CHECK: bb1([[REBORROW:%.*]] : @reborrow @guaranteed $C,
// CHECK: } // end sil function 'enclosing_def_cycle'
// CHECK: Enclosing values for: %{{.*}} = argument of bb1 : $C
// CHECK-NEXT: [[REBORROW]] = argument of bb1 : $C
// CHECK-NEXT: enclosing_def_cycle: enclosing_values with: %forward
sil [ossa] @enclosing_def_cycle : $@convention(thin) (@guaranteed C) -> () {
entry(%0 : @guaranteed $C):
  %borrow = begin_borrow %0 : $C
  %aggregate1 = struct $PairC(%borrow : $C, %borrow : $C)
  %first1 = struct_extract %aggregate1 : $PairC, #PairC.first
  br bb2(%borrow : $C, %first1 : $C)

bb2(%reborrow_outer : @guaranteed $C, %forward : @guaranteed $C):
  specify_test "find-enclosing-defs %forward"
  specify_test "enclosing_values %forward"
  %aggregate2 = struct $PairC(%reborrow_outer : $C, %forward : $C)
  %first2 = struct_extract %aggregate2 : $PairC, #PairC.first
  br bb2(%reborrow_outer : $C, %first2 : $C)

exit:
  %retval = tuple ()
  return %retval : $()
}

// CHECK-LABEL: enclosing_def_example: enclosing_values with: %0
// CHECK: Enclosing values for: %0 = argument of bb0 : $C
// CHECK-NEXT: enclosing_def_example: enclosing_values with: %0

// CHECK-LABEL: enclosing_def_example: enclosing_values with: %borrow0
// CHECK: Enclosing values for:   %{{.*}} = begin_borrow %0 : $C
// CHECK-NEXT: %0 = argument of bb0 : $C
// CHECK-NEXT: enclosing_def_example: enclosing_values with: %borrow0

// CHECK-LABEL: enclosing_def_example: enclosing_values with: %first
// CHECK: Enclosing values for:   %{{.*}} = struct_extract %{{.*}} : $PairC, #PairC.first
// CHECK-NEXT:   %{{.*}} = begin_borrow %0 : $C
// CHECK-NEXT:   %{{.*}} = argument of bb0 : $C
// CHECK-NEXT: enclosing_def_example: enclosing_values with: %first

// CHECK-LABEL: enclosing_def_example: enclosing_values with: %field
// CHECK: Enclosing values for:   %{{.*}} = ref_element_addr %{{.*}} : $C, #C.field
// CHECK-NEXT: enclosing_def_example: enclosing_values with: %field

// CHECK-LABEL: enclosing_def_example: enclosing_values with: %load
// CHECK: Enclosing values for:   %{{.*}} = load_borrow %{{.*}} : $*C
// CHECK-NEXT: enclosing_def_example: enclosing_values with: %load
sil [ossa] @enclosing_def_example : $@convention(thin) (@owned C, @guaranteed C) -> () {
bb0(%0 : @owned $C,
    %1 : @guaranteed $C):
  specify_test "enclosing_values %0"
  %borrow0 = begin_borrow %0 : $C
  specify_test "enclosing_values %borrow0"
  %pair = struct $PairC(%borrow0 : $C, %1 : $C)
  %first = struct_extract %pair : $PairC, #PairC.first
  specify_test "enclosing_values %first"
  %field = ref_element_addr %first : $C, #C.field
  specify_test "enclosing_values %field"
  %load = load_borrow %field : $*C
  specify_test "enclosing_values %load"
  end_borrow %load : $C
  end_borrow %borrow0 : $C
  destroy_value %0 : $C
  %retval = tuple ()
  return %retval : $()
}

// CHECK-LABEL: enclosing_def_reborrow_example: enclosing_values with: %outerReborrow
// CHECK: Enclosing values for: %{{.*}} = argument of bb1 : $C
// CHECK-NEXT: %0 = argument of bb0 : $C
// CHECK-NEXT: enclosing_def_reborrow_example: enclosing_values with: %outerReborrow

// CHECK-LABEL: enclosing_def_reborrow_example: enclosing_values with: %innerReborrow
// CHECK: Enclosing values for: %{{.*}} = argument of bb1 : $C
// CHECK-NEXT: %{{.*}} = argument of bb1 : $C
// CHECK-NEXT: enclosing_def_reborrow_example: enclosing_values with: %innerReborrow
sil [ossa] @enclosing_def_reborrow_example : $@convention(thin) (@guaranteed C) -> () {
bb0(%0 : @guaranteed $C):
  %outerBorrow = begin_borrow %0 : $C
  %innerBorrow = begin_borrow %outerBorrow : $C
  br bb1(%outerBorrow : $C, %innerBorrow : $C)
bb1(%outerReborrow : @guaranteed $C, %innerReborrow : @guaranteed $C):  
  specify_test "enclosing_values %outerReborrow"
  specify_test "enclosing_values %innerReborrow"
  end_borrow %innerReborrow : $C
  end_borrow %outerReborrow : $C
  %retval = tuple ()
  return %retval : $()
}