|
1 | 1 | // RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -inline -sil-inline-generics=true | %FileCheck %s
|
| 2 | +// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -inline -sil-inline-generics=false | %FileCheck --check-prefix=DISABLED-GENERIC-INLINING-CHECK %s |
2 | 3 |
|
3 | 4 | sil_stage canonical
|
4 | 5 |
|
@@ -112,6 +113,68 @@ bb0(%0 : $T, %1 : $@callee_owned (@owned P) -> Bool):
|
112 | 113 | return %3 : $Bool
|
113 | 114 | } // end sil function 'thunk2'
|
114 | 115 |
|
| 116 | + |
| 117 | +sil [always_inline] @alwaysInlineGenericCallee : $@convention(thin) <T> (@in T) -> @out T { |
| 118 | +bb0(%0 : $*T, %1 : $*T): |
| 119 | + copy_addr [take] %1 to [initialization] %0 : $*T |
| 120 | + %4 = tuple () |
| 121 | + return %4 : $() |
| 122 | +} // end sil function 'alwaysInlineGenericCallee' |
| 123 | + |
| 124 | +sil [transparent] @transparentGenericCallee : $@convention(thin) <T> (@in T) -> @out T { |
| 125 | +bb0(%0 : $*T, %1 : $*T): |
| 126 | + copy_addr [take] %1 to [initialization] %0 : $*T |
| 127 | + %4 = tuple () |
| 128 | + return %4 : $() |
| 129 | +} // end sil function 'transparentInlineGenericCallee' |
| 130 | + |
| 131 | + |
| 132 | +// Check that [always_inline] and [transparent] functions are inlined even if |
| 133 | +// inlining of generics is disabled. Regular generic functions should not be |
| 134 | +// inlined. |
| 135 | +// DISABLED-GENERIC-INLINING-CHECK-LABEL: sil @testComplexInliningOfGenerics |
| 136 | +// DISABLED-GENERIC-INLINING-CHECK-NOT: function_ref @{{.*}} |
| 137 | +// DISABLED-GENERIC-INLINING-CHECK-NOT: apply |
| 138 | +// DISABLED-GENERIC-INLINING-CHECK: [[FUNC:%[0-9]+]] = function_ref @genericFoo |
| 139 | +// DISABLED-GENERIC-INLINING-CHECK: apply [[FUNC]] |
| 140 | +// DISABLED-GENERIC-INLINING-CHECK-NOT: function_ref |
| 141 | +// DISABLED-GENERIC-INLINING-CHECK-NOT: apply |
| 142 | +// DISABLED-GENERIC-INLINING-CHECK: end sil function 'testComplexInliningOfGenerics' |
| 143 | + |
| 144 | +// Check that all callees are inlined if inlining of generics is enabled. |
| 145 | +// CHECK-LABEL: sil @testComplexInliningOfGenerics |
| 146 | +// CHECK-NOT: apply |
| 147 | +// CHECK: end sil function 'testComplexInliningOfGenerics' |
| 148 | +sil @testComplexInliningOfGenerics : $@convention(thin) <T> (@in T) -> @out T { |
| 149 | +bb0(%0 : $*T, %1 : $*T): |
| 150 | + |
| 151 | + // Call an [always_inline] function. |
| 152 | + %3 = function_ref @alwaysInlineGenericCallee : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0 |
| 153 | + %4 = alloc_stack $T |
| 154 | + copy_addr %1 to [initialization] %4 : $*T |
| 155 | + %6 = apply %3<T>(%0, %4) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0 |
| 156 | + dealloc_stack %4 : $*T |
| 157 | + |
| 158 | + // Call a [transparent] function. |
| 159 | + %8 = function_ref @transparentGenericCallee : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0 |
| 160 | + %9 = alloc_stack $T |
| 161 | + copy_addr %1 to [initialization] %9 : $*T |
| 162 | + %10 = apply %8<T>(%0, %9) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0 |
| 163 | + dealloc_stack %9 : $*T |
| 164 | + |
| 165 | + // Call a regular function. |
| 166 | + // function_ref genericFoo<A> (A) -> A |
| 167 | + %12 = function_ref @genericFoo : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0 |
| 168 | + %13 = alloc_stack $T |
| 169 | + copy_addr %1 to [initialization] %13 : $*T |
| 170 | + %15 = apply %12<T>(%0, %13) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> @out τ_0_0 |
| 171 | + dealloc_stack %13 : $*T |
| 172 | + |
| 173 | + destroy_addr %1 : $*T |
| 174 | + %18 = tuple () |
| 175 | + return %18 : $() |
| 176 | +} // end sil function 'testComplexInliningOfGenerics' |
| 177 | + |
115 | 178 | sil_default_witness_table P {
|
116 | 179 | no_default
|
117 | 180 | }
|
0 commit comments