llvm.org GIT mirror llvm / ac96e13
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368194 91177308-0d34-0410-b5e6-96231b3b80d8 Stefan Stipanovic 3 months ago
2 changed file(s) with 48 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
289289 (unsigned)Instruction::Call});
290290 }
291291
292 /// Check \p Pred on all Read/Write instructions.
293 ///
294 /// This method will evaluate \p Pred on all instructions that read or write
295 /// to memory present in \p InfoCache and return true if \p Pred holds on all
296 /// of them.
297 bool checkForAllReadWriteInstructions(
298 const Function &F, const llvm::function_ref &Pred,
299 AbstractAttribute &QueryingAA, InformationCache &InfoCache);
300
292301 private:
293302 /// The set of all abstract attributes.
294303 ///{
928928 InformationCache &InfoCache) {
929929 Function &F = getAnchorScope();
930930
931 auto *LivenessAA = A.getAAFor(*this, F);
932
933 /// We are looking for volatile instructions or Non-Relaxed atomics.
934 /// FIXME: We should ipmrove the handling of intrinsics.
935 for (Instruction *I : InfoCache.getReadOrWriteInstsForFunction(F)) {
936 // Skip assumed dead instructions.
937 if (LivenessAA && LivenessAA->isAssumedDead(I))
938 continue;
939
940 ImmutableCallSite ICS(I);
941 auto *NoSyncAA = A.getAAFor(*this, *I);
942
943 if (isa(I) && isNoSyncIntrinsic(I))
944 continue;
931 auto CheckRWInstForNoSync = [&](Instruction &I) {
932 /// We are looking for volatile instructions or Non-Relaxed atomics.
933 /// FIXME: We should ipmrove the handling of intrinsics.
934
935 ImmutableCallSite ICS(&I);
936 auto *NoSyncAA = A.getAAFor(*this, I);
937
938 if (isa(&I) && isNoSyncIntrinsic(&I))
939 return true;
945940
946941 if (ICS && (!NoSyncAA || !NoSyncAA->isAssumedNoSync()) &&
947942 !ICS.hasFnAttr(Attribute::NoSync))
948 return indicatePessimisticFixpoint();
943 return false;
949944
950945 if (ICS)
951 continue;
952
953 if (!isVolatile(I) && !isNonRelaxedAtomic(I))
954 continue;
955
956 return indicatePessimisticFixpoint();
957 }
946 return true;
947
948 if (!isVolatile(&I) && !isNonRelaxedAtomic(&I))
949 return true;
950
951 return false;
952 };
958953
959954 auto CheckForNoSync = [&](Instruction &I) {
960955 // At this point we handled all read/write effects and they are all
966961 return !ImmutableCallSite(&I).isConvergent();
967962 };
968963
969 if (!A.checkForAllCallLikeInstructions(F, CheckForNoSync, *this, InfoCache))
964 if (!A.checkForAllReadWriteInstructions(F, CheckRWInstForNoSync, *this,
965 InfoCache) ||
966 !A.checkForAllCallLikeInstructions(F, CheckForNoSync, *this, InfoCache))
970967 return indicatePessimisticFixpoint();
968
971969 return ChangeStatus::UNCHANGED;
972970 }
973971
22682266 return true;
22692267 }
22702268
2269 bool Attributor::checkForAllReadWriteInstructions(
2270 const Function &F, const llvm::function_ref &Pred,
2271 AbstractAttribute &QueryingAA, InformationCache &InfoCache) {
2272
2273 auto *LivenessAA = getAAFor(QueryingAA, F);
2274
2275 for (Instruction *I : InfoCache.getReadOrWriteInstsForFunction(F)) {
2276 // Skip dead instructions.
2277 if (LivenessAA && LivenessAA->isAssumedDead(I))
2278 continue;
2279
2280 if (!Pred(*I))
2281 return false;
2282 }
2283
2284 return true;
2285 }
2286
22712287 ChangeStatus Attributor::run(InformationCache &InfoCache) {
22722288 // Initialize all abstract attributes.
22732289 for (AbstractAttribute *AA : AllAbstractAttributes)