mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
The Swift Simplification pass can do more than the old MandatoryCombine pass: simplification of more instruction types and dead code elimination. The result is a better -Onone performance while still keeping debug info consistent. Currently following code patterns are simplified: * `struct` -> `struct_extract` * `enum` -> `unchecked_enum_data` * `partial_apply` -> `apply` * `br` to a 1:1 related block * `cond_br` with a constant condition * `isConcrete` and `is_same_metadata` builtins More simplifications can be added in the future. rdar://96708429 rdar://104562580
64 lines
3.2 KiB
Plaintext
64 lines
3.2 KiB
Plaintext
// RUN: %target-sil-opt -O -wmo -enable-sil-verify-all -sil-disable-pass=DeadFunctionAndGlobalElimination -sil-disable-pass=function-signature-opts %s | %FileCheck %s
|
|
|
|
// REQUIRES: swift_in_compiler
|
|
|
|
sil_stage canonical
|
|
|
|
import Swift
|
|
|
|
protocol ClassProtocol: AnyObject { func method() }
|
|
|
|
class C: ClassProtocol { func method() {} }
|
|
|
|
// CHECK-LABEL: sil [signature_optimized_thunk] [always_inline] @test_indirect_class_protocol : $@convention(thin) (@in any ClassProtocol) -> ()
|
|
sil [noinline] @test_indirect_class_protocol : $@convention(thin) (@in ClassProtocol) -> () {
|
|
// CHECK: bb0(%0 : $*any ClassProtocol):
|
|
bb0(%0 : $*ClassProtocol):
|
|
destroy_addr %0 : $*ClassProtocol
|
|
return undef : $()
|
|
}
|
|
|
|
// Check that all the opened types are optimized away in the specialization of test_indirect_class_protocol_guaranteed
|
|
// CHECK-LABEL: sil shared @$s39test_indirect_class_protocol_guaranteedTf4e_n : $@convention(thin) <τ_0_0 where τ_0_0 : ClassProtocol> (@in_guaranteed τ_0_0) -> ()
|
|
// CHECK: bb0(%0 : $*τ_0_0):
|
|
// CHECK-NEXT: [[INPUT:%1]] = load %0
|
|
// CHECK-NEXT: [[ARG:%.*]] = unchecked_ref_cast [[INPUT]]
|
|
// CHECK-NEXT: [[METHOD:%.*]] = witness_method $C, #ClassProtocol.method
|
|
// CHECK-NEXT: apply [[METHOD]]<C>([[ARG]])
|
|
// CHECK-NEXT: return undef
|
|
// CHECK: } // end sil function '$s39test_indirect_class_protocol_guaranteedTf4e_n'
|
|
|
|
sil @test_indirect_class_protocol_guaranteed : $@convention(thin) (@in_guaranteed ClassProtocol) -> () {
|
|
bb0(%0 : $*ClassProtocol):
|
|
%1 = load %0 : $*ClassProtocol
|
|
%2 = open_existential_ref %1 : $ClassProtocol to $@opened("ABCDEF01-ABCD-ABCD-ABCD-ABCDEFABCDEF", ClassProtocol) Self
|
|
%f = witness_method $@opened("ABCDEF01-ABCD-ABCD-ABCD-ABCDEFABCDEF", ClassProtocol) Self, #ClassProtocol.method : <Self: ClassProtocol> (Self) -> () -> (), %2 : $@opened("ABCDEF01-ABCD-ABCD-ABCD-ABCDEFABCDEF", ClassProtocol) Self : $@convention(witness_method : ClassProtocol) <Self: ClassProtocol> (@guaranteed Self) -> ()
|
|
apply %f<@opened("ABCDEF01-ABCD-ABCD-ABCD-ABCDEFABCDEF", ClassProtocol) Self>(%2) : $@convention(witness_method : ClassProtocol) <Self: ClassProtocol> (@guaranteed Self) -> ()
|
|
return undef : $()
|
|
}
|
|
|
|
// Check that a specialization of test_indirect_class_protocol is created.
|
|
// CHECK-LABEL: sil shared {{.*}}@$s28test_indirect_class_protocolTf4e_n4main1CC_Tg5 : $@convention(thin) (@owned C) -> ()
|
|
// CHECK: bb0(%0 : $C):
|
|
// CHECK-NEXT: strong_release %0
|
|
// CHECK-NEXT: return undef
|
|
// CHECK-LABEL: end sil function '$s28test_indirect_class_protocolTf4e_n4main1CC_Tg5'
|
|
|
|
sil @invoke_indirect_class_protocol : $@convention(thin) (@guaranteed C) -> () {
|
|
bb0(%0 : $C):
|
|
%1 = init_existential_ref %0 : $C : $C, $ClassProtocol
|
|
|
|
%z = alloc_stack $ClassProtocol
|
|
retain_value %1 : $ClassProtocol
|
|
store %1 to %z : $*ClassProtocol
|
|
|
|
%f = function_ref @test_indirect_class_protocol_guaranteed : $@convention(thin) (@in_guaranteed ClassProtocol) -> ()
|
|
apply %f(%z) : $@convention(thin) (@in_guaranteed ClassProtocol) -> ()
|
|
|
|
%g = function_ref @test_indirect_class_protocol : $@convention(thin) (@in ClassProtocol) -> ()
|
|
apply %g(%z) : $@convention(thin) (@in ClassProtocol) -> ()
|
|
|
|
dealloc_stack %z : $*ClassProtocol
|
|
return undef : $()
|
|
}
|