|
| 1 | +// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -sil-combine -verify-skip-unreachable-must-be-last -sil-combine-disable-alloc-stack-opts | %FileCheck %s |
| 2 | + |
| 3 | +import Builtin |
| 4 | + |
| 5 | +////////////////// |
| 6 | +// Declarations // |
| 7 | +////////////////// |
| 8 | + |
| 9 | +sil @unknown : $@convention(thin) () -> () |
| 10 | + |
| 11 | +///////////////////////////////// |
| 12 | +// Tests for SILCombinerApply. // |
| 13 | +///////////////////////////////// |
| 14 | + |
| 15 | +// Make sure that we handle partial_apply captured arguments correctly. |
| 16 | +// |
| 17 | +// We use custom types here to make it easier to pattern match with FileCheck. |
| 18 | +struct S1 { var x: Builtin.NativeObject } |
| 19 | +struct S2 { var x: Builtin.NativeObject } |
| 20 | +struct S3 { var x: Builtin.NativeObject } |
| 21 | +struct S4 { var x: Builtin.NativeObject } |
| 22 | +struct S5 { var x: Builtin.NativeObject } |
| 23 | +struct S6 { var x: Builtin.NativeObject } |
| 24 | +struct S7 { var x: Builtin.NativeObject } |
| 25 | +struct S8 { var x: Builtin.NativeObject } |
| 26 | +sil @sil_combine_partial_apply_callee : $@convention(thin) (@in S1, @in S2, @in_guaranteed S3, @in_guaranteed S4, @inout S5, S6, @owned S7, @guaranteed S8) -> () |
| 27 | + |
| 28 | +// *NOTE PLEASE READ*. If this test case looks funny to you, it is b/c partial |
| 29 | +// apply is funny. Specifically, even though a partial apply has the conventions |
| 30 | +// of the function on it, arguments to the partial apply (that will be passed |
| 31 | +// off to the function) must /always/ be passed in at +1. This is because the |
| 32 | +// partial apply is building up a boxed aggregate to send off to the closed over |
| 33 | +// function. Of course when you call the function, the proper conventions will |
| 34 | +// be used. |
| 35 | +// |
| 36 | +// CHECK-LABEL: sil @sil_combine_dead_partial_apply : $@convention(thin) (@in S2, @in S4, @inout S5, S6, @owned S7, @guaranteed S8) -> () { |
| 37 | +// CHECK: bb0([[IN_ARG:%.*]] : $*S2, [[INGUARANTEED_ARG:%.*]] : $*S4, [[INOUT_ARG:%.*]] : $*S5, [[UNOWNED_ARG:%.*]] : $S6, [[OWNED_ARG:%.*]] : $S7, [[GUARANTEED_ARG:%.*]] : $S8): |
| 38 | +// |
| 39 | +// CHECK: function_ref unknown |
| 40 | +// CHECK: [[UNKNOWN_FUNC:%.*]] = function_ref @unknown |
| 41 | +// CHECK-NEXT: [[IN_ADDRESS:%.*]] = alloc_stack $S1 |
| 42 | +// CHECK-NEXT: [[INGUARANTEED_ADDRESS:%.*]] = alloc_stack $S3 |
| 43 | +// |
| 44 | +// CHECK-NEXT: apply [[UNKNOWN_FUNC]]() |
| 45 | +// |
| 46 | +// Then make sure that the destroys are placed after the destroy_value of the |
| 47 | +// partial_apply (which is after this apply)... |
| 48 | +// CHECK-NEXT: apply [[UNKNOWN_FUNC]]() |
| 49 | +// |
| 50 | +// CHECK-NEXT: destroy_addr [[IN_ADDRESS]] |
| 51 | +// CHECK-NEXT: destroy_addr [[IN_ARG]] |
| 52 | +// CHECK-NEXT: destroy_addr [[INGUARANTEED_ADDRESS]] |
| 53 | +// CHECK-NEXT: destroy_addr [[INGUARANTEED_ARG]] |
| 54 | +// CHECK-NEXT: release_value [[UNOWNED_ARG]] |
| 55 | +// CHECK-NEXT: release_value [[OWNED_ARG]] |
| 56 | +// CHECK-NEXT: release_value [[GUARANTEED_ARG]] |
| 57 | +// |
| 58 | +// ... but before the function epilog. |
| 59 | +// CHECK-NEXT: apply [[UNKNOWN_FUNC]]() |
| 60 | +// CHECK-NEXT: dealloc_stack [[INGUARANTEED_ADDRESS]] |
| 61 | +// CHECK-NEXT: dealloc_stack [[IN_ADDRESS]] |
| 62 | +// CHECK-NEXT: tuple |
| 63 | +// CHECK-NEXT: return |
| 64 | +// CHECK-NEXT: } // end sil function 'sil_combine_dead_partial_apply' |
| 65 | +sil @sil_combine_dead_partial_apply : $@convention(thin) (@in S2, @in S4, @inout S5, S6, @owned S7, @guaranteed S8) -> () { |
| 66 | +bb0(%1 : $*S2, %2 : $*S4, %4 : $*S5, %5 : $S6, %6 : $S7, %7 : $S8): |
| 67 | + %8 = function_ref @unknown : $@convention(thin) () -> () |
| 68 | + %9 = function_ref @sil_combine_partial_apply_callee : $@convention(thin) (@in S1, @in S2, @in_guaranteed S3, @in_guaranteed S4, @inout S5, S6, @owned S7, @guaranteed S8) -> () |
| 69 | + |
| 70 | + // This is for the @in alloc_stack case. |
| 71 | + %10 = alloc_stack $S1 |
| 72 | + // This is for the @in_guaranteed alloc_stack case. |
| 73 | + %11 = alloc_stack $S3 |
| 74 | + |
| 75 | + // Marker of space in between the alloc_stack and the partial_apply |
| 76 | + apply %8() : $@convention(thin) () -> () |
| 77 | + |
| 78 | + // Now call the partial apply. We use the "unknown" function call after the |
| 79 | + // partial apply to ensure that we are truly placing releases at the partial |
| 80 | + // applies release rather than right afterwards. |
| 81 | + %102 = partial_apply %9(%10, %1, %11, %2, %4, %5, %6, %7) : $@convention(thin) (@in S1, @in S2, @in_guaranteed S3, @in_guaranteed S4, @inout S5, S6, @owned S7, @guaranteed S8) -> () |
| 82 | + |
| 83 | + // Marker of space in between partial_apply and the release of %102. |
| 84 | + apply %8() : $@convention(thin) () -> () |
| 85 | + |
| 86 | + strong_release %102 : $@callee_owned () -> () |
| 87 | + |
| 88 | + apply %8() : $@convention(thin) () -> () |
| 89 | + |
| 90 | + // Epilog. |
| 91 | + |
| 92 | + // Cleanup the stack locations. |
| 93 | + dealloc_stack %11 : $*S3 |
| 94 | + dealloc_stack %10 : $*S1 |
| 95 | + |
| 96 | + %9999 = tuple() |
| 97 | + return %9999 : $() |
| 98 | +} |
0 commit comments