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 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
|
// RUN: %target-swift-frontend %s -Xllvm -sil-print-after=loadable-address -import-objc-header %S/Inputs/large_c.h -c -o %t/t.o 2>&1 | %FileCheck %s
// wasm currently disables aggressive reg2mem
// UNSUPPORTED: wasm
// UNSUPPORTED: OS=wasi
// UNSUPPORTED: CPU=wasm32
// REQUIRES: PTRSIZE=64
sil_stage canonical
import Builtin
import Swift
struct X {
var x1 : Int
var x2 : Int
var x3 : Int
var x4: Int
var x5: Int
var x6: Int
var x7: Int
var x8: Int
var x9: Int
var x10: Int
var x11: Int
var x12: Int
var x13: Int
var x14: Int
var x15: Int
var x16: Int
}
struct X2 {
var x1 : Int
var x2 : Int
var x3 : Int
var x4: Int
var x5: Int
var x6: Int
var x7: Int
var x8: Int
var x9: Int
var x10: Int
var x11: Int
var x12: Int
var x13: Int
var x14: Int
var x15: Int
var x16: Int
}
struct Y {
var y1 : X
var y2: X
}
class C1 {
}
sil_vtable C1 {
}
struct Small {
var x1 : Int
}
// CHECK: sil @test1 : $@convention(thin) () -> () {
// CHECK: bb0:
// CHECK: %0 = alloc_stack $Optional<X>
// CHECK: %1 = alloc_stack $X
// CHECK: %2 = alloc_stack $X
// CHECK: %3 = alloc_stack $Optional<X>
// CHECK: copy_addr [take] %2 to [init] %1 : $*X
// CHECK: %5 = init_enum_data_addr %0 : $*Optional<X>, #Optional.some!enumelt
// CHECK: copy_addr [take] %1 to [init] %5 : $*X
// CHECK: inject_enum_addr %0 : $*Optional<X>, #Optional.some!enumelt
// CHECK: copy_addr [take] %0 to [init] %3 : $*Optional<X>
// CHECK: dealloc_stack %3 : $*Optional<X>
// CHECK: dealloc_stack %2 : $*X
// CHECK: dealloc_stack %1 : $*X
// CHECK: dealloc_stack %0 : $*Optional<X>
// CHECK: } // end sil function 'test1'
sil @test1 : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $X
%1 = alloc_stack $Optional<X>
%2 = load %0 : $*X
%3 = enum $Optional<X>, #Optional.some!enumelt, %2 : $X
store %3 to %1 : $*Optional<X>
dealloc_stack %1 : $*Optional<X>
dealloc_stack %0 : $*X
%t = tuple ()
return %t : $()
}
// CHECK: sil @test2 : $@convention(thin) () -> () {
// CHECK: bb0:
// CHECK: %0 = alloc_stack $Optional<X>
// CHECK: %1 = alloc_stack $Optional<X>
// CHECK: %2 = alloc_stack $Optional<X>
// CHECK: copy_addr [take] %2 to [init] %1 : $*Optional<X>
// CHECK: copy_addr [take] %1 to [init] %0 : $*Optional<X>
// CHECK: switch_enum_addr %0 : $*Optional<X>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2
// CHECK: bb1:
// CHECK: %6 = unchecked_take_enum_data_addr %0 : $*Optional<X>, #Optional.some!enumelt
// CHECK: br bb3
// CHECK: bb2:
// CHECK: br bb3
// CHECK: bb3:
// CHECK: dealloc_stack %2 : $*Optional<X>
// CHECK: dealloc_stack %1 : $*Optional<X>
// CHECK: dealloc_stack %0 : $*Optional<X>
// CHECK: } // end sil function 'test2'
sil @test2 : $@convention(thin) () -> () {
bb0:
%1 = alloc_stack $Optional<X>
%2 = load %1 : $*Optional<X>
switch_enum %2 : $Optional<X>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2
bb1(%3: $X):
br bb3
bb2:
br bb3
bb3:
dealloc_stack %1 : $*Optional<X>
%t = tuple ()
return %t : $()
}
// CHECK: sil @test3 : $@convention(thin) () -> Builtin.Int1 {
// CHECK: bb0:
// CHECK: %0 = alloc_stack $Optional<X>
// CHECK: %1 = alloc_stack $Optional<X>
// CHECK: copy_addr [take] %1 to [init] %0 : $*Optional<X>
// CHECK: %3 = integer_literal $Builtin.Int1, -1
// CHECK: %4 = integer_literal $Builtin.Int1, 0
// CHECK: %5 = select_enum_addr %0 : $*Optional<X>, case #Optional.some!enumelt: %3, case #Optional.none!enumelt: %4 : $Builtin.Int1
// CHECK: dealloc_stack %1 : $*Optional<X>
// CHECK: dealloc_stack %0 : $*Optional<X>
// CHECK: return %5 : $Builtin.Int1
// CHECK: } // end sil function 'test3'
sil @test3 : $@convention(thin) () -> Builtin.Int1 {
bb0:
%1 = alloc_stack $Optional<X>
%2 = load %1 : $*Optional<X>
%3 = integer_literal $Builtin.Int1, -1
%4 = integer_literal $Builtin.Int1, 0
%r = select_enum %2 : $Optional<X>, case #Optional.some!enumelt: %3, case #Optional.none!enumelt: %4 : $Builtin.Int1
dealloc_stack %1 : $*Optional<X>
return %r : $Builtin.Int1
}
// CHECK: sil @test4 : $@convention(thin) () -> () {
// CHECK: bb0:
// CHECK: %0 = alloc_stack $(X, X)
// CHECK: %1 = alloc_stack $X
// CHECK: %2 = alloc_stack $X
// CHECK: %3 = alloc_stack $(X, X)
// CHECK: copy_addr [take] %2 to [init] %1 : $*X
// CHECK: %5 = tuple_element_addr %0 : $*(X, X), 0
// CHECK: copy_addr [take] %1 to [init] %5 : $*X
// CHECK: %7 = tuple_element_addr %0 : $*(X, X), 1
// CHECK: copy_addr [take] %1 to [init] %7 : $*X
// CHECK: copy_addr [take] %0 to [init] %3 : $*(X, X)
// CHECK: } // end sil function 'test4'
sil @test4 : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $X
%1 = alloc_stack $(X, X)
%2 = load %0 : $*X
%3 = tuple (%2 : $X , %2 : $X)
store %3 to %1 : $*(X, X)
dealloc_stack %1 : $*(X,X)
dealloc_stack %0 : $*X
%t = tuple ()
return %t : $()
}
// CHECK: sil @test5 : $@convention(thin) (@in (X, X)) -> () {
// CHECK: bb0(%0 : $*(X, X)):
// CHECK: %1 = alloc_stack $(X, X)
// CHECK: %2 = alloc_stack $X
// CHECK: copy_addr [take] %0 to [init] %1 : $*(X, X)
// CHECK: %4 = tuple_element_addr %1 : $*(X, X), 1
// CHECK: copy_addr [take] %4 to [init] %2 : $*X
// CHECK: } // end sil function 'test5'
sil @test5 : $@convention(thin) (@in (X, X)) -> () {
bb0(%0 : $*(X, X)):
%1 = alloc_stack $X
%2 = load %0 : $*(X, X)
%4 = tuple_extract %2 : $(X, X), 1
store %4 to %1 : $*X
dealloc_stack %1 : $*X
%t = tuple ()
return %t : $()
}
// CHECK: sil @test6 : $@convention(thin) () -> () {
// CHECK: bb0:
// CHECK: %0 = alloc_stack $Y
// CHECK: %1 = alloc_stack $X
// CHECK: %2 = alloc_stack $X
// CHECK: %3 = alloc_stack $Y
// CHECK: copy_addr [take] %2 to [init] %1 : $*X
// CHECK: %5 = struct_element_addr %0 : $*Y, #Y.y1
// CHECK: copy_addr [take] %1 to [init] %5 : $*X
// CHECK: %7 = struct_element_addr %0 : $*Y, #Y.y2
// CHECK: copy_addr [take] %1 to [init] %7 : $*X
// CHECK: copy_addr [take] %0 to [init] %3 : $*Y
// CHECK: } // end sil function 'test6'
sil @test6 : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $X
%1 = alloc_stack $Y
%2 = load %0 : $*X
%3 = struct $Y (%2 : $X , %2 : $X)
store %3 to %1 : $*Y
dealloc_stack %1 : $*Y
dealloc_stack %0 : $*X
%t = tuple ()
return %t : $()
}
// CHECK: sil @test7 : $@convention(thin) (@in Y) -> () {
// CHECK: bb0(%0 : $*Y):
// CHECK: %1 = alloc_stack $Y
// CHECK: %2 = alloc_stack $X
// CHECK: copy_addr [take] %0 to [init] %1 : $*Y
// CHECK: %4 = struct_element_addr %1 : $*Y, #Y.y1
// CHECK: copy_addr [take] %4 to [init] %2 : $*X
// CHECK: } // end sil function 'test7'
sil @test7 : $@convention(thin) (@in Y) -> () {
bb0(%0 : $*Y):
%1 = alloc_stack $X
%2 = load %0 : $*Y
%4 = struct_extract %2 : $Y, #Y.y1
store %4 to %1 : $*X
dealloc_stack %1 : $*X
%t = tuple ()
return %t : $()
}
// CHECK: sil @test8
// CHECK: bb0(%0 : $SamplesType):
// CHECK: %1 = alloc_stack $SamplesType
// CHECK: store %0 to %1 : $*SamplesType
sil @helper : $@convention(thin) (SamplesType) -> ()
sil @test8 : $@convention(c) (SamplesType) -> () {
bb0(%0 : $SamplesType):
%1 = function_ref @helper : $@convention(thin) (SamplesType) -> ()
%2 = apply %1(%0) : $@convention(thin) (SamplesType) -> ()
%t = tuple ()
return %t : $()
}
// In this test case Container type is identified as not large but contained
// type is.
sil @test9 : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $_ContainerType
%1 = load %0 : $*_ContainerType
%2 = alloc_stack $(_ContainedType, _ContainedType, _ContainedType, _ContainedType, _ContainedType,
_ContainedType, _ContainedType, _ContainedType, _ContainedType, _ContainedType)
%3 = struct_extract %1 : $_ContainerType, #_ContainerType.l
store %3 to %2 : $*(_ContainedType, _ContainedType, _ContainedType, _ContainedType, _ContainedType,
_ContainedType, _ContainedType, _ContainedType, _ContainedType, _ContainedType)
dealloc_stack %2 : $*(_ContainedType, _ContainedType, _ContainedType, _ContainedType, _ContainedType,
_ContainedType, _ContainedType, _ContainedType, _ContainedType, _ContainedType)
dealloc_stack %0 : $*_ContainerType
%t = tuple ()
return %t : $()
}
sil @test10 : $@convention(thin) (@in_guaranteed C1, @in Small) -> () {
bb0(%0 : $*C1, %1 : $*Small):
%2 = load %1 : $*Small
%3 = load %0 : $*C1
retain_value %3 : $C1
store %2 to %1 : $*Small
retain_value %3 : $C1
%t = tuple ()
return %t : $()
}
sil @use : $@convention(thin) (UInt32) -> ()
// We need to make sure we use the bigger alloc_stack for the address of
// unchecked_trivial_bit_cast. A bitcast can go from bigger to smaller type.
// CHECK: sil @test11 : $@convention(thin) (@in union_t) -> () {
// CHECK-NOT: unchecked_addr_cast %1 : $*union_t.__Unnamed_struct_in to $*union_t
// CHECK: unchecked_addr_cast {{.*}} : $*union_t to $*union_t.__Unnamed_struct_in
// CHECK: } // end sil function 'test11'
sil @test11 : $@convention(thin) (@in union_t) -> () {
bb0(%0 : $*union_t):
%1 = alloc_stack $union_t
%2 = alloc_stack $union_t
copy_addr [take] %0 to [init] %2 : $*union_t
%4 = load %2 : $*union_t
%7 = unchecked_trivial_bit_cast %4 : $union_t to $union_t.__Unnamed_struct_in
%8 = struct_extract %7 : $union_t.__Unnamed_struct_in, #union_t.__Unnamed_struct_in.slot
%10 = struct_extract %8 : $enum_t, #enum_t.rawValue
%11 = function_ref @use : $@convention(thin) (UInt32) -> ()
%12 = apply %11(%10) : $@convention(thin) (UInt32) -> ()
%13 = tuple ()
dealloc_stack %2 : $*union_t
dealloc_stack %1 : $*union_t
return %13 : $()
}
// This test case used to crash because we did not handle `mark_dependence`.
sil @test12 : $@convention(thin) () -> () {
bb0:
%0 = alloc_stack $X
%1 = alloc_stack $Y
%2 = alloc_stack $X
%3 = load %0 : $*X
%4 = load %2 : $*X
%5 = mark_dependence %3 : $X on %4 : $X
%6 = struct $Y (%5 : $X , %5 : $X)
store %6 to %1 : $*Y
dealloc_stack %2 : $*X
dealloc_stack %1 : $*Y
dealloc_stack %0 : $*X
%t = tuple ()
return %t : $()
}
// CHECK: sil @test13
// CHECK: [[ADDR:%.*]] = unchecked_addr_cast %1 : $*X to $*Y
// CHECK: copy_addr [take] [[ADDR]] to [init] %2 : $*Y
// CHECK: } // end sil function 'test13'
sil @test13 : $@convention(thin) (@in X) -> () {
bb0(%0 : $*X):
%1 = alloc_stack $Y
%2 = alloc_stack $X
copy_addr [take] %0 to [init] %2 : $*X
%4 = load %2 : $*X
%7 = unchecked_bitwise_cast %4 : $X to $Y
store %7 to %1: $*Y
%13 = tuple ()
dealloc_stack %2 : $*X
dealloc_stack %1 : $*Y
return %13 : $()
}
// CHECK: sil @test14
// CHECK: [[VAL:%.*]] = load {{.*}} : $*X
// CHECK: throw [[VAL]]
// CHECK: } // end sil function 'test14'
sil @test14 : $@convention(thin) (@in X) -> @error X {
bb0(%0 : $*X):
%1 = alloc_stack $X
copy_addr [take] %0 to [init] %1 : $*X
%3 = load %1 : $*X
dealloc_stack %1 : $*X
throw %3 : $X
}
// CHECK: sil @test15
// CHECK: cond_br %1, bb1, bb2
// CHECK: bb1:
// CHECK: copy_addr [take] {{.*}} to [init] [[PHI:%[0-9]+]] : $*X
// CHECK: br bb3
// CHECK: bb2:
// CHECK: [[UNDEF:%.*]] = alloc_stack $X
// CHECK: copy_addr [take] [[UNDEF]] to [init] [[PHI]] : $*X
// CHECK: dealloc_stack [[UNDEF]] : $*X
// CHECK: br bb3
// CHECK:} // end sil function 'test15'
sil @test15 : $@convention(thin) (X, Builtin.Int1) -> () {
bb0(%0: $X, %1: $Builtin.Int1):
%2 = alloc_stack $X
cond_br %1, bb1, bb2
bb1:
br bb3(%0 : $X)
bb2:
br bb3(undef : $X)
bb3(%4 : $X):
store %4 to %2: $*X
dealloc_stack %2 : $*X
%t = tuple ()
return %t : $()
}
sil @usei8 : $@convention(thin) (UInt8) -> ()
// CHECK: sil @test16
// CHECK: bb0(%0 : $member_id_t):
// CHECK: [[T0:%.*]] = alloc_stack $member_id_t
// CHECK: store %0 to [[T0]] : $*member_id_t
// CHECK: struct_element_addr [[T0]]
// CHECK:} // end sil function 'test16'
sil @test16 : $@convention(thin) (member_id_t) -> () {
bb0(%0 : $member_id_t):
%2 = alloc_stack $X
%44 = struct_extract %0 : $member_id_t, #member_id_t.member_value // user: %45
%45 = unchecked_trivial_bit_cast %44 : $member_id_t.__Unnamed_union_member_value to $(UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
%46 = tuple_extract %45 : $(UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8), 0
%11 = function_ref @usei8 : $@convention(thin) (UInt8) -> ()
%12 = apply %11(%46) : $@convention(thin) (UInt8) -> ()
dealloc_stack %2 : $*X
%13 = tuple ()
return %13 : $()
}
|