Skip to content

Commit b275d98

Browse files
committed
ComputeSideEffects: handle reference count reading instructions.
Conservatively model those effects as "destroy" effects.
1 parent 8961e29 commit b275d98

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ private struct CollectedEffects {
168168
is CondFailInst:
169169
break
170170

171+
case is BeginCOWMutationInst, is IsUniqueInst, is IsEscapingClosureInst:
172+
// Model reference count reading as "destroy" for now. Although we could intoduce a "read-refcount"
173+
// effect, it would not give any significant benefit in any of our current optimizations.
174+
addEffects(.destroy, to: inst.operands[0].value, fromInitialPath: SmallProjectionPath(.anyValueFields))
175+
171176
default:
172177
if inst.mayRelease {
173178
globalEffects = .worstEffects

test/SILOptimizer/side_effects.sil

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ bb0(%0 : @guaranteed ${ var Int32 }):
10701070
return %6 : $Int32
10711071
}
10721072

1073+
10731074
// CHECK-LABEL: sil [ossa] @callUnknownIsDeinitBarrier : {{.*}} {
10741075
// CHECK-NEXT: [global: {{.*}}deinit_barrier]
10751076
// CHECK-LABEL: } // end sil function 'callUnknownIsDeinitBarrier'
@@ -1079,3 +1080,36 @@ sil [ossa] @callUnknownIsDeinitBarrier : $@convention(thin) () -> () {
10791080
%retval = tuple ()
10801081
return %retval : $()
10811082
}
1083+
1084+
// CHECK-LABEL: sil @begin_cow_test
1085+
// CHECK-NEXT: [%0: destroy v**]
1086+
// CHECK-NEXT: [global: ]
1087+
// CHECK-NEXT: {{^[^[]}}
1088+
sil @begin_cow_test : $@convention(thin) (@guaranteed X) -> () {
1089+
bb0(%0 : $X):
1090+
(%1, %2) = begin_cow_mutation %0 : $X
1091+
%3 = tuple()
1092+
return %3 : $()
1093+
}
1094+
1095+
// CHECK-LABEL: sil @is_unique_test
1096+
// CHECK-NEXT: [%0: destroy v**]
1097+
// CHECK-NEXT: [global: ]
1098+
// CHECK-NEXT: {{^[^[]}}
1099+
sil @is_unique_test : $@convention(thin) (@inout X) -> () {
1100+
bb0(%0 : $*X):
1101+
%1 = is_unique %0 : $*X
1102+
%3 = tuple()
1103+
return %3 : $()
1104+
}
1105+
1106+
// CHECK-LABEL: sil @is_escaping_closure_test
1107+
// CHECK-NEXT: [%0: destroy v**]
1108+
// CHECK-NEXT: [global: ]
1109+
// CHECK-NEXT: {{^[^[]}}
1110+
sil @is_escaping_closure_test : $@convention(thin)(@guaranteed @callee_guaranteed () -> ()) -> Builtin.Int1 {
1111+
bb0(%0 : $@callee_guaranteed () -> ()):
1112+
%1 = is_escaping_closure %0: $@callee_guaranteed () -> ()
1113+
return %1 : $Builtin.Int1
1114+
}
1115+

0 commit comments

Comments
 (0)