Skip to content

Commit

Permalink
Merge pull request swiftlang#1638 from gottesmm/guaranteed-arg-always…
Browse files Browse the repository at this point in the history
…-known-safe-bu

[arc] guaranteed parameters are always known safe BU.
  • Loading branch information
gottesmm committed Mar 11, 2016
2 parents bcb12a5 + 0c5d457 commit e9a1214
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/SILOptimizer/ARC/RCStateTransitionVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ BottomUpDataflowRCStateVisitor<ARCState>::visitStrongDecrement(ValueBase *V) {
}
}

// A guaranteed function argument is guaranteed to outlive the function we are
// processing. So bottom up for such a parameter, we are always known safe.
if (auto *Arg = dyn_cast<SILArgument>(Op)) {
if (Arg->isFunctionArg() &&
Arg->hasConvention(SILArgumentConvention::Direct_Guaranteed)) {
State.updateKnownSafe(true);
}
}

DEBUG(llvm::dbgs() << " REF COUNT DECREMENT! Known Safe: "
<< (State.isKnownSafe() ? "yes" : "no") << "\n");

Expand Down
15 changes: 15 additions & 0 deletions test/SILOptimizer/arcsequenceopts.sil
Original file line number Diff line number Diff line change
Expand Up @@ -2116,3 +2116,18 @@ bb2:
%5 = tuple()
return %5 : $()
}

// CHECK-LABEL: sil @guaranteed_always_known_safe_bu : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
// CHECK: strong_retain
// CHECK-NOT: strong_retain
// CHECK-NOT: strong_release
sil @guaranteed_always_known_safe_bu : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
bb0(%0 : $Builtin.NativeObject):
strong_retain %0 : $Builtin.NativeObject
strong_retain %0 : $Builtin.NativeObject
%1 = function_ref @use : $@convention(thin) (Builtin.NativeObject) -> ()
apply %1(%0) : $@convention(thin) (Builtin.NativeObject) -> ()
apply %1(%0) : $@convention(thin) (Builtin.NativeObject) -> ()
strong_release %0 : $Builtin.NativeObject
return undef : $()
}

0 comments on commit e9a1214

Please sign in to comment.