Files
swift-mirror/test/SILOptimizer/closure_specialization_fragile.sil
Erik Eckstein df20d36255 ClosureSpecialization: support for OSSA and a big overhaul
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.
2025-10-06 12:02:48 +02:00

61 lines
2.5 KiB
Plaintext

// RUN: %target-sil-opt %s -verify -closure-specialization -o - | %FileCheck %s
// Make sure we do not specialize resilientCallee.
sil_stage canonical
import Builtin
import Swift
import SwiftShims
@_optimize(none) public func action()
@inline(__always) public func fragileCaller()
public func resilientCallee(fn: () -> ())
// action()
sil [Onone] [ossa] @$s26closure_specialize_fragile6actionyyF : $@convention(thin) () -> () {
bb0:
%0 = tuple ()
return %0 : $()
} // end sil function '$s26closure_specialize_fragile6actionyyF'
// CHECK-LABEL: sil [serialized] [heuristic_always_inline] [ossa] @$s26closure_specialize_fragile0C6CalleryyF : $@convention(thin) () -> ()
// CHECK: function_ref @$s26closure_specialize_fragile15resilientCalleeyyyc2fn_tF : $@convention(thin) (@owned @callee_owned () -> ()) -> ()
// CHECK: return
// fragileCaller()
sil [serialized] [heuristic_always_inline] [ossa] @$s26closure_specialize_fragile0C6CalleryyF : $@convention(thin) () -> () {
bb0:
// function_ref resilientCallee(fn:)
%0 = function_ref @$s26closure_specialize_fragile15resilientCalleeyyyc2fn_tF : $@convention(thin) (@owned @callee_owned () -> ()) -> ()
// function_ref closure #1 in fragileCaller()
%1 = function_ref @$s26closure_specialize_fragile0C6CalleryyFyycfU_ : $@convention(thin) () -> ()
%2 = thin_to_thick_function %1 : $@convention(thin) () -> () to $@callee_owned () -> ()
%3 = apply %0(%2) : $@convention(thin) (@owned @callee_owned () -> ()) -> ()
%4 = tuple ()
return %4 : $()
} // end sil function '$s26closure_specialize_fragile0C6CalleryyF'
// CHECK-LABEL: sil [ossa] @$s26closure_specialize_fragile15resilientCalleeyyyc2fn_tF : $@convention(thin) (@owned @callee_owned () -> ()) -> ()
// resilientCallee(fn:)
sil [ossa] @$s26closure_specialize_fragile15resilientCalleeyyyc2fn_tF : $@convention(thin) (@owned @callee_owned () -> ()) -> () {
bb0(%0 : @owned $@callee_owned () -> ()):
%1 = copy_value %0
%3 = apply %1() : $@callee_owned () -> ()
destroy_value %0
%5 = tuple ()
return %5 : $()
} // end sil function '$s26closure_specialize_fragile15resilientCalleeyyyc2fn_tF'
// closure #1 in fragileCaller()
sil shared [serialized] [ossa] @$s26closure_specialize_fragile0C6CalleryyFyycfU_ : $@convention(thin) () -> () {
bb0:
// function_ref action()
%0 = function_ref @$s26closure_specialize_fragile6actionyyF : $@convention(thin) () -> ()
%1 = apply %0() : $@convention(thin) () -> ()
%2 = tuple ()
return %2 : $()
} // end sil function '$s26closure_specialize_fragile0C6CalleryyFyycfU_'