Skip to content

Commit

Permalink
[Attributor] Move recursion reasoning into AA::isPotentiallyReachable
Browse files Browse the repository at this point in the history
With D106397 we ensured that `AAReachability` will not answer queries for
potentially recursive functions. This was necessary as we did not treat
recursion explicitly otherwise. Now that we have
`AA::isPotentiallyReachable` we can make `AAReachability` a purely
intra-procedural AA which does not care about recursion.
`AA::isPotentiallyReachable`, however, does already deal with "going
back" the call graph and can now do so for potentially recursive
functions.
  • Loading branch information
jdoerfert committed Apr 6, 2022
1 parent ced9a79 commit a8610d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
5 changes: 4 additions & 1 deletion llvm/lib/Transforms/IPO/Attributor.cpp
Expand Up @@ -519,6 +519,8 @@ isPotentiallyReachable(Attributor &A, const Instruction &FromI,
SmallVector<const Instruction *> Worklist;
Worklist.push_back(&FromI);

const auto &NoRecurseAA = A.getAAFor<AANoRecurse>(
QueryingAA, IRPosition::function(ToFn), DepClassTy::OPTIONAL);
while (!Worklist.empty()) {
const Instruction *CurFromI = Worklist.pop_back_val();
if (!Visited.insert(CurFromI).second)
Expand All @@ -538,7 +540,8 @@ isPotentiallyReachable(Attributor &A, const Instruction &FromI,
<< *ToI << " [Intra]\n");
if (Result)
return true;
continue;
if (NoRecurseAA.isAssumedNoRecurse())
continue;
}

// TODO: If we can go arbitrarily backwards we will eventually reach an
Expand Down
13 changes: 3 additions & 10 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Expand Up @@ -3071,10 +3071,6 @@ struct AAReachabilityImpl : AAReachability {

/// See AbstractAttribute::updateImpl(...).
ChangeStatus updateImpl(Attributor &A) override {
const auto &NoRecurseAA = A.getAAFor<AANoRecurse>(
*this, IRPosition::function(*getAnchorScope()), DepClassTy::REQUIRED);
if (!NoRecurseAA.isAssumedNoRecurse())
return indicatePessimisticFixpoint();
return ChangeStatus::UNCHANGED;
}
};
Expand Down Expand Up @@ -3306,12 +3302,6 @@ struct AANoAliasCallSiteArgument final : AANoAliasImpl {
return true;

if (ScopeFn) {
const auto &ReachabilityAA = A.getAAFor<AAReachability>(
*this, IRPosition::function(*ScopeFn), DepClassTy::OPTIONAL);

if (!ReachabilityAA.isAssumedReachable(A, *UserI, *getCtxI()))
return true;

if (auto *CB = dyn_cast<CallBase>(UserI)) {
if (CB->isArgOperand(&U)) {

Expand All @@ -3325,6 +3315,9 @@ struct AANoAliasCallSiteArgument final : AANoAliasImpl {
return true;
}
}

if (!AA::isPotentiallyReachable(A, *UserI, *getCtxI(), *this))
return true;
}

// For cases which can potentially have more users
Expand Down

0 comments on commit a8610d7

Please sign in to comment.