|
| 1 | +// RUN: %target-sil-opt -enable-sil-verify-all -sil-print-debuginfo -sroa %s | %FileCheck --check-prefix=CHECK-SROA %s |
| 2 | +sil_stage canonical |
| 3 | + |
| 4 | +import Builtin |
| 5 | +import Swift |
| 6 | + |
| 7 | +struct MyStruct { |
| 8 | + @_hasStorage var x: Int64 { get set } |
| 9 | + @_hasStorage var y: Int64 { get set } |
| 10 | + init(x: Int64, y: Int64) |
| 11 | +} |
| 12 | + |
| 13 | +struct MyContainer { |
| 14 | + @_hasStorage var z: MyStruct { get set } |
| 15 | +} |
| 16 | + |
| 17 | +sil_scope 1 { loc "sroa.swift":2:8 parent @MyStructInit : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct } |
| 18 | + |
| 19 | +// MyStruct.init(x:y:) |
| 20 | +sil hidden @MyStructInit : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct { |
| 21 | +bb0(%0 : $Int64, %1 : $Int64, %2 : $@thin MyStruct.Type): |
| 22 | + %3 = struct $MyStruct (%0 : $Int64, %1 : $Int64), loc "sroa.swift":2:8, scope 1 |
| 23 | + return %3 : $MyStruct, loc "sroa.swift":2:8, scope 1 |
| 24 | +} // end sil function 'MyStructInit' |
| 25 | + |
| 26 | +sil_scope 2 { loc "sroa.swift":7:6 parent @foo : $@convention(thin) (Int64, Int64) -> Int64 } |
| 27 | + |
| 28 | +// foo(in_x:in_y:) |
| 29 | +sil hidden @foo : $@convention(thin) (Int64, Int64) -> Int64 { |
| 30 | +bb0(%0 : $Int64, %1 : $Int64): |
| 31 | + debug_value %0 : $Int64, let, name "in_x", argno 1, loc "sroa.swift":7:10, scope 2 |
| 32 | + debug_value %1 : $Int64, let, name "in_y", argno 2, loc "sroa.swift":7:21, scope 2 |
| 33 | + %4 = alloc_stack $MyStruct, var, name "my_struct", type $*MyContainer, expr op_fragment:#MyContainer.z, loc "sroa.swift":8:9, scope 2 |
| 34 | + // Recursive SROA of already SROA-ed aggregates is not yet supported. |
| 35 | + // CHECK-SROA: alloc_stack $Int64 |
| 36 | + // CHECK-SROA-NOT: var, |
| 37 | + // CHECK-SROA: alloc_stack $Int64 |
| 38 | + // CHECK-SROA-NOT: var, |
| 39 | + // CHECK-SROA: metatype |
| 40 | + %5 = metatype $@thin MyStruct.Type, loc "sroa.swift":8:21, scope 2 |
| 41 | + %6 = integer_literal $Builtin.Int64, 0, loc "sroa.swift":8:33, scope 2 |
| 42 | + %7 = struct $Int64 (%6 : $Builtin.Int64), loc "sroa.swift":8:33, scope 2 |
| 43 | + %8 = integer_literal $Builtin.Int64, 0, loc "sroa.swift":8:39, scope 2 |
| 44 | + %9 = struct $Int64 (%8 : $Builtin.Int64), loc "sroa.swift":8:39, scope 2 |
| 45 | + // function_ref MyStruct.init(x:y:) |
| 46 | + %10 = function_ref @MyStructInit : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct, loc "sroa.swift":8:21, scope 2 |
| 47 | + %11 = apply %10(%7, %9, %5) : $@convention(method) (Int64, Int64, @thin MyStruct.Type) -> MyStruct, loc "sroa.swift":8:21, scope 2 |
| 48 | + store %11 to %4 : $*MyStruct, loc "sroa.swift":8:21, scope 2 |
| 49 | + %13 = struct_element_addr %4 : $*MyStruct, #MyStruct.x, loc "sroa.swift":9:17, scope 2 |
| 50 | + store %0 to %13 : $*Int64, loc "sroa.swift":9:17, scope 2 |
| 51 | + %15 = struct_element_addr %4 : $*MyStruct, #MyStruct.y, loc "sroa.swift":10:17, scope 2 |
| 52 | + store %1 to %15 : $*Int64, loc "sroa.swift":10:17, scope 2 |
| 53 | + dealloc_stack %4 : $*MyStruct, loc "sroa.swift":8:9, scope 2 |
| 54 | + return %0 : $Int64, loc "sroa.swift":11:5, scope 2 |
| 55 | +} // end sil function 'foo' |
0 commit comments