Skip to content

Commit 0c5d457

Browse files
committed
[arc] guaranteed parameters are always known safe BU.
The reason why this is true is that we know that a guaranteed parameter must out live the current function. That means that no releases on that guaranteed parameter can be "last" releases. rdar://25091228
1 parent 0e40128 commit 0c5d457

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/SILOptimizer/ARC/RCStateTransitionVisitors.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ BottomUpDataflowRCStateVisitor<ARCState>::visitStrongDecrement(ValueBase *V) {
8080
}
8181
}
8282

83+
// A guaranteed function argument is guaranteed to outlive the function we are
84+
// processing. So bottom up for such a parameter, we are always known safe.
85+
if (auto *Arg = dyn_cast<SILArgument>(Op)) {
86+
if (Arg->isFunctionArg() &&
87+
Arg->hasConvention(SILArgumentConvention::Direct_Guaranteed)) {
88+
State.updateKnownSafe(true);
89+
}
90+
}
91+
8392
DEBUG(llvm::dbgs() << " REF COUNT DECREMENT! Known Safe: "
8493
<< (State.isKnownSafe() ? "yes" : "no") << "\n");
8594

test/SILOptimizer/arcsequenceopts.sil

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,3 +2116,18 @@ bb2:
21162116
%5 = tuple()
21172117
return %5 : $()
21182118
}
2119+
2120+
// CHECK-LABEL: sil @guaranteed_always_known_safe_bu : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
2121+
// CHECK: strong_retain
2122+
// CHECK-NOT: strong_retain
2123+
// CHECK-NOT: strong_release
2124+
sil @guaranteed_always_known_safe_bu : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
2125+
bb0(%0 : $Builtin.NativeObject):
2126+
strong_retain %0 : $Builtin.NativeObject
2127+
strong_retain %0 : $Builtin.NativeObject
2128+
%1 = function_ref @use : $@convention(thin) (Builtin.NativeObject) -> ()
2129+
apply %1(%0) : $@convention(thin) (Builtin.NativeObject) -> ()
2130+
apply %1(%0) : $@convention(thin) (Builtin.NativeObject) -> ()
2131+
strong_release %0 : $Builtin.NativeObject
2132+
return undef : $()
2133+
}

0 commit comments

Comments
 (0)