From aaa5270c5362c60402ecc3e64e647b79791ea468 Mon Sep 17 00:00:00 2001 From: Stefan Stipanovic Date: Wed, 7 Aug 2019 18:26:02 +0000 Subject: [PATCH] [Attributor] Introduce checkForAllReadWriteInstructions(...). Summary: Similarly to D65731 `Attributor::checkForAllReadWriteInstructions` is introduced. Reviewers: jdoerfert, uenoku Subscribers: hiraditya, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65825 llvm-svn: 368194 --- llvm/include/llvm/Transforms/IPO/Attributor.h | 9 +++++ llvm/lib/Transforms/IPO/Attributor.cpp | 54 +++++++++++++++++---------- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h index 1129b28..b41d9e4 100644 --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -290,6 +290,15 @@ struct Attributor { (unsigned)Instruction::Call}); } + /// Check \p Pred on all Read/Write instructions. + /// + /// This method will evaluate \p Pred on all instructions that read or write + /// to memory present in \p InfoCache and return true if \p Pred holds on all + /// of them. + bool checkForAllReadWriteInstructions( + const Function &F, const llvm::function_ref &Pred, + AbstractAttribute &QueryingAA, InformationCache &InfoCache); + private: /// The set of all abstract attributes. ///{ diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index d98028a..d25d532 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -929,33 +929,28 @@ ChangeStatus AANoSyncImpl::updateImpl(Attributor &A, InformationCache &InfoCache) { Function &F = getAnchorScope(); - auto *LivenessAA = A.getAAFor(*this, F); + auto CheckRWInstForNoSync = [&](Instruction &I) { + /// We are looking for volatile instructions or Non-Relaxed atomics. + /// FIXME: We should ipmrove the handling of intrinsics. - /// We are looking for volatile instructions or Non-Relaxed atomics. - /// FIXME: We should ipmrove the handling of intrinsics. - for (Instruction *I : InfoCache.getReadOrWriteInstsForFunction(F)) { - // Skip assumed dead instructions. - if (LivenessAA && LivenessAA->isAssumedDead(I)) - continue; - - ImmutableCallSite ICS(I); - auto *NoSyncAA = A.getAAFor(*this, *I); + ImmutableCallSite ICS(&I); + auto *NoSyncAA = A.getAAFor(*this, I); - if (isa(I) && isNoSyncIntrinsic(I)) - continue; + if (isa(&I) && isNoSyncIntrinsic(&I)) + return true; if (ICS && (!NoSyncAA || !NoSyncAA->isAssumedNoSync()) && !ICS.hasFnAttr(Attribute::NoSync)) - return indicatePessimisticFixpoint(); + return false; if (ICS) - continue; + return true; - if (!isVolatile(I) && !isNonRelaxedAtomic(I)) - continue; + if (!isVolatile(&I) && !isNonRelaxedAtomic(&I)) + return true; - return indicatePessimisticFixpoint(); - } + return false; + }; auto CheckForNoSync = [&](Instruction &I) { // At this point we handled all read/write effects and they are all @@ -967,8 +962,11 @@ ChangeStatus AANoSyncImpl::updateImpl(Attributor &A, return !ImmutableCallSite(&I).isConvergent(); }; - if (!A.checkForAllCallLikeInstructions(F, CheckForNoSync, *this, InfoCache)) + if (!A.checkForAllReadWriteInstructions(F, CheckRWInstForNoSync, *this, + InfoCache) || + !A.checkForAllCallLikeInstructions(F, CheckForNoSync, *this, InfoCache)) return indicatePessimisticFixpoint(); + return ChangeStatus::UNCHANGED; } @@ -2269,6 +2267,24 @@ bool Attributor::checkForAllInstructions( return true; } +bool Attributor::checkForAllReadWriteInstructions( + const Function &F, const llvm::function_ref &Pred, + AbstractAttribute &QueryingAA, InformationCache &InfoCache) { + + auto *LivenessAA = getAAFor(QueryingAA, F); + + for (Instruction *I : InfoCache.getReadOrWriteInstsForFunction(F)) { + // Skip dead instructions. + if (LivenessAA && LivenessAA->isAssumedDead(I)) + continue; + + if (!Pred(*I)) + return false; + } + + return true; +} + ChangeStatus Attributor::run(InformationCache &InfoCache) { // Initialize all abstract attributes. for (AbstractAttribute *AA : AllAbstractAttributes) -- 2.7.4