Skip to content

Commit

Permalink
[arc] An apply of a callee_guaranteed thick function is a "guaranteed…
Browse files Browse the repository at this point in the history
… use" of the function.

rdar://37820485
  • Loading branch information
gottesmm committed Feb 25, 2018
1 parent 251093e commit 4941fba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/SILOptimizer/Analysis/ARCAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,24 @@ mayGuaranteedUseValue(SILInstruction *User, SILValue Ptr, AliasAnalysis *AA) {

FullApplySite FAS(User);

// Ok, we have a full apply site. If the apply has no arguments, we don't need
// to worry about any guaranteed parameters.
// Ok, we have a full apply site. Check if the callee is callee_guaranteed. In
// such a case, if we can not prove no alias, we need to be conservative and
// return true.
CanSILFunctionType FType = FAS.getSubstCalleeType();
if (FType->isCalleeGuaranteed() && !AA->isNoAlias(FAS.getCallee(), Ptr)) {
return true;
}

// Ok, we have a full apply site and our callee is a normal use. Thus if the
// apply does not have any normal arguments, we don't need to worry about any
// guaranteed parameters and return early.
if (!FAS.getNumArguments())
return false;

// Ok, we have an apply site with arguments. Look at the function type and
// iterate through the function parameters. If any of the parameters are
// guaranteed, attempt to prove that the passed in parameter cannot alias
// Ptr. If we fail, return true.
CanSILFunctionType FType = FAS.getSubstCalleeType();
auto Params = FType->getParameters();
for (unsigned i : indices(Params)) {
if (!Params[i].isGuaranteed())
Expand Down
17 changes: 17 additions & 0 deletions test/SILOptimizer/arcsequenceopts.sil
Original file line number Diff line number Diff line change
Expand Up @@ -2146,3 +2146,20 @@ bb0(%0 : $*Builtin.NativeObject):
strong_release %1 : $Builtin.NativeObject
return undef : $()
}

// Make sure that we treat applications of callee_guaranteed functions as a
// guaranteed use of the function object.
//
// CHECK-LABEL: sil @test_callee_guaranteed_is_treated_as_guaranteed : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> () {
// CHECK: strong_retain
// CHECK: apply
// CHECK: strong_release
// CHECK: } // end sil function 'test_callee_guaranteed_is_treated_as_guaranteed'
sil @test_callee_guaranteed_is_treated_as_guaranteed : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> () {
bb0(%0 : $@callee_guaranteed () -> ()):
strong_retain %0 : $@callee_guaranteed () -> ()
apply %0() : $@callee_guaranteed () -> ()
strong_release %0 : $@callee_guaranteed () -> ()
%9999 = tuple()
return %9999 : $()
}

0 comments on commit 4941fba

Please sign in to comment.