File: sink.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 (250 lines) | stat: -rw-r--r-- 6,265 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
// RUN: %target-sil-opt -enable-sil-verify-all %s -code-sinking | %FileCheck %s

sil_stage canonical

import Builtin
import Swift
import SwiftShims

class X
{
  private func ping() -> Int
  deinit
  init()
}

class Y : X
{
  deinit
  override init()
}


sil @_TFC14devirt_access21X4pingfS0_FT_Si : $@convention(method) (@guaranteed X) -> Int
sil @_TFC14devirt_access21XcfMS0_FT_S0_ : $@convention(method) (@owned X) -> @owned X
sil @_TFC14devirt_access21XCfMS0_FT_S0_ : $@convention(thin) (@thick X.Type) -> @owned X
sil @_TFC14devirt_access21YcfMS0_FT_S0_ : $@convention(method) (@owned Y) -> @owned Y
sil @_TFC14devirt_access21YCfMS0_FT_S0_ : $@convention(thin) (@thick Y.Type) -> @owned Y


//CHECK-LABEL: sil @trivial_sink
//CHECK: bb1:
//CHECK-NEXT: upcast
//CHECK-NEXT: class_method
//CHECK-NEXT: apply
//CHECK: return
sil @trivial_sink : $@convention(thin) (@owned Y) -> Int {
bb0(%0 : $Y):
  debug_value %0 : $Y
  strong_retain %0 : $Y
  %3 = upcast %0 : $Y to $X
  %4 = class_method %3 : $X, #X.ping : (X) -> () -> Int, $@convention(method) (@guaranteed X) -> Int
  br bb1

bb1:
  %5 = apply %4(%3) : $@convention(method) (@guaranteed X) -> Int
  strong_release %0 : $Y
  return %5 : $Int
}

//CHECK-LABEL: sil @no_sink
//CHECK: upcast
//CHECK-NEXT: class_method
//CHECK-NEXT: cond_br
//CHECK: return
sil @no_sink : $@convention(thin) (@owned Y) -> Int {
bb0(%0 : $Y):
  debug_value %0 : $Y
  strong_retain %0 : $Y
  %3 = upcast %0 : $Y to $X
  %4 = class_method %3 : $X, #X.ping : (X) -> () -> Int, $@convention(method) (@guaranteed X) -> Int
  cond_br undef, bb1, bb2

bb1:
  %5 = apply %4(%3) : $@convention(method) (@guaranteed X) -> Int
  strong_release %0 : $Y
  br bb3

bb2:
  %9 = apply %4(%3) : $@convention(method) (@guaranteed X) -> Int
  strong_release %0 : $Y
  br bb3

bb3:
  return undef : $Int
}

//CHECK-LABEL: sil @cf_sink
//CHECK: bb1:
//CHECK-NEXT: upcast
//CHECK-NEXT: class_method
//CHECK-NEXT: apply
//CHECK-NOT: upcast
//CHECK: return
sil @cf_sink : $@convention(thin) (@owned Y) -> Int {
bb0(%0 : $Y):
  debug_value %0 : $Y
  strong_retain %0 : $Y
  %3 = upcast %0 : $Y to $X
  %4 = class_method %3 : $X, #X.ping : (X) -> () -> Int, $@convention(method) (@guaranteed X) -> Int
  cond_br undef, bb1, bb2

bb1:
  %5 = apply %4(%3) : $@convention(method) (@guaranteed X) -> Int
  strong_release %0 : $Y
  br bb3

bb2:
  strong_release %0 : $Y
  br bb3

bb3:
  return undef : $Int
}


//CHECK-LABEL: sil @sink_multi_blocks
//CHECK: bb4:
//CHECK-NEXT: upcast
//CHECK-NEXT: class_method
//CHECK-NEXT: apply
//CHECK-NOT: upcast
//CHECK: return
sil @sink_multi_blocks : $@convention(thin) (@owned Y) -> Int {
bb0(%0 : $Y):
  debug_value %0 : $Y
  strong_retain %0 : $Y
  %3 = upcast %0 : $Y to $X
  %4 = class_method %3 : $X, #X.ping : (X) -> () -> Int, $@convention(method) (@guaranteed X) -> Int
  br bb1

bb1:
  br bb2

bb2:
  br bb3

bb3:
  br bb4

bb4:
  %5 = apply %4(%3) : $@convention(method) (@guaranteed X) -> Int
  strong_release %0 : $Y
  return %5 : $Int
}


//CHECK-LABEL: sil @sink_loop
//CHECK: bb1:
//CHECK-NEXT: apply
//CHECK-NEXT: br bb1
//CHECK: return
sil @sink_loop : $@convention(thin) (@owned Y) -> Int {
bb0(%0 : $Y):
  debug_value %0 : $Y
  strong_retain %0 : $Y
  %3 = upcast %0 : $Y to $X
  %4 = class_method %3 : $X, #X.ping : (X) -> () -> Int, $@convention(method) (@guaranteed X) -> Int
  br bb1

// This is a loop!
bb1:
  %5 = apply %4(%3) : $@convention(method) (@guaranteed X) -> Int
  br bb1

bb2:
  strong_release %0 : $Y
  return undef : $Int
}


//CHECK-LABEL: sil @sink_nested_loop
//CHECK: bb0
//CHECK-NEXT: upcast
//CHECK-NEXT: class_method
//CHECK-NEXT: br bb1
//CHECK: return
sil @sink_nested_loop : $@convention(thin) (@owned Y) -> Int {
bb0(%0 : $Y):
  %3 = upcast %0 : $Y to $X
  %4 = class_method %3 : $X, #X.ping : (X) -> () -> Int, $@convention(method) (@guaranteed X) -> Int
  br bb1

bb1:
  br bb2

// This is a loop!
bb2:
  %5 = apply %4(%3) : $@convention(method) (@guaranteed X) -> Int
  cond_br undef, bb2, bb3

bb3:
  cond_br undef, bb3, bb1

bb4:
  strong_release %0 : $Y
  return undef : $Int
}

sil @takeY : $@convention(thin) (@guaranteed Y) -> ()

//CHECK-LABEL: sil @dont_sink_stack_allocs
//CHECK: alloc_ref [stack] $X
//CHECK: alloc_ref [stack] $Y
//CHECK: dealloc_stack_ref %{{[0-9]+}}  : $Y
//CHECK: dealloc_stack_ref %{{[0-9]+}}  : $X
//CHECK: return
sil @dont_sink_stack_allocs : $@convention(thin) () -> () {
bb0:
  %0 = alloc_ref [stack] $X
  %1 = alloc_ref [stack] $Y
  %f = function_ref @takeY : $@convention(thin) (@guaranteed Y) -> ()
  %a = apply %f(%1) : $@convention(thin) (@guaranteed Y) -> ()
  br bb1

bb1:
  strong_release %1 : $Y
  dealloc_stack_ref %1  : $Y
  strong_release %0 : $X
  dealloc_stack_ref %0  : $X

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

public protocol P : class {
  func foo() -> Int32
  func boo() -> Int32
}

// Check that open_existential is not moved after its uses and still
// dominates them after a run of a code sinking pass.
// CHECK-LABEL: sil @dont_sink_open_existential
// CHECK-NOT: metatype
// CHECK-NOT: witness_method
// CHECK: open_existential_ref
// CHECK: metatype
sil @dont_sink_open_existential : $@convention(thin) (@owned P) -> () {
bb0(%0 : $P):
  %1 = open_existential_ref %0 : $P to $@opened("C4960DBA-02C5-11E6-BE1B-B8E856428C60", P) Self
  %2 = metatype $@thick (@opened("C4960DBA-02C5-11E6-BE1B-B8E856428C60", P) Self).Type
  %3 = witness_method $@opened("C4960DBA-02C5-11E6-BE1B-B8E856428C60", P) Self, #P.foo, %1 : $@opened("C4960DBA-02C5-11E6-BE1B-B8E856428C60", P) Self : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@guaranteed τ_0_0) -> Int32
  br bb1

bb1:
  %4 = apply %3<@opened("C4960DBA-02C5-11E6-BE1B-B8E856428C60", P) Self>(%1) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@guaranteed τ_0_0) -> Int32
  strong_release %0 : $P
  %5 = tuple ()
  return %5 : $()
}

sil_vtable X {
  #X.ping: @_TFC14devirt_access21X4pingfS0_FT_Si	// devirt_access2.X.ping (devirt_access2.X)() -> Swift.Int
  #X.init!initializer: @_TFC14devirt_access21XcfMS0_FT_S0_	// devirt_access2.X.init (devirt_access2.X.Type)() -> devirt_access2.X
}

sil_vtable Y {
  #X.ping: @_TFC14devirt_access21X4pingfS0_FT_Si [inherited]
  #X.init!initializer: @_TFC14devirt_access21YcfMS0_FT_S0_ [override]
}