diff options
author | Johannes Doerfert <jdoerfert@anl.gov> | 2019-10-07 23:14:58 +0000 |
---|---|---|
committer | Johannes Doerfert <jdoerfert@anl.gov> | 2019-10-07 23:14:58 +0000 |
commit | 661db04b98c9905ec38a218bd421327b7b888c13 (patch) | |
tree | 6a085c8304615d81013b787fdff3c91e3b7c72e8 /llvm/lib/Transforms | |
parent | 2fdec42a167c7325f771ba340c3a5eff3d33061a (diff) | |
download | bcm5719-llvm-661db04b98c9905ec38a218bd421327b7b888c13.tar.gz bcm5719-llvm-661db04b98c9905ec38a218bd421327b7b888c13.zip |
[Attributor] Use abstract call sites for call site callback
Summary:
When we iterate over uses of functions and expect them to be call sites,
we now use abstract call sites to allow callback calls.
Reviewers: sstefan1, uenoku
Subscribers: hiraditya, bollu, hfinkel, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67871
llvm-svn: 373985
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/IPO/Attributor.cpp | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 6b9888bcdae..6c389f33f73 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -596,11 +596,16 @@ static void clampCallSiteArgumentStates(Attributor &A, const AAType &QueryingAA, // The argument number which is also the call site argument number. unsigned ArgNo = QueryingAA.getIRPosition().getArgNo(); - auto CallSiteCheck = [&](CallSite CS) { - const IRPosition &CSArgPos = IRPosition::callsite_argument(CS, ArgNo); - const AAType &AA = A.getAAFor<AAType>(QueryingAA, CSArgPos); - LLVM_DEBUG(dbgs() << "[Attributor] CS: " << *CS.getInstruction() - << " AA: " << AA.getAsStr() << " @" << CSArgPos << "\n"); + auto CallSiteCheck = [&](AbstractCallSite ACS) { + const IRPosition &ACSArgPos = IRPosition::callsite_argument(ACS, ArgNo); + // Check if a coresponding argument was found or if it is on not associated + // (which can happen for callback calls). + if (ACSArgPos.getPositionKind() == IRPosition::IRP_INVALID) + return false; + + const AAType &AA = A.getAAFor<AAType>(QueryingAA, ACSArgPos); + LLVM_DEBUG(dbgs() << "[Attributor] ACS: " << *ACS.getInstruction() + << " AA: " << AA.getAsStr() << " @" << ACSArgPos << "\n"); const StateType &AAS = static_cast<const StateType &>(AA.getState()); if (T.hasValue()) *T &= AAS; @@ -3100,9 +3105,12 @@ struct AAValueSimplifyArgument final : AAValueSimplifyImpl { ChangeStatus updateImpl(Attributor &A) override { bool HasValueBefore = SimplifiedAssociatedValue.hasValue(); - auto PredForCallSite = [&](CallSite CS) { - return checkAndUpdate(A, *this, *CS.getArgOperand(getArgNo()), - SimplifiedAssociatedValue); + auto PredForCallSite = [&](AbstractCallSite ACS) { + // Check if we have an associated argument or not (which can happen for + // callback calls). + if (Value *ArgOp = ACS.getCallArgOperand(getArgNo())) + return checkAndUpdate(A, *this, *ArgOp, SimplifiedAssociatedValue); + return false; }; if (!A.checkForAllCallSites(PredForCallSite, *this, true)) @@ -3914,9 +3922,9 @@ bool Attributor::isAssumedDead(const AbstractAttribute &AA, return true; } -bool Attributor::checkForAllCallSites(const function_ref<bool(CallSite)> &Pred, - const AbstractAttribute &QueryingAA, - bool RequireAllCallSites) { +bool Attributor::checkForAllCallSites( + const function_ref<bool(AbstractCallSite)> &Pred, + const AbstractAttribute &QueryingAA, bool RequireAllCallSites) { // We can try to determine information from // the call sites. However, this is only possible all call sites are known, // hence the function has internal linkage. @@ -3934,15 +3942,21 @@ bool Attributor::checkForAllCallSites(const function_ref<bool(CallSite)> &Pred, } for (const Use &U : AssociatedFunction->uses()) { - Instruction *I = dyn_cast<Instruction>(U.getUser()); - // TODO: Deal with abstract call sites here. - if (!I) + AbstractCallSite ACS(&U); + if (!ACS) { + LLVM_DEBUG(dbgs() << "[Attributor] Function " + << AssociatedFunction->getName() + << " has non call site use " << *U.get() << " in " + << *U.getUser() << "\n"); return false; + } + Instruction *I = ACS.getInstruction(); Function *Caller = I->getFunction(); - const auto &LivenessAA = getAAFor<AAIsDead>( - QueryingAA, IRPosition::function(*Caller), /* TrackDependence */ false); + const auto &LivenessAA = + getAAFor<AAIsDead>(QueryingAA, IRPosition::function(*Caller), + /* TrackDependence */ false); // Skip dead calls. if (LivenessAA.isAssumedDead(I)) { @@ -3952,22 +3966,22 @@ bool Attributor::checkForAllCallSites(const function_ref<bool(CallSite)> &Pred, continue; } - CallSite CS(U.getUser()); - if (!CS || !CS.isCallee(&U)) { + const Use *EffectiveUse = + ACS.isCallbackCall() ? &ACS.getCalleeUseForCallback() : &U; + if (!ACS.isCallee(EffectiveUse)) { if (!RequireAllCallSites) continue; - - LLVM_DEBUG(dbgs() << "[Attributor] User " << *U.getUser() + LLVM_DEBUG(dbgs() << "[Attributor] User " << EffectiveUse->getUser() << " is an invalid use of " << AssociatedFunction->getName() << "\n"); return false; } - if (Pred(CS)) + if (Pred(ACS)) continue; LLVM_DEBUG(dbgs() << "[Attributor] Call site callback failed for " - << *CS.getInstruction() << "\n"); + << *ACS.getInstruction() << "\n"); return false; } @@ -4319,7 +4333,7 @@ ChangeStatus Attributor::run(Module &M) { const auto *LivenessAA = lookupAAFor<AAIsDead>(IRPosition::function(*F)); if (LivenessAA && - !checkForAllCallSites([](CallSite CS) { return false; }, + !checkForAllCallSites([](AbstractCallSite ACS) { return false; }, *LivenessAA, true)) continue; |