mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Beside supporting OSSA, this change significantly simplifies the pass. The main change is that instead of starting at a closure (e.g. `partial_apply`) and finding all call sites, we now start at a call site and look for closures for all arguments. This makes a lot of things much simpler, e.g. not so many intermediate data structures are required to track all the states. I needed to remove the 3 unit tests because the things those tests were testing are not there anymore. However, the pass is tested with a lot of sil tests (and I added quite a few), which should give good test coverage. The old ClosureSpecializer pass is still kept in place, because at that point in the pipeline we don't have OSSA, yet. Once we have that, we can replace the old pass withe the new one. However, the autodiff closure specializer already runs in the OSSA pipeline and there the new changes take effect.
42 lines
2.3 KiB
Plaintext
42 lines
2.3 KiB
Plaintext
// RUN: %target-sil-opt -sil-print-types -enable-sil-opaque-values -enable-sil-verify-all -closure-specialization %s | %FileCheck %s
|
|
|
|
struct TestView {}
|
|
struct TestRange {}
|
|
struct TestSlice {}
|
|
|
|
// helper
|
|
sil [ossa] @closure : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> () {
|
|
bb0(%0 : $*TestView, %1 : $TestRange, %2 : $TestSlice):
|
|
%1284 = tuple ()
|
|
return %1284 : $()
|
|
}
|
|
|
|
// helper
|
|
sil [ossa] @thunk : $@convention(thin) (@inout TestView, @owned @callee_owned (@inout TestView) -> ()) -> () {
|
|
bb0(%0 : $*TestView, %1 : @owned $@callee_owned (@inout TestView) ->()):
|
|
%call = apply %1(%0) : $@callee_owned (@inout TestView) -> ()
|
|
%1284 = tuple ()
|
|
return %1284 : $()
|
|
}
|
|
|
|
// Test that ClosureSpecializer can handle captured @in args, in addition to direct args.
|
|
//
|
|
// CHECK-LABEL: sil [ossa] @testSpecializeThunk : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> () {
|
|
// CHECK: bb0(%0 : $*TestView, %1 : $TestRange, %2 : $TestSlice):
|
|
// CHECK: [[CLOSURE:%.*]] = function_ref @closure : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> ()
|
|
// CHECK: [[THUNK:%.*]] = function_ref @thunk : $@convention(thin) (@inout TestView, @owned @callee_owned (@inout TestView) -> ()) -> ()
|
|
// CHECK: [[SPECIALIZED:%.*]] = function_ref @$s5thunk7closure4main9TestRangeVAC0D5SliceVTf1nc_n : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> ()
|
|
// CHECK: [[CALL:%.*]] = apply [[SPECIALIZED]](%0, %1, %2) : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> ()
|
|
// CHECK: %{{.*}} = tuple ()
|
|
// CHECK: return %{{.*}} : $()
|
|
// CHECK-LABEL: } // end sil function 'testSpecializeThunk'
|
|
sil [ossa] @testSpecializeThunk : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> () {
|
|
bb0(%0 : $*TestView, %1 : $TestRange, %2 : $TestSlice):
|
|
%closurefn = function_ref @closure : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> ()
|
|
%pa = partial_apply %closurefn(%1, %2) : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> ()
|
|
%thunk = function_ref @thunk : $@convention(thin) (@inout TestView, @owned @callee_owned (@inout TestView) -> ()) -> ()
|
|
%call = apply %thunk(%0, %pa) : $@convention(thin) (@inout TestView, @owned @callee_owned (@inout TestView) -> ()) -> ()
|
|
%1284 = tuple ()
|
|
return %1284 : $()
|
|
}
|