Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIL] Maintain owned argument lifetimes at inlining. #60670

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Test] Adjusted SIL tests.
Changes to teach the optimizer pipeline about move_value require some
corresponding test updates.
  • Loading branch information
nate-chandler committed Jan 26, 2023
commit a3fa2464f4bce10f68ea792808b3e6b8bd46df83
1 change: 1 addition & 0 deletions test/SILOptimizer/arc_crash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Base {
public class Node : Base {
var node: Base

@inline(never)
init(node: Base) { self.node = node }
}
struct Queue {
Expand Down
14 changes: 8 additions & 6 deletions test/SILOptimizer/semantic-arc-opts.sil
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ bb3(%7 : @owned $FakeOptional<Builtin.NativeObject>):

// SemanticARCOptVisitor::performGuaranteedCopyValueOptimization should not optimize this case.
//
// CHECK-LABEL: sil [ossa] @testDeadInterleavedBorrow : $@convention(c) (@owned FakeOptional<AnyObject>) -> () {
// CHECK-LABEL: sil [ossa] @testDeadInterleavedBorrow : $@convention(c) () -> () {
// CHECK: [[B:%.*]] = begin_borrow [lexical] %0 : $FakeOptional<AnyObject>
// CHECK: copy_value
// CHECK: switch_enum
Expand All @@ -1539,8 +1539,9 @@ bb3(%7 : @owned $FakeOptional<Builtin.NativeObject>):
// CHECK: end_borrow
// CHECK: destroy_value [[COPY]] : $AnyObject
// CHECK-LABEL: } // end sil function 'testDeadInterleavedBorrow'
sil [ossa] @testDeadInterleavedBorrow : $@convention(c) (@owned FakeOptional<AnyObject>) -> () {
bb0(%opt : @owned $FakeOptional<AnyObject>):
sil [ossa] @testDeadInterleavedBorrow : $@convention(c) () -> () {
bb0:
%opt = apply undef() : $@convention(thin) () -> (@owned FakeOptional<AnyObject>)
%opt_borrow = begin_borrow [lexical] %opt : $FakeOptional<AnyObject>
%opt_borrow_copy = copy_value %opt_borrow : $FakeOptional<AnyObject>
switch_enum %opt_borrow_copy : $FakeOptional<AnyObject>, case #FakeOptional.some!enumelt: some, case #FakeOptional.none!enumelt: none
Expand All @@ -1567,7 +1568,7 @@ exit:

// SemanticARCOptVisitor::performGuaranteedCopyValueOptimization should not optimize this case.
//
// CHECK-LABEL: sil [ossa] @testDeadAndAliveInterleavedBorrow : $@convention(c) (@owned FakeOptional<AnyObject>) -> () {
// CHECK-LABEL: sil [ossa] @testDeadAndAliveInterleavedBorrow : $@convention(c) () -> () {
// CHECK: [[B:%.*]] = begin_borrow [lexical] %0 : $FakeOptional<AnyObject>
// CHECK: copy_value
// CHECK: switch_enum
Expand All @@ -1586,8 +1587,9 @@ exit:
// CHECK: destroy_value [[COPY]] : $AnyObject
// CHECK: destroy_value %0 : $FakeOptional<AnyObject>
// CHECK-LABEL: } // end sil function 'testDeadAndAliveInterleavedBorrow'
sil [ossa] @testDeadAndAliveInterleavedBorrow : $@convention(c) (@owned FakeOptional<AnyObject>) -> () {
bb0(%opt : @owned $FakeOptional<AnyObject>):
sil [ossa] @testDeadAndAliveInterleavedBorrow : $@convention(c) () -> () {
bb0:
%opt = apply undef() : $@convention(thin) () -> (@owned FakeOptional<AnyObject>)
%opt_borrow = begin_borrow [lexical] %opt : $FakeOptional<AnyObject>
%opt_borrow_copy = copy_value %opt_borrow : $FakeOptional<AnyObject>
switch_enum %opt_borrow_copy : $FakeOptional<AnyObject>, case #FakeOptional.some!enumelt: some, case #FakeOptional.none!enumelt: none
Expand Down
18 changes: 9 additions & 9 deletions test/SILOptimizer/sil_combine_protocol_conf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ public class OtherClass {
// CHECK: load [[S11]]
// CHECK: [[R2:%.*]] = ref_element_addr [[ARG]] : $OtherClass, #OtherClass.arg2
// CHECK: [[ACC2:%.*]] = begin_access [read] [static] [no_nested_conflict] [[R2]]
// CHECK: copy_addr [[ACC2]] to [init] [[T1:%[0-9]*]]
// CHECK: [[O2:%.*]] = open_existential_addr immutable_access [[T1]] : $*any GenericPropProtocol to $*@opened("{{.*}}", any GenericPropProtocol) Self
// CHECK: [[O2:%.*]] = open_existential_addr immutable_access [[ACC2]] : $*any GenericPropProtocol to $*@opened("{{.*}}", any GenericPropProtocol) Self
// CHECK: copy_addr [[O2]] to [init] [[T1:%[0-9]*]]
// CHECK: [[W2:%.*]] = witness_method $@opened("{{.*}}", any GenericPropProtocol) Self, #GenericPropProtocol.val!getter : <Self where Self : GenericPropProtocol> (Self) -> () -> Int, [[O2]] : $*@opened("{{.*}}", any GenericPropProtocol) Self : $@convention(witness_method: GenericPropProtocol) <τ_0_0 where τ_0_0 : GenericPropProtocol> (@in_guaranteed τ_0_0) -> Int
// CHECK: apply [[W2]]<@opened("{{.*}}", any GenericPropProtocol) Self>([[O2]]) : $@convention(witness_method: GenericPropProtocol) <τ_0_0 where τ_0_0 : GenericPropProtocol> (@in_guaranteed τ_0_0) -> Int
// CHECK: apply [[W2]]<@opened("{{.*}}", any GenericPropProtocol) Self>([[T1]]) : $@convention(witness_method: GenericPropProtocol) <τ_0_0 where τ_0_0 : GenericPropProtocol> (@in_guaranteed τ_0_0) -> Int
// CHECK: struct_extract
// CHECK: integer_literal
// CHECK: builtin
Expand All @@ -271,10 +271,10 @@ public class OtherClass {
// CHECK: cond_fail
// CHECK: [[R5:%.*]] = ref_element_addr [[ARG]] : $OtherClass, #OtherClass.arg4
// CHECK: [[ACC5:%.*]] = begin_access [read] [static] [no_nested_conflict] [[R5]]
// CHECK: copy_addr [[ACC5]] to [init] [[T2:%[0-9]+]]
// CHECK: [[O5:%.*]] = open_existential_addr immutable_access [[T2]] : $*any GenericNestedPropProtocol to $*@opened("{{.*}}", any GenericNestedPropProtocol) Self
// CHECK: [[O5:%.*]] = open_existential_addr immutable_access [[ACC5]] : $*any GenericNestedPropProtocol to $*@opened("{{.*}}", any GenericNestedPropProtocol) Self
// CHECK: copy_addr [[O5]] to [init] [[T2:%[0-9]+]]
// CHECK: [[W5:%.*]] = witness_method $@opened("{{.*}}", any GenericNestedPropProtocol) Self, #GenericNestedPropProtocol.val!getter : <Self where Self : GenericNestedPropProtocol> (Self) -> () -> Int, [[O5:%.*]] : $*@opened("{{.*}}", any GenericNestedPropProtocol) Self : $@convention(witness_method: GenericNestedPropProtocol) <τ_0_0 where τ_0_0 : GenericNestedPropProtocol> (@in_guaranteed τ_0_0) -> Int
// CHECK: apply [[W5]]<@opened("{{.*}}", any GenericNestedPropProtocol) Self>([[O5]]) : $@convention(witness_method: GenericNestedPropProtocol) <τ_0_0 where τ_0_0 : GenericNestedPropProtocol> (@in_guaranteed τ_0_0) -> Int
// CHECK: apply [[W5]]<@opened("{{.*}}", any GenericNestedPropProtocol) Self>([[T2]]) : $@convention(witness_method: GenericNestedPropProtocol) <τ_0_0 where τ_0_0 : GenericNestedPropProtocol> (@in_guaranteed τ_0_0) -> Int
// CHECK: struct_extract
// CHECK: builtin
// CHECK: tuple_extract
Expand Down Expand Up @@ -341,10 +341,10 @@ public class OtherKlass {
// CHECK: integer_literal
// CHECK: [[R1:%.*]] = ref_element_addr [[ARG]] : $OtherKlass, #OtherKlass.arg2
// CHECK: [[ACC1:%.*]] = begin_access [read] [static] [no_nested_conflict] [[R1]]
// CHECK: copy_addr [[ACC1]] to [init] [[T1:%[0-9]+]]
// CHECK: [[O1:%.*]] = open_existential_addr immutable_access [[T1]] : $*any AGenericProtocol to $*@opened("{{.*}}", any AGenericProtocol) Self
// CHECK: [[O1:%.*]] = open_existential_addr immutable_access [[ACC1]] : $*any AGenericProtocol to $*@opened("{{.*}}", any AGenericProtocol) Self
// CHECK: copy_addr [[O1]] to [init] [[T1:%[0-9]+]]
// CHECK: [[W1:%.*]] = witness_method $@opened("{{.*}}", any AGenericProtocol) Self, #AGenericProtocol.val!getter : <Self where Self : AGenericProtocol> (Self) -> () -> Int, [[O1]] : $*@opened("{{.*}}", any AGenericProtocol) Self : $@convention(witness_method: AGenericProtocol) <τ_0_0 where τ_0_0 : AGenericProtocol> (@in_guaranteed τ_0_0) -> Int
// CHECK: apply [[W1]]<@opened("{{.*}}", any AGenericProtocol) Self>([[O1]]) : $@convention(witness_method: AGenericProtocol) <τ_0_0 where τ_0_0 : AGenericProtocol> (@in_guaranteed τ_0_0) -> Int
// CHECK: apply [[W1]]<@opened("{{.*}}", any AGenericProtocol) Self>([[T1]]) : $@convention(witness_method: AGenericProtocol) <τ_0_0 where τ_0_0 : AGenericProtocol> (@in_guaranteed τ_0_0) -> Int
// CHECK: struct_extract
// CHECK: integer_literal
// CHECK: builtin
Expand Down
6 changes: 3 additions & 3 deletions test/SILOptimizer/type_wrapper_init_transform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ struct TupleFlatteningTest<K: Collection & Hashable, V> {
// CHECK: [[STORAGE_VAR:%.*]] = alloc_stack $TupleFlatteningTest<K, V>.$Storage
// CHECK: [[STORAGE_INIT_REF:%.*]] = function_ref @$s4test19TupleFlatteningTestV8$StorageV1a1b1c1dAEyxq__GSi_SS_Si_xttSDyxq_Gq_SgtcfC
// CHECK: [[LOCAL_STORAGE_ACCESS:%.*]] = begin_access [read] [unsafe] [[LOCAL_STORAGE:%.*]] : $*(a: Int, b: (String, (Int, K)), c: Dictionary<K, V>, d: Optional<V>)
// CHECK: [[A_REF:%.*]] = tuple_element_addr %73 : $*(a: Int, b: (String, (Int, K)), c: Dictionary<K, V>, d: Optional<V>), 0
// CHECK: [[A_REF:%.*]] = tuple_element_addr {{%[^,]+}} : $*(a: Int, b: (String, (Int, K)), c: Dictionary<K, V>, d: Optional<V>), 0
// CHECK: [[A:%.*]] = load [trivial] [[A_REF]] : $*Int
// CHECK: [[B_TUPLE:%.*]] = tuple_element_addr [[LOCAL_STORAGE_ACCESS]] : $*(a: Int, b: (String, (Int, K)), c: Dictionary<K, V>, d: Optional<V>), 1
// CHECK: [[B_ELT_0_REF:%.*]] = tuple_element_addr [[B_TUPLE]] : $*(String, (Int, K)), 0
Expand Down Expand Up @@ -354,7 +354,7 @@ struct TypeWithLetProperties<T> {
public init(a: T, b: Int? = nil, onSet: (() -> Void)? = nil) {
// CHECK: [[LOCAL_STORAGE_ACCESS:%.*]] = begin_access [modify] [static] [[LOCAL_STORAGE]] : $*(a: T, b: Int)
// CHECK-NEXT: [[A_REF:%.*]] = tuple_element_addr [[LOCAL_STORAGE_ACCESS]] : $*(a: T, b: Int), 0
// CHECK-NEXT: copy_addr [take] %11 to [init] [[A_REF]] : $*T
// CHECK-NEXT: copy_addr [take] {{%[^,]+}} to [init] [[A_REF]] : $*T
// CHECK-NOT: {{.*}} = assign_by_wrapper {{.*}}
// CHECK-NEXT: end_access [[LOCAL_STORAGE_ACCESS]]
self.a = a
Expand Down Expand Up @@ -444,7 +444,7 @@ struct TypeWithDefaultedProperties<T> {
// --> Assignment to `let a`
// CHECK: [[LOCAL_STORAGE_ACCESS:%.*]] = begin_access [modify] [static] [[LOCAL_STORAGE]] : $*(a: Array<String>, b: Optional<T>, c: Int)
// CHECK-NEXT: [[A_REF:%.*]] = tuple_element_addr [[LOCAL_STORAGE_ACCESS]] : $*(a: Array<String>, b: Optional<T>, c: Int), 0
// CHECK-NEXT: assign [[A_ARG:%.*]] to [init] %18 : $*Array<String>
// CHECK-NEXT: assign [[A_ARG:%.*]] to [init] {{%[^,]+}} : $*Array<String>
// CHECK-NEXT: end_access [[LOCAL_STORAGE_ACCESS]]
// --> Assignment to `var c`, note that the assignment is done to a wrapped value
// CHECK: [[C_REF:%.*]] = tuple_element_addr [[LOCAL_STORAGE]] : $*(a: Array<String>, b: Optional<T>, c: Int), 2
Expand Down