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
|
// RUN: %target-sil-opt -enable-sil-verify-all %s -sil-combine -jumpthread-simplify-cfg | %FileCheck %s
sil_stage canonical
import Builtin
import Swift
// CHECK-LABEL: sil [ossa] @convert_inject_enum_addr_select_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout, @in_guaranteed any CustomStringConvertible) -> ()
// XHECK-NOT: init_existential_addr
// XHECK-NOT: inject_enum_addr
// XHECK-NOT: select_enum_addr
// XHECK-NOT: unchecked_take_enum_data_addr
// XHECK: return
// CHEcK: } // end sil function 'convert_inject_enum_addr_select_enum_addr_into_cond_br'
sil [ossa] @convert_inject_enum_addr_select_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout, @in_guaranteed CustomStringConvertible) -> () {
bb0(%0 : $*Int, %1 : $*_Stdout, %1a : $*CustomStringConvertible):
%2 = alloc_stack $CustomStringConvertible
%3 = alloc_stack $Optional<CustomStringConvertible>
%4 = init_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
%5 = alloc_stack $Int
%6 = load [trivial] %0 : $*Int
store %6 to [trivial] %5 : $*Int
unconditional_checked_cast_addr Int in %5 : $*Int to CustomStringConvertible in %4 : $*CustomStringConvertible
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
dealloc_stack %5 : $*Int
%11 = integer_literal $Builtin.Int1, -1
%12 = integer_literal $Builtin.Int1, 0
%13 = select_enum_addr %3 : $*Optional<CustomStringConvertible>, case #Optional.some!enumelt: %11, case #Optional.none!enumelt: %12 : $Builtin.Int1
cond_br %13, bb2, bb1a
bb1a:
destroy_addr %3 : $*Optional<CustomStringConvertible>
copy_addr %1a to [init] %2 : $*CustomStringConvertible
br bb1
bb1:
%15 = tuple ()
dealloc_stack %3 : $*Optional<CustomStringConvertible>
destroy_addr %2 : $*CustomStringConvertible
dealloc_stack %2 : $*CustomStringConvertible
return %15 : $()
bb2:
%19 = unchecked_take_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
copy_addr [take] %19 to [init] %2 : $*CustomStringConvertible
br bb1
}
// CHECK-LABEL: sil [ossa] @convert_inject_enum_addr_switch_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout, @in_guaranteed any CustomStringConvertible) -> ()
// XHECK-NOT: init_existential_addr
// XHECK-NOT: inject_enum_addr
// XHECK-NOT: switch_enum_addr
// XHECK-NOT: unchecked_take_enum_data_addr
// XHECK: return
// XHECK: } // end sil function 'convert_inject_enum_addr_switch_enum_addr_into_cond_br'
sil [ossa] @convert_inject_enum_addr_switch_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout, @in_guaranteed CustomStringConvertible) -> () {
bb0(%0 : $*Int, %1 : $*_Stdout, %1a : $*CustomStringConvertible):
%2 = alloc_stack $CustomStringConvertible
%3 = alloc_stack $Optional<CustomStringConvertible>
%4 = init_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
%5 = alloc_stack $Int
%6 = load [trivial] %0 : $*Int
store %6 to [trivial] %5 : $*Int
unconditional_checked_cast_addr Int in %5 : $*Int to CustomStringConvertible in %4 : $*CustomStringConvertible
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
dealloc_stack %5 : $*Int
switch_enum_addr %3 : $*Optional<CustomStringConvertible>, case #Optional.some!enumelt: bb3, case #Optional.none!enumelt: bb2
bb1:
%15 = tuple ()
dealloc_stack %3 : $*Optional<CustomStringConvertible>
destroy_addr %2 : $*CustomStringConvertible
dealloc_stack %2 : $*CustomStringConvertible
return %15 : $()
bb2:
copy_addr %1a to [init] %2 : $*CustomStringConvertible
br bb1
bb3:
%19 = unchecked_take_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
copy_addr [take] %19 to [init] %2 : $*CustomStringConvertible
br bb1
}
// Check that a checked_cast_addr_br converting a known type into a protocol type
// is performed at the compile-time if protocol conformances are statically known.
//
// TODO: This is disabled for now since the transformation is done by jumpthread
// simplify-cfg that has not been updated yet for ossa.
//
// CHECK-LABEL: sil [ossa] @convert_checked_cast_addr_br_into_unconditional_checked_cast_addr_cond_br : $@convention(thin) (@in Int, @inout _Stdout) -> ()
// XHECK: checked_cast_addr_br
// XHECK: } // end sil function 'convert_checked_cast_addr_br_into_unconditional_checked_cast_addr_cond_br'
// xXHECK: store
// xXHECK-NOT: checked_cast_addr_br
// xXHECK-NOT: bb1
// xXHECK: inject_enum_addr %{{.*}} : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
// xXHECK: dealloc_stack
// xXHECK: return
sil [ossa] @convert_checked_cast_addr_br_into_unconditional_checked_cast_addr_cond_br : $@convention(thin) (@in Int, @inout _Stdout) -> () {
bb0(%0 : $*Int, %1 : $*_Stdout):
%2 = alloc_stack $CustomStringConvertible
%3 = alloc_stack $Optional<CustomStringConvertible>
%4 = init_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
%5 = alloc_stack $Int
%6 = load [trivial] %0 : $*Int
store %6 to [trivial] %5 : $*Int
checked_cast_addr_br take_always Int in %5 : $*Int to CustomStringConvertible in %4 : $*CustomStringConvertible, bb1, bb22
bb1:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
br bb2
bb2:
dealloc_stack %5 : $*Int
destroy_addr %3 : $*Optional<CustomStringConvertible>
dealloc_stack %3 : $*Optional<CustomStringConvertible>
%12 = integer_literal $Builtin.Int1, -1
%13 = integer_literal $Builtin.Int1, 0
%26 = tuple ()
dealloc_stack %2 : $*CustomStringConvertible
return %26 : $()
bb22:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.none!enumelt
br bb2
}
class A {
}
private final class B {
}
public class C {
}
// D cannot be extended elsewhere, but C can!
private class D : C {
}
// Check that a checked_cast_addr_br converting a known type into a protocol type
// is performed at the compile-time if protocol conformances are statically known.
// In a negative case, take care that check for internal types are not folded (unless
// a whole module optimization is used), because an extension implementing a conformance
// could be defined elsewhere.
//
// CHECK-LABEL: sil [ossa] @convert_checked_cast_addr_br_with_internal_type : $@convention(thin) (@in A, @inout _Stdout) -> ()
// XHECK: checked_cast_addr_br
// XHECK: inject_enum_addr %{{.*}} : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
// XHECK: dealloc_stack
// XHECK: return
// XHECK: inject_enum_addr %{{.*}} : $*Optional<CustomStringConvertible>, #Optional.none!enumelt
// XHECK: }
sil [ossa] @convert_checked_cast_addr_br_with_internal_type : $@convention(thin) (@in A, @inout _Stdout) -> () {
bb0(%0 : $*A, %1 : $*_Stdout):
%2 = alloc_stack $CustomStringConvertible
%3 = alloc_stack $Optional<CustomStringConvertible>
%4 = init_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
%5 = alloc_stack $A
%6 = load [take] %0 : $*A
store %6 to [init] %5 : $*A
checked_cast_addr_br take_always A in %5 : $*A to CustomStringConvertible in %4 : $*CustomStringConvertible, bb1, bb22
bb1:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
br bb2
bb2:
dealloc_stack %5 : $*A
destroy_addr %3 : $*Optional<CustomStringConvertible>
dealloc_stack %3 : $*Optional<CustomStringConvertible>
%12 = integer_literal $Builtin.Int1, -1
%13 = integer_literal $Builtin.Int1, 0
%26 = tuple ()
dealloc_stack %2 : $*CustomStringConvertible
return %26 : $()
bb22:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.none!enumelt
br bb2
}
// Check that a checked_cast_addr_br converting a known type into a protocol type
// is performed at the compile-time if protocol conformances are statically known.
// In a negative case, if the source type is private, it is safe to fold the check,
// because a conformance for this type cannot be defined elsewhere.
//
// TODO: This is handled by jumpthread simplify-cfg which has not been updated
// yet for OSSA so just validate we don't optimize this.
//
// CHECK-LABEL: sil [ossa] @convert_checked_cast_addr_br_with_private_type : $@convention(thin) (@in B, @inout _Stdout) -> ()
// XHECK: checked_cast_addr_br
// XHECK: } // end sil function 'convert_checked_cast_addr_br_with_private_type'
// xXHECK: store
// xXHECK-NOT: checked_cast_addr_br
// xXHECK-NOT: bb1
// xXHECK: inject_enum_addr %{{.*}} : $*Optional<CustomStringConvertible>, #Optional.none!enumelt
// xXHECK: dealloc_stack
// xXHECK: return
sil [ossa] @convert_checked_cast_addr_br_with_private_type : $@convention(thin) (@in B, @inout _Stdout) -> () {
bb0(%0 : $*B, %1 : $*_Stdout):
%2 = alloc_stack $CustomStringConvertible
%3 = alloc_stack $Optional<CustomStringConvertible>
%4 = init_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
%5 = alloc_stack $B
%6 = load [take] %0 : $*B
store %6 to [init] %5 : $*B
checked_cast_addr_br take_always B in %5 : $*B to CustomStringConvertible in %4 : $*CustomStringConvertible, bb1, bb22
bb1:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
br bb2
bb2:
dealloc_stack %5 : $*B
destroy_addr %3 : $*Optional<CustomStringConvertible>
dealloc_stack %3 : $*Optional<CustomStringConvertible>
%12 = integer_literal $Builtin.Int1, -1
%13 = integer_literal $Builtin.Int1, 0
%26 = tuple ()
dealloc_stack %2 : $*CustomStringConvertible
return %26 : $()
bb22:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.none!enumelt
br bb2
}
// Check that a checked_cast_addr_br converting a known type into a protocol type
// is performed at the compile-time if protocol conformances are statically known.
// In a negative case, take care that cast for private types are not folded if one
// of its superclasses could have a conformance extension defined elsewhere.
//
// CHECK-LABEL: sil [ossa] @convert_checked_cast_addr_br_with_non_private_superclass : $@convention(thin) (@in D, @inout _Stdout) -> ()
// XHECK: checked_cast_addr_br
// XHECK: inject_enum_addr %{{.*}} : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
// XHECK: dealloc_stack
// XHECK: return
// XHECK: inject_enum_addr %{{.*}} : $*Optional<CustomStringConvertible>, #Optional.none!enumelt
// XHECK: }
sil [ossa] @convert_checked_cast_addr_br_with_non_private_superclass : $@convention(thin) (@in D, @inout _Stdout) -> () {
bb0(%0 : $*D, %1 : $*_Stdout):
%2 = alloc_stack $CustomStringConvertible
%3 = alloc_stack $Optional<CustomStringConvertible>
%4 = init_enum_data_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
%5 = alloc_stack $D
%6 = load [take] %0 : $*D
store %6 to [init] %5 : $*D
checked_cast_addr_br take_always D in %5 : $*D to CustomStringConvertible in %4 : $*CustomStringConvertible, bb1, bb22
bb1:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.some!enumelt
br bb2
bb2:
dealloc_stack %5 : $*D
destroy_addr %3 : $*Optional<CustomStringConvertible>
dealloc_stack %3 : $*Optional<CustomStringConvertible>
%12 = integer_literal $Builtin.Int1, -1
%13 = integer_literal $Builtin.Int1, 0
%26 = tuple ()
dealloc_stack %2 : $*CustomStringConvertible
return %26 : $()
bb22:
inject_enum_addr %3 : $*Optional<CustomStringConvertible>, #Optional.none!enumelt
br bb2
}
|