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
|
// RUN: %target-sil-opt -enable-sil-verify-all %s -cse -o %t.sil
// RUN: %FileCheck %s -check-prefix=CHECK_ID < %t.sil
// RUN: %FileCheck %s -check-prefix=CHECK_OPT < %t.sil
import Builtin
import Swift
class Class {}
protocol P : Class {}
sil @blackhole : $@convention(thin) <T> (@guaranteed T) -> ()
// CHECK-LABEL: sil @test_direct_use_with_dependent_result
// CHECK_ID-NOT: 00000000-0000-0000-0000-000000000002
// CHECK_OPT: bb0(
// CHECK_OPT-NEXT: // function_ref
// CHECK_OPT-NEXT: function_ref @blackhole
// CHECK_OPT-NEXT: open_existential_ref
// CHECK_OPT-NEXT: apply
// CHECK_OPT-NEXT: enum
// CHECK_OPT-NEXT: apply
// CHECK_OPT-NEXT: tuple
// CHECK_OPT-NEXT: return
// CHECK: } // end sil function 'test_direct_use_with_dependent_result'
sil @test_direct_use_with_dependent_result : $@convention(thin) (@guaranteed any P) -> () {
bb0(%p : $any P):
%blackhole = function_ref @blackhole : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
%opened1 = open_existential_ref %p : $any P to $@opened("00000000-0000-0000-0000-000000000001", any P) Self
// Don't let the first opened existential get optimized away.
%void1 = apply %blackhole<@opened("00000000-0000-0000-0000-000000000001", any P) Self>(%opened1) : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
%opened2 = open_existential_ref %p : $any P to $@opened("00000000-0000-0000-0000-000000000002", any P) Self
%optional = enum $Optional<@opened("00000000-0000-0000-0000-000000000002", any P) Self>, #Optional.some!enumelt, %opened2 : $@opened("00000000-0000-0000-0000-000000000002", any P) Self
// Don't let the optional get optimized away.
%void2 = apply %blackhole<Optional<@opened("00000000-0000-0000-0000-000000000002", any P) Self>>(%optional) : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
%result = tuple ()
return %result : $()
}
// CHECK-LABEL: sil @test_use_chain_beginning_with_type_dependent_operand
// CHECK_ID-NOT: 00000000-0000-0000-0000-000000000004
// CHECK_OPT: bb0(
// CHECK_OPT-NEXT: // function_ref
// CHECK_OPT-NEXT: function_ref @blackhole
// CHECK_OPT-NEXT: open_existential_ref
// CHECK_OPT-NEXT: apply
// CHECK_OPT-NEXT: unchecked_ref_cast
// CHECK_OPT-NEXT: enum
// CHECK_OPT-NEXT: = enum
// CHECK_OPT-NEXT: apply
// CHECK_OPT-NEXT: tuple
// CHECK_OPT-NEXT: return
// CHECK: } // end sil function 'test_use_chain_beginning_with_type_dependent_operand'
sil @test_use_chain_beginning_with_type_dependent_operand: $@convention(thin) (@guaranteed any P, @guaranteed Class) -> () {
bb0(%p : $any P, %class : $Class):
%blackhole = function_ref @blackhole : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
%opened1 = open_existential_ref %p : $any P to $@opened("00000000-0000-0000-0000-000000000003", any P) Self
// Don't let the first opened existential get optimized away.
%void1 = apply %blackhole<@opened("00000000-0000-0000-0000-000000000003", any P) Self>(%opened1) : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
%opened2 = open_existential_ref %p : $any P to $@opened("00000000-0000-0000-0000-000000000004", any P) Self
%refcast = unchecked_ref_cast %class : $Class to $@opened("00000000-0000-0000-0000-000000000004", any P) Self
%optional4 = enum $Optional<@opened("00000000-0000-0000-0000-000000000004", any P) Self>, #Optional.some!enumelt, %refcast : $@opened("00000000-0000-0000-0000-000000000004", any P) Self
%optional5 = enum $Optional<Optional<@opened("00000000-0000-0000-0000-000000000004", any P) Self>>, #Optional.some!enumelt, %optional4 : $Optional<@opened("00000000-0000-0000-0000-000000000004", any P) Self>
%void2 = apply %blackhole<Optional<Optional<@opened("00000000-0000-0000-0000-000000000004", any P) Self>>>(%optional5) : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
%result = tuple ()
return %result : $()
}
// CHECK-LABEL: sil @test_use_chain_beginning_with_dependent_result
// CHECK_ID-NOT: 00000000-0000-0000-0000-000000000006
// CHECK_OPT: bb0(
// CHECK_OPT-NEXT: // function_ref
// CHECK_OPT-NEXT: function_ref @blackhole
// CHECK_OPT-NEXT: open_existential_ref
// CHECK_OPT-NEXT: apply
// CHECK_OPT-NEXT: enum
// CHECK_OPT-NEXT: = enum
// CHECK_OPT-NEXT: = enum
// CHECK_OPT-NEXT: apply
// CHECK_OPT-NEXT: tuple
// CHECK_OPT-NEXT: return
// CHECK: } // end sil function 'test_use_chain_beginning_with_dependent_result'
sil @test_use_chain_beginning_with_dependent_result: $@convention(thin) (@guaranteed any P) -> () {
bb0(%p : $any P):
%blackhole = function_ref @blackhole : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
%opened1 = open_existential_ref %p : $any P to $@opened("00000000-0000-0000-0000-000000000005", any P) Self
// Don't let the first opened existential get optimized away.
%void1 = apply %blackhole<@opened("00000000-0000-0000-0000-000000000005", any P) Self>(%opened1) : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
%opened2 = open_existential_ref %p : $any P to $@opened("00000000-0000-0000-0000-000000000006", any P) Self
%optional1 = enum $Optional<@opened("00000000-0000-0000-0000-000000000006", any P) Self>, #Optional.some!enumelt, %opened2 : $@opened("00000000-0000-0000-0000-000000000006", any P) Self
%optional2 = enum $Optional<Optional<@opened("00000000-0000-0000-0000-000000000006", any P) Self>>, #Optional.some!enumelt, %optional1 : $Optional<@opened("00000000-0000-0000-0000-000000000006", any P) Self>
%optional3 = enum $Optional<Optional<Optional<@opened("00000000-0000-0000-0000-000000000006", any P) Self>>>, #Optional.some!enumelt, %optional2 : $Optional<Optional<@opened("00000000-0000-0000-0000-000000000006", any P) Self>>
%void2 = apply %blackhole<Optional<Optional<Optional<@opened("00000000-0000-0000-0000-000000000006", any P) Self>>>>(%optional3) : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
%result = tuple ()
return %result : $()
}
// CHECK-LABEL: sil @test_terminator_inst_indirect_use
// CHECK_ID-NOT: 00000000-0000-0000-0000-000000000008
// CHECK_OPT: bb0(
// CHECK_OPT-NEXT: // function_ref
// CHECK_OPT-NEXT: function_ref @blackhole
// CHECK_OPT-NEXT: open_existential_ref
// CHECK_OPT-NEXT: apply
// CHECK_OPT-NEXT: unchecked_ref_cast
// CHECK_OPT-NEXT: br bb1
// CHECK_OPT-EMPTY:
// CHECK_OPT-NEXT: //
// CHECK_OPT-NEXT: bb1(
// CHECK_OPT-NEXT: apply
// CHECK_OPT-NEXT: tuple
// CHECK_OPT-NEXT: return
// CHECK: } // end sil function 'test_terminator_inst_indirect_use'
sil @test_terminator_inst_indirect_use : $@convention(thin) (@guaranteed any P, @guaranteed Class) -> () {
bb0(%p : $any P, %class : $Class):
%blackhole = function_ref @blackhole : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
%opened1 = open_existential_ref %p : $any P to $@opened("00000000-0000-0000-0000-000000000007", any P) Self
// Don't let the first opened existential get optimized away.
%void1 = apply %blackhole<@opened("00000000-0000-0000-0000-000000000007", any P) Self>(%opened1) : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
%opened2 = open_existential_ref %p : $any P to $@opened("00000000-0000-0000-0000-000000000008", any P) Self
%refcast = unchecked_ref_cast %class : $Class to $@opened("00000000-0000-0000-0000-000000000008", any P) Self
br bb1(%refcast : $@opened("00000000-0000-0000-0000-000000000008", any P) Self)
bb1(%arg : $@opened("00000000-0000-0000-0000-000000000008", any P) Self):
%void2 = apply %blackhole<@opened("00000000-0000-0000-0000-000000000008", any P) Self>(%arg) : $@convention(thin) <τ_0_0> (@guaranteed τ_0_0) -> ()
%result = tuple ()
return %result : $()
}
|