[llvm] r368194 - [Attributor] Introduce checkForAllReadWriteInstructions(...).

Stefan Stipanovic via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 7 11:26:02 PDT 2019


Author: sstefan
Date: Wed Aug  7 11:26:02 2019
New Revision: 368194

URL: http://llvm.org/viewvc/llvm-project?rev=368194&view=rev
Log:
[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

Modified:
    llvm/trunk/include/llvm/Transforms/IPO/Attributor.h
    llvm/trunk/lib/Transforms/IPO/Attributor.cpp

Modified: llvm/trunk/include/llvm/Transforms/IPO/Attributor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/Attributor.h?rev=368194&r1=368193&r2=368194&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/Attributor.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/Attributor.h Wed Aug  7 11:26:02 2019
@@ -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<bool(Instruction &)> &Pred,
+      AbstractAttribute &QueryingAA, InformationCache &InfoCache);
+
 private:
   /// The set of all abstract attributes.
   ///{

Modified: llvm/trunk/lib/Transforms/IPO/Attributor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Attributor.cpp?rev=368194&r1=368193&r2=368194&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Attributor.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Attributor.cpp Wed Aug  7 11:26:02 2019
@@ -929,33 +929,28 @@ ChangeStatus AANoSyncImpl::updateImpl(At
                                       InformationCache &InfoCache) {
   Function &F = getAnchorScope();
 
-  auto *LivenessAA = A.getAAFor<AAIsDead>(*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<AANoSyncImpl>(*this, *I);
+    ImmutableCallSite ICS(&I);
+    auto *NoSyncAA = A.getAAFor<AANoSyncImpl>(*this, I);
 
-    if (isa<IntrinsicInst>(I) && isNoSyncIntrinsic(I))
-      continue;
+    if (isa<IntrinsicInst>(&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(At
     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;
 }
 
@@ -2267,6 +2265,24 @@ bool Attributor::checkForAllInstructions
   }
 
   return true;
+}
+
+bool Attributor::checkForAllReadWriteInstructions(
+    const Function &F, const llvm::function_ref<bool(Instruction &)> &Pred,
+    AbstractAttribute &QueryingAA, InformationCache &InfoCache) {
+
+  auto *LivenessAA = getAAFor<AAIsDead>(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) {




More information about the llvm-commits mailing list