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 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
|
// First parse this and then emit a *.sib. Then read in the *.sib, then recreate
// RUN: %empty-directory(%t)
// RUN: %target-sil-opt %s -emit-sib -o %t/tmp.sib -module-name basic2 -enable-experimental-feature ValueGenerics
// RUN: %target-sil-opt %t/tmp.sib -o %t/tmp.2.sib -module-name basic2 -enable-experimental-feature ValueGenerics
// RUN: %target-sil-opt %t/tmp.2.sib -module-name basic2 -emit-sorted-sil -enable-experimental-feature ValueGenerics | %FileCheck %s
// REQUIRES: swift_feature_ValueGenerics
import Builtin
import Swift
class C {}
class Klass {}
sil @getC : $@convention(thin) () -> (@owned C)
sil @getKlass : $@convention(thin) () -> (@owned Klass)
// CHECK-LABEL: sil [ossa] @merge_isolation_region : $@convention(thin) (@guaranteed Klass) -> () {
// CHECK: merge_isolation_region %0 : $Klass, %1 : $*C
// CHECK: merge_isolation_region %1 : $*C, %0 : $Klass, %0 : $Klass
// CHECK: } // end sil function 'merge_isolation_region'
sil [ossa] @merge_isolation_region : $@convention(thin) (@guaranteed Klass) -> () {
bb0(%0 : @guaranteed $Klass):
%1 = alloc_stack $C
merge_isolation_region %0 : $Klass, %1 : $*C
merge_isolation_region %1 : $*C, %0 : $Klass, %0 : $Klass
dealloc_stack %1 : $*C
%9999 = tuple ()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @test_allocbox_moveable_value_debuginfo_flag : $@convention(thin) () -> () {
// CHECK: alloc_box [moveable_value_debuginfo] ${ var Builtin.NativeObject }
// CHECK: } // end sil function 'test_allocbox_moveable_value_debuginfo_flag'
sil [ossa] @test_allocbox_moveable_value_debuginfo_flag : $@convention(thin) () -> () {
bb0:
%0 = alloc_box [moveable_value_debuginfo] ${ var Builtin.NativeObject }
dealloc_box %0 : ${ var Builtin.NativeObject }
%9999 = tuple()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @test_copyable_to_moveonlywrapper : $@convention(thin) (@owned Builtin.NativeObject) -> () {
// CHECK: copyable_to_moveonlywrapper [owned]
// CHECK: } // end sil function 'test_copyable_to_moveonlywrapper'
sil [ossa] @test_copyable_to_moveonlywrapper : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
%0a = copyable_to_moveonlywrapper [owned] %0 : $Builtin.NativeObject
destroy_value %0a : $@moveOnly Builtin.NativeObject
%9999 = tuple()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @test_copyable_to_moveonlywrapper_addr : $@convention(thin) (@in Builtin.NativeObject) -> () {
// CHECK: copyable_to_moveonlywrapper_addr
// CHECK: } // end sil function 'test_copyable_to_moveonlywrapper_addr'
sil [ossa] @test_copyable_to_moveonlywrapper_addr : $@convention(thin) (@in Builtin.NativeObject) -> () {
bb0(%0 : $*Builtin.NativeObject):
%0a = copyable_to_moveonlywrapper_addr %0 : $*Builtin.NativeObject
destroy_addr %0a : $*@moveOnly Builtin.NativeObject
%9999 = tuple()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @test_dealloc_box : {{.*}} {
// CHECK: cond_br undef, [[EXIT:bb[0-9]+]], [[DIE:bb[0-9]+]]
// CHECK: [[DIE]]:
// CHECK: dealloc_box [dead_end]
// CHECK: unreachable
// CHECK: [[EXIT]]:
// CHECK: dealloc_box
// CHECK-LABEL: } // end sil function 'test_dealloc_box'
sil [ossa] @test_dealloc_box : $@convention(thin) () -> () {
entry:
%b = alloc_box ${ var C }
cond_br undef, exit, die
exit:
dealloc_box %b : ${ var C }
%retval = tuple()
return %retval : $()
die:
dealloc_box [dead_end] %b : ${ var C }
unreachable
}
// We don't serialize debug_value today... but we should.
//
// CHECK-LABEL: sil [ossa] @test_debug_value_alloc_stack_moved : $@convention(thin) (@owned Builtin.NativeObject) -> () {
// CHECK: %1 = alloc_stack [moveable_value_debuginfo] $Builtin.NativeObject
// CHECK: } // end sil function 'test_debug_value_alloc_stack_moved'
sil [ossa] @test_debug_value_alloc_stack_moved : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
debug_value [moveable_value_debuginfo] %0 : $Builtin.NativeObject
debug_value [poison] %0 : $Builtin.NativeObject
debug_value [moveable_value_debuginfo] [poison] %0 : $Builtin.NativeObject
debug_value [poison] [moveable_value_debuginfo] %0 : $Builtin.NativeObject
%1 = alloc_stack [moveable_value_debuginfo] $Builtin.NativeObject
dealloc_stack %1 : $*Builtin.NativeObject
destroy_value %0 : $Builtin.NativeObject
%9999 = tuple()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @test_destroy_value : {{.*}} {
// CHECK: cond_br undef, [[GOOD:bb[0-9]+]], [[BAD:bb[0-9]+]]
// CHECK: [[BAD]]:
// CHECK: cond_br undef, [[BLEFT:bb[0-9]+]], [[BRIGHT:bb[0-9]+]]
// CHECK: [[BRIGHT]]:
// CHECK: %3 = apply %0()
// CHECK: destroy_value [poison] [dead_end] %3
// CHECK: unreachable
// CHECK: [[BLEFT]]:
// CHECK: %6 = apply %0()
// CHECK: destroy_value [dead_end] %6
// CHECK: unreachable
// CHECK: [[GOOD]]:
// CHECK: cond_br undef, [[GLEFT:bb[0-9]+]], [[GRIGHT:bb[0-9]+]]
// CHECK: [[GRIGHT]]:
// CHECK: %10 = apply %0()
// CHECK: destroy_value [poison] %10
// CHECK: br [[EXIT:bb[0-9]+]]
// CHECK: [[GLEFT]]:
// CHECK: %13 = apply %0()
// CHECK: destroy_value %13
// CHECK: br [[EXIT]]
// CHECK: [[EXIT]]:
// CHECK-LABEL: } // end sil function 'test_destroy_value'
sil [ossa] @test_destroy_value : $@convention(thin) () -> () {
entry:
%getC = function_ref @getC : $@convention(thin) () -> (@owned C)
cond_br undef, good, bad
good:
cond_br undef, gleft, gright
gleft:
%k1 = apply %getC() : $@convention(thin) () -> (@owned C)
destroy_value %k1 : $C
br exit
gright:
%k2 = apply %getC() : $@convention(thin) () -> (@owned C)
destroy_value [poison] %k2 : $C
br exit
exit:
%retval = tuple()
return %retval : $()
bad:
cond_br undef, bleft, bright
bleft:
%k3 = apply %getC() : $@convention(thin) () -> (@owned C)
destroy_value [dead_end] %k3 : $C
unreachable
bright:
%k4 = apply %getC() : $@convention(thin) () -> (@owned C)
destroy_value [poison] [dead_end] %k4 : $C
unreachable
}
// CHECK-LABEL: sil [ossa] @test_explicit_copy_addr : $@convention(thin) (@owned Builtin.NativeObject) -> () {
// CHECK: explicit_copy_addr %{{[0-9]+}} to [init] %{{[0-9]+}} :
// CHECK: explicit_copy_addr [take] %{{[0-9]+}} to [init] %{{[0-9]+}} :
// CHECK: explicit_copy_addr [take] %{{[0-9]+}} to %{{[0-9]+}} :
// CHECK: explicit_copy_addr %{{[0-9]+}} to %{{[0-9]+}} :
// CHECK: } // end sil function 'test_explicit_copy_addr'
sil [ossa] @test_explicit_copy_addr : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
%1 = alloc_stack $Builtin.NativeObject
%2 = alloc_stack $Builtin.NativeObject
%3 = alloc_stack $Builtin.NativeObject
%0a = copy_value %0 : $Builtin.NativeObject
store %0a to [init] %1 : $*Builtin.NativeObject
explicit_copy_addr %1 to [init] %2 : $*Builtin.NativeObject
explicit_copy_addr [take] %2 to [init] %3 : $*Builtin.NativeObject
explicit_copy_addr [take] %3 to %1 : $*Builtin.NativeObject
store %0 to [init] %2 : $*Builtin.NativeObject
explicit_copy_addr %1 to %2 : $*Builtin.NativeObject
destroy_addr %2 : $*Builtin.NativeObject
destroy_addr %1 : $*Builtin.NativeObject
dealloc_stack %3 : $*Builtin.NativeObject
dealloc_stack %2 : $*Builtin.NativeObject
dealloc_stack %1 : $*Builtin.NativeObject
%9999 = tuple()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @test_extend_lifetime : {{.*}} {
// CHECK: bb0([[K:%[^,]+]] :
// CHECK: br [[LOOP:bb[0-9]+]]
// CHECK: [[LOOP]]:
// CHECK: extend_lifetime [[K]]
// CHECK: br [[LOOP]]
// CHECK-LABEL: } // end sil function 'test_extend_lifetime'
sil [ossa] @test_extend_lifetime : $@convention(thin) (@owned Builtin.NativeObject) -> () {
entry(%k : @owned $Builtin.NativeObject):
br bb1
bb1:
extend_lifetime %k : $Builtin.NativeObject
br bb1
}
// CHECK-LABEL: sil [ossa] @test_mark_dependence : $@convention(thin) (@owned Builtin.NativeObject, @owned Builtin.NativeObject) -> () {
// CHECK: [[MD1:%.*]] = mark_dependence %1 : $Builtin.NativeObject on %0 : $Builtin.NativeObject
// CHECK: [[MD2:%.*]] = mark_dependence [nonescaping] [[MD1]] : $Builtin.NativeObject on %0 : $Builtin.NativeObject
// CHECK: mark_dependence [unresolved] [[MD2]] : $Builtin.NativeObject on %0 : $Builtin.NativeObject
// CHECK: } // end sil function 'test_mark_dependence'
sil [ossa] @test_mark_dependence : $@convention(thin) (@owned Builtin.NativeObject, @owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject, %1 : @owned $Builtin.NativeObject):
%md1 = mark_dependence %1 : $Builtin.NativeObject on %0 : $Builtin.NativeObject
%md2 = mark_dependence [nonescaping] %md1 : $Builtin.NativeObject on %0 : $Builtin.NativeObject
%md3 = mark_dependence [unresolved] %md2 : $Builtin.NativeObject on %0 : $Builtin.NativeObject
destroy_value %md3 : $Builtin.NativeObject
destroy_value %0 : $Builtin.NativeObject
%9999 = tuple()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @test_moveonlywrapper_to_copyable_addr : $@convention(thin) (@in Builtin.NativeObject) -> () {
// CHECK: moveonlywrapper_to_copyable_addr
// CHECK: } // end sil function 'test_moveonlywrapper_to_copyable_addr'
sil [ossa] @test_moveonlywrapper_to_copyable_addr : $@convention(thin) (@in Builtin.NativeObject) -> () {
bb0(%0 : $*Builtin.NativeObject):
%1 = alloc_stack $@moveOnly Builtin.NativeObject
%1a = moveonlywrapper_to_copyable_addr %1 : $*@moveOnly Builtin.NativeObject
copy_addr [take] %0 to [init] %1a : $*Builtin.NativeObject
destroy_addr %1 : $*@moveOnly Builtin.NativeObject
dealloc_stack %1 : $*@moveOnly Builtin.NativeObject
%9999 = tuple()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @test_moveonlywrapper_to_copyable_box : $@convention(thin) () -> () {
// CHECK: [[BOX:%.*]] = alloc_box ${ var @moveOnly Builtin.NativeObject }
// CHECK: [[CAST:%.*]] = moveonlywrapper_to_copyable_box [[BOX]] : ${ var @moveOnly Builtin.NativeObject }
// CHECK: dealloc_box [[CAST]] : ${ var Builtin.NativeObject }
// CHECK: } // end sil function 'test_moveonlywrapper_to_copyable_box'
sil [ossa] @test_moveonlywrapper_to_copyable_box : $@convention(thin) () -> () {
bb0:
%0 = alloc_box ${ var @moveOnly Builtin.NativeObject }
%1 = moveonlywrapper_to_copyable_box %0 : ${ var @moveOnly Builtin.NativeObject }
dealloc_box %1 : ${ var Builtin.NativeObject }
%9999 = tuple ()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @test_type_value : $@convention(thin) <let N : Int> () -> Int {
// CHECK: [[VAL:%.*]] = type_value $Int for N
// CHECK: return [[VAL]] : $Int
// CHECK-LABEL: } // end sil function 'test_type_value'
sil [ossa] @test_type_value : $@convention(thin) <let N : Int> () -> Int {
entry:
%val = type_value $Int for N
return %val : $Int
}
// CHECK-LABEL: sil @thunk_inst : $@convention(thin) () -> () {
// CHECK: [[FUNC:%[0-9]+]] = function_ref @getKlass : $@convention(thin) () -> @owned Klass
// CHECK: %{{.*}} = thunk [identity] [[FUNC]]() : $@convention(thin) () -> @owned Klass
// CHECK: } // end sil function 'thunk_inst'
sil @thunk_inst : $@convention(thin) () -> () {
bb0:
%0 = function_ref @getKlass : $@convention(thin) () -> (@owned Klass)
%1 = thunk [identity] %0() : $@convention(thin) () -> @owned Klass
%9999 = tuple ()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @thunk_inst_ossa : $@convention(thin) () -> () {
// CHECK: [[FUNC:%[0-9]+]] = function_ref @getKlass : $@convention(thin) () -> @owned Klass
// CHECK: %{{.*}} = thunk [identity] [[FUNC]]() : $@convention(thin) () -> @owned Klass
// CHECK: } // end sil function 'thunk_inst_ossa'
sil [ossa] @thunk_inst_ossa : $@convention(thin) () -> () {
bb0:
%0 = function_ref @getKlass : $@convention(thin) () -> @owned Klass
%1 = thunk [identity] %0() : $@convention(thin) () -> @owned Klass
destroy_value %1 : $@callee_guaranteed () -> @owned Klass
%9999 = tuple ()
return %9999 : $()
}
sil @generic_func : $@convention(thin) <T> (@in T) -> ()
// CHECK-LABEL: sil [ossa] @thunk_inst_ossa_generic : $@convention(thin) () -> () {
// CHECK: [[FUNC:%[0-9]+]] = function_ref @generic_func : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
// CHECK: {{%.*}} = thunk [identity] [[FUNC]]<Klass>() : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
// CHECK: } // end sil function 'thunk_inst_ossa_generic'
sil [ossa] @thunk_inst_ossa_generic : $@convention(thin) () -> () {
bb0:
%0 = function_ref @generic_func : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
%1 = thunk [identity] %0<Klass>() : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
destroy_value %1 : $@callee_guaranteed (@in Klass) -> ()
%9999 = tuple ()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @tuple_addr_constructor_assign : $@convention(thin) (@in Builtin.NativeObject, @in (Builtin.NativeObject, Builtin.NativeObject)) -> () {
// CHECK: bb0([[LHS:%.*]] : $*Builtin.NativeObject,
// CHECK: [[RHS:%.*]] = alloc_stack $Builtin.NativeObject
// CHECK: [[DEST:%.*]] = alloc_stack $(Builtin.NativeObject, Builtin.NativeObject)
// CHECK: tuple_addr_constructor [assign] [[DEST]] : $*(Builtin.NativeObject, Builtin.NativeObject) with ([[LHS]] : $*Builtin.NativeObject, [[RHS]] : $*Builtin.NativeObject)
// CHECK: } // end sil function 'tuple_addr_constructor_assign'
sil [ossa] @tuple_addr_constructor_assign : $@convention(thin) (@in Builtin.NativeObject, @in (Builtin.NativeObject, Builtin.NativeObject)) -> () {
bb0(%0 : $*Builtin.NativeObject, %0a : $*(Builtin.NativeObject, Builtin.NativeObject)):
%1 = alloc_stack $Builtin.NativeObject
copy_addr %0 to [init] %1 : $*Builtin.NativeObject
%2 = alloc_stack $(Builtin.NativeObject, Builtin.NativeObject)
copy_addr [take] %0a to [init] %2 : $*(Builtin.NativeObject, Builtin.NativeObject)
tuple_addr_constructor [assign] %2 : $*(Builtin.NativeObject, Builtin.NativeObject) with (%0 : $*Builtin.NativeObject, %1 : $*Builtin.NativeObject)
destroy_addr %2 : $*(Builtin.NativeObject, Builtin.NativeObject)
destroy_addr %1 : $*Builtin.NativeObject
dealloc_stack %2 : $*(Builtin.NativeObject, Builtin.NativeObject)
dealloc_stack %1 : $*Builtin.NativeObject
%9999 = tuple ()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @tuple_addr_constructor_differing_category : $@convention(thin) (@in Builtin.NativeObject, @owned Builtin.NativeObject) -> () {
// CHECK: bb0([[LHS:%.*]] : $*Builtin.NativeObject, [[RHS:%.*]] : @owned $Builtin.NativeObject)
// CHECK: [[DEST:%.*]] = alloc_stack $(Builtin.NativeObject, Builtin.NativeObject)
// CHECK: tuple_addr_constructor [init] [[DEST]] : $*(Builtin.NativeObject, Builtin.NativeObject) with ([[LHS]] : $*Builtin.NativeObject, [[RHS]] : $Builtin.NativeObject)
// CHECK: } // end sil function 'tuple_addr_constructor_differing_category'
sil [ossa] @tuple_addr_constructor_differing_category : $@convention(thin) (@in Builtin.NativeObject, @owned Builtin.NativeObject) -> () {
bb0(%0 : $*Builtin.NativeObject, %1 : @owned $Builtin.NativeObject):
%2 = alloc_stack $(Builtin.NativeObject, Builtin.NativeObject)
tuple_addr_constructor [init] %2 : $*(Builtin.NativeObject, Builtin.NativeObject) with (%0 : $*Builtin.NativeObject, %1 : $Builtin.NativeObject)
destroy_addr %2 : $*(Builtin.NativeObject, Builtin.NativeObject)
dealloc_stack %2 : $*(Builtin.NativeObject, Builtin.NativeObject)
%9999 = tuple ()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @tuple_addr_constructor_init : $@convention(thin) (@in Builtin.NativeObject) -> () {
// CHECK: bb0([[LHS:%.*]] : $*
// CHECK: [[RHS:%.*]] = alloc_stack $Builtin.NativeObject
// CHECK: [[DEST:%.*]] = alloc_stack $(Builtin.NativeObject, Builtin.NativeObject)
// CHECK: tuple_addr_constructor [init] [[DEST]] : $*(Builtin.NativeObject, Builtin.NativeObject) with ([[LHS]] : $*Builtin.NativeObject, [[RHS]] : $*Builtin.NativeObject)
// CHECK: } // end sil function 'tuple_addr_constructor_init'
sil [ossa] @tuple_addr_constructor_init : $@convention(thin) (@in Builtin.NativeObject) -> () {
bb0(%0 : $*Builtin.NativeObject):
%1 = alloc_stack $Builtin.NativeObject
copy_addr %0 to [init] %1 : $*Builtin.NativeObject
%2 = alloc_stack $(Builtin.NativeObject, Builtin.NativeObject)
tuple_addr_constructor [init] %2 : $*(Builtin.NativeObject, Builtin.NativeObject) with (%0 : $*Builtin.NativeObject, %1 : $*Builtin.NativeObject)
destroy_addr %2 : $*(Builtin.NativeObject, Builtin.NativeObject)
dealloc_stack %2 : $*(Builtin.NativeObject, Builtin.NativeObject)
dealloc_stack %1 : $*Builtin.NativeObject
%9999 = tuple ()
return %9999 : $()
}
// CHECK-LABEL: sil [ossa] @tuple_addr_constructor_unfriendly_tuple : $@convention(thin) (@in Builtin.NativeObject, @owned Builtin.NativeObject) -> () {
// CHECK: tuple_addr_constructor [init] {{%.*}} : $*((), (Builtin.NativeObject, Builtin.NativeObject)) with
sil [ossa] @tuple_addr_constructor_unfriendly_tuple : $@convention(thin) (@in Builtin.NativeObject, @owned Builtin.NativeObject) -> () {
bb0(%0 : $*Builtin.NativeObject, %1 : @owned $Builtin.NativeObject):
%2 = alloc_stack $((), (Builtin.NativeObject, Builtin.NativeObject))
tuple_addr_constructor [init] %2 : $*((), (Builtin.NativeObject, Builtin.NativeObject)) with (%0 : $*Builtin.NativeObject, %1 : $Builtin.NativeObject)
destroy_addr %2 : $*((), (Builtin.NativeObject, Builtin.NativeObject))
dealloc_stack %2 : $*((), (Builtin.NativeObject, Builtin.NativeObject))
%9999 = tuple ()
return %9999 : $()
}
|