|
3 | 3 | sil_stage canonical
|
4 | 4 |
|
5 | 5 | import Builtin
|
| 6 | +import Swift |
6 | 7 |
|
7 | 8 | class Klass {}
|
8 | 9 |
|
9 | 10 | sil @returnInt : $@convention(thin) () -> Builtin.Int32
|
| 11 | +sil @use_anyobject : $@convention(thin) (@guaranteed AnyObject) -> () |
| 12 | +sil @use_nativeobject : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () |
10 | 13 |
|
11 | 14 | // CHECK-LABEL: sil @optimize_convert_escape_to_noescape :
|
12 | 15 | // CHECK: [[FN:%.*]] = function_ref @returnInt
|
|
37 | 40 | %4 = apply %2() : $@noescape @callee_guaranteed () -> Builtin.Int32
|
38 | 41 | return %4 : $Builtin.Int32
|
39 | 42 | }
|
| 43 | + |
| 44 | +////////////////////////////// |
| 45 | +// ref_to_raw_pointer tests // |
| 46 | +////////////////////////////// |
| 47 | + |
| 48 | +// RefToRawPointer pointer consumption. |
| 49 | +// |
| 50 | +// (ref_to_raw_pointer (unchecked_ref_cast x)) |
| 51 | +// -> (ref_to_raw_pointer x) |
| 52 | +// |
| 53 | +// CHECK-LABEL: sil @ref_to_raw_pointer_unchecked_ref_cast_composition : $@convention(thin) (@guaranteed Klass) -> Builtin.RawPointer |
| 54 | +// CHECK: bb0 |
| 55 | +// CHECK-NEXT: ref_to_raw_pointer |
| 56 | +// CHECK-NEXT: return |
| 57 | +// CHECK: } // end sil function 'ref_to_raw_pointer_unchecked_ref_cast_composition' |
| 58 | +sil @ref_to_raw_pointer_unchecked_ref_cast_composition : $@convention(thin) (@guaranteed Klass) -> Builtin.RawPointer { |
| 59 | +bb0(%0 : $Klass): |
| 60 | + %1 = unchecked_ref_cast %0 : $Klass to $Builtin.NativeObject |
| 61 | + %2 = ref_to_raw_pointer %1 : $Builtin.NativeObject to $Builtin.RawPointer |
| 62 | + return %2 : $Builtin.RawPointer |
| 63 | +} |
| 64 | + |
| 65 | +// CHECK-LABEL: sil [ossa] @ref_to_raw_pointer_unchecked_ref_cast_composition_ossa_guaranteed : $@convention(thin) (@guaranteed Klass) -> Builtin.RawPointer |
| 66 | +// CHECK: bb0 |
| 67 | +// CHECK-NEXT: ref_to_raw_pointer |
| 68 | +// CHECK-NEXT: return |
| 69 | +// CHECK: } // end sil function 'ref_to_raw_pointer_unchecked_ref_cast_composition_ossa_guaranteed' |
| 70 | +sil [ossa] @ref_to_raw_pointer_unchecked_ref_cast_composition_ossa_guaranteed : $@convention(thin) (@guaranteed Klass) -> Builtin.RawPointer { |
| 71 | +bb0(%0 : @guaranteed $Klass): |
| 72 | + %1 = unchecked_ref_cast %0 : $Klass to $Builtin.NativeObject |
| 73 | + %2 = ref_to_raw_pointer %1 : $Builtin.NativeObject to $Builtin.RawPointer |
| 74 | + return %2 : $Builtin.RawPointer |
| 75 | +} |
| 76 | + |
| 77 | +// CHECK-LABEL: sil [ossa] @ref_to_raw_pointer_unchecked_ref_cast_composition_ossa_owned : $@convention(thin) (@owned Klass) -> Builtin.RawPointer |
| 78 | +// CHECK: bb0([[ARG:%.*]] : @owned |
| 79 | +// CHECK-NEXT: [[RESULT:%.*]] = ref_to_raw_pointer [[ARG]] |
| 80 | +// CHECK-NEXT: [[CAST:%.*]] = unchecked_ref_cast [[ARG]] |
| 81 | +// CHECK-NEXT: destroy_value [[CAST]] |
| 82 | +// CHECK-NEXT: return [[RESULT]] |
| 83 | +// CHECK: } // end sil function 'ref_to_raw_pointer_unchecked_ref_cast_composition_ossa_owned' |
| 84 | +sil [ossa] @ref_to_raw_pointer_unchecked_ref_cast_composition_ossa_owned : $@convention(thin) (@owned Klass) -> Builtin.RawPointer { |
| 85 | +bb0(%0 : @owned $Klass): |
| 86 | + %1 = unchecked_ref_cast %0 : $Klass to $Builtin.NativeObject |
| 87 | + %2 = ref_to_raw_pointer %1 : $Builtin.NativeObject to $Builtin.RawPointer |
| 88 | + destroy_value %1 : $Builtin.NativeObject |
| 89 | + return %2 : $Builtin.RawPointer |
| 90 | +} |
| 91 | + |
| 92 | +// CHECK-LABEL: sil @collapse_existential_pack_unpack_ref_to_raw_pointer : |
| 93 | +// CHECK: bb0([[Ref:%.*]] : $Klass): |
| 94 | +// CHECK-NOT: init_existential_ref |
| 95 | +// CHECK-NOT: open_existential_ref |
| 96 | +// CHECK: ref_to_raw_pointer [[Ref]] |
| 97 | +// CHECK: } // end sil function 'collapse_existential_pack_unpack_ref_to_raw_pointer' |
| 98 | +sil @collapse_existential_pack_unpack_ref_to_raw_pointer : $@convention(thin) (@guaranteed Klass) -> () { |
| 99 | +bb0(%0 : $Klass): |
| 100 | + %1 = init_existential_ref %0 : $Klass : $Klass, $AnyObject |
| 101 | + %2 = open_existential_ref %1 : $AnyObject to $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject |
| 102 | + %3 = ref_to_raw_pointer %2 : $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject to $Builtin.RawPointer |
| 103 | + %4 = pointer_to_address %3 : $Builtin.RawPointer to [strict] $*Builtin.Word |
| 104 | + %5 = integer_literal $Builtin.Word, 5 |
| 105 | + store %5 to %4: $*Builtin.Word |
| 106 | + %6 = tuple () |
| 107 | + return %6 : $() |
| 108 | +} |
| 109 | + |
| 110 | +// CHECK-LABEL: sil [ossa] @collapse_existential_pack_unpack_ref_to_raw_pointer_ossa_guaranteed : |
| 111 | +// CHECK: bb0([[Ref:%.*]] : @guaranteed $Klass): |
| 112 | +// CHECK-NOT: init_existential_ref |
| 113 | +// CHECK-NOT: open_existential_ref |
| 114 | +// CHECK: ref_to_raw_pointer [[Ref]] |
| 115 | +// CHECK: } // end sil function 'collapse_existential_pack_unpack_ref_to_raw_pointer_ossa_guaranteed' |
| 116 | +sil [ossa] @collapse_existential_pack_unpack_ref_to_raw_pointer_ossa_guaranteed : $@convention(thin) (@guaranteed Klass) -> () { |
| 117 | +bb0(%0 : @guaranteed $Klass): |
| 118 | + %1 = init_existential_ref %0 : $Klass : $Klass, $AnyObject |
| 119 | + %2 = open_existential_ref %1 : $AnyObject to $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject |
| 120 | + %3 = ref_to_raw_pointer %2 : $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject to $Builtin.RawPointer |
| 121 | + %4 = pointer_to_address %3 : $Builtin.RawPointer to [strict] $*Builtin.Word |
| 122 | + %5 = integer_literal $Builtin.Word, 5 |
| 123 | + store %5 to [trivial] %4: $*Builtin.Word |
| 124 | + %6 = tuple () |
| 125 | + return %6 : $() |
| 126 | +} |
| 127 | + |
| 128 | +// We need to hoist the ref_to_raw_pointer above the init_existential_ref since |
| 129 | +// that is where %0 is live. |
| 130 | +// |
| 131 | +// CHECK-LABEL: sil [ossa] @collapse_existential_pack_unpack_ref_to_raw_pointer_ossa_owned : |
| 132 | +// CHECK: bb0([[ARG:%.*]] : @owned $Klass): |
| 133 | +// CHECK-NOT: init_existential_ref |
| 134 | +// CHECK-NOT: open_existential_ref |
| 135 | +// CHECK: [[PTR:%.*]] = ref_to_raw_pointer [[ARG]] |
| 136 | +// CHECK: [[FORWARDED_ARG:%.*]] = init_existential_ref [[ARG]] |
| 137 | +// CHECK: destroy_value [[FORWARDED_ARG]] |
| 138 | +// CHECK: } // end sil function 'collapse_existential_pack_unpack_ref_to_raw_pointer_ossa_owned' |
| 139 | +sil [ossa] @collapse_existential_pack_unpack_ref_to_raw_pointer_ossa_owned : $@convention(thin) (@owned Klass) -> () { |
| 140 | +bb0(%0 : @owned $Klass): |
| 141 | + %1 = init_existential_ref %0 : $Klass : $Klass, $AnyObject |
| 142 | + %f = function_ref @use_anyobject : $@convention(thin) (@guaranteed AnyObject) -> () |
| 143 | + apply %f(%1) : $@convention(thin) (@guaranteed AnyObject) -> () |
| 144 | + %2 = open_existential_ref %1 : $AnyObject to $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject |
| 145 | + %3 = ref_to_raw_pointer %2 : $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject to $Builtin.RawPointer |
| 146 | + %4 = pointer_to_address %3 : $Builtin.RawPointer to [strict] $*Builtin.Word |
| 147 | + %5 = integer_literal $Builtin.Word, 5 |
| 148 | + store %5 to [trivial] %4: $*Builtin.Word |
| 149 | + destroy_value %2 : $@opened("2CAE06CE-5F10-11E4-AF13-C82A1428F987") AnyObject |
| 150 | + %6 = tuple () |
| 151 | + return %6 : $() |
| 152 | +} |
| 153 | + |
| 154 | + |
| 155 | +// (ref_to_raw_pointer (unchecked_ref_cast x)) -> (unchecked_trivial_bit_cast x) |
| 156 | +// |
| 157 | +// CHECK-LABEL: sil @collapse_to_unchecked_trivial_bit_cast : |
| 158 | +// CHECK: bb0([[Ref:%.*]] : $Optional<Klass>): |
| 159 | +// CHECK: unchecked_trivial_bit_cast [[Ref]] |
| 160 | +// CHECK-NOT: unchecked_ref_cast |
| 161 | +// CHECK-NOT: ref_to_raw_pointer |
| 162 | +// CHECK: } // end sil function 'collapse_to_unchecked_trivial_bit_cast' |
| 163 | +sil @collapse_to_unchecked_trivial_bit_cast : $@convention(thin) (Optional<Klass>) -> (Builtin.RawPointer) { |
| 164 | +bb0(%0 : $Optional<Klass>): |
| 165 | + %1 = unchecked_ref_cast %0 : $Optional<Klass> to $Builtin.NativeObject |
| 166 | + %2 = ref_to_raw_pointer %1 : $Builtin.NativeObject to $Builtin.RawPointer |
| 167 | + return %2 : $Builtin.RawPointer |
| 168 | +} |
| 169 | + |
| 170 | +// CHECK-LABEL: sil [ossa] @collapse_to_unchecked_trivial_bit_cast_ossa_guaranteed : |
| 171 | +// CHECK: bb0([[Ref:%.*]] : @guaranteed $Optional<Klass>): |
| 172 | +// CHECK: unchecked_trivial_bit_cast [[Ref]] |
| 173 | +// CHECK-NOT: unchecked_ref_cast |
| 174 | +// CHECK-NOT: ref_to_raw_pointer |
| 175 | +// CHECK: } // end sil function 'collapse_to_unchecked_trivial_bit_cast_ossa_guaranteed' |
| 176 | +sil [ossa] @collapse_to_unchecked_trivial_bit_cast_ossa_guaranteed : $@convention(thin) (@guaranteed Optional<Klass>) -> (Builtin.RawPointer) { |
| 177 | +bb0(%0 : @guaranteed $Optional<Klass>): |
| 178 | + %1 = unchecked_ref_cast %0 : $Optional<Klass> to $Builtin.NativeObject |
| 179 | + %2 = ref_to_raw_pointer %1 : $Builtin.NativeObject to $Builtin.RawPointer |
| 180 | + return %2 : $Builtin.RawPointer |
| 181 | +} |
| 182 | + |
| 183 | +// We need to make sure that we hoist unchecked_trivial_bit_cast above |
| 184 | +// unchecked_ref_cast since we are not eliminating it here due to an additional |
| 185 | +// user. |
| 186 | +// |
| 187 | +// CHECK-LABEL: sil [ossa] @collapse_to_unchecked_trivial_bit_cast_ossa_owned : |
| 188 | +// CHECK: bb0([[ARG:%.*]] : @owned $Optional<Klass>): |
| 189 | +// CHECK: [[RESULT:%.*]] = unchecked_trivial_bit_cast [[ARG]] |
| 190 | +// CHECK: [[FORWARDED_ARG:%.*]] = unchecked_ref_cast [[ARG]] |
| 191 | +// CHECK: destroy_value [[FORWARDED_ARG]] |
| 192 | +// CHECK: return [[RESULT]] |
| 193 | +// CHECK: } // end sil function 'collapse_to_unchecked_trivial_bit_cast_ossa_owned' |
| 194 | +sil [ossa] @collapse_to_unchecked_trivial_bit_cast_ossa_owned : $@convention(thin) (@owned Optional<Klass>) -> (Builtin.RawPointer) { |
| 195 | +bb0(%0 : @owned $Optional<Klass>): |
| 196 | + %1 = unchecked_ref_cast %0 : $Optional<Klass> to $Builtin.NativeObject |
| 197 | + %f = function_ref @use_nativeobject : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () |
| 198 | + apply %f(%1) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () |
| 199 | + %2 = ref_to_raw_pointer %1 : $Builtin.NativeObject to $Builtin.RawPointer |
| 200 | + destroy_value %1 : $Builtin.NativeObject |
| 201 | + return %2 : $Builtin.RawPointer |
| 202 | +} |
| 203 | + |
0 commit comments