[LoopAccesses] Factor out RuntimePointerCheck::needsChecking
authorAdam Nemet <anemet@apple.com>
Wed, 18 Feb 2015 03:43:58 +0000 (03:43 +0000)
committerAdam Nemet <anemet@apple.com>
Wed, 18 Feb 2015 03:43:58 +0000 (03:43 +0000)
Will be used by the new RuntimePointerCheck::print.

This is part of the patchset that converts LoopAccessAnalysis into an
actual analysis pass.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229629 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/LoopAccessAnalysis.h
lib/Analysis/LoopAccessAnalysis.cpp

index 3f85fdf765b0cfdcbe4c6a70e71f74d24b9668d1..e05f99726f297639bdc98eacd425d9a67ca44f71 100644 (file)
@@ -116,6 +116,10 @@ public:
     void insert(ScalarEvolution *SE, Loop *Lp, Value *Ptr, bool WritePtr,
                 unsigned DepSetId, unsigned ASId, ValueToValueMap &Strides);
 
+    /// \brief Decide whether we need to issue a run-time check for pointer at
+    /// index \p I and \p J to prove their independence.
+    bool needsChecking(unsigned I, unsigned J) const;
+
     /// This flag indicates if we need to add the runtime check.
     bool Need;
     /// Holds the pointers that we need to check.
index 4ccd135f8949850fefbe215966e624981d752c55..e9e9be31ff74f626cbf542abd1ab51075326c62a 100644 (file)
@@ -93,6 +93,23 @@ void LoopAccessInfo::RuntimePointerCheck::insert(ScalarEvolution *SE, Loop *Lp,
   AliasSetId.push_back(ASId);
 }
 
+bool LoopAccessInfo::RuntimePointerCheck::needsChecking(unsigned I,
+                                                        unsigned J) const {
+  // No need to check if two readonly pointers intersect.
+  if (!IsWritePtr[I] && !IsWritePtr[J])
+    return false;
+
+  // Only need to check pointers between two different dependency sets.
+  if (DependencySetId[I] == DependencySetId[J])
+    return false;
+
+  // Only need to check pointers in the same alias set.
+  if (AliasSetId[I] != AliasSetId[J])
+    return false;
+
+  return true;
+}
+
 namespace {
 /// \brief Analyses memory accesses in a loop.
 ///
@@ -1147,15 +1164,7 @@ LoopAccessInfo::addRuntimeCheck(Instruction *Loc) {
   Value *MemoryRuntimeCheck = nullptr;
   for (unsigned i = 0; i < NumPointers; ++i) {
     for (unsigned j = i+1; j < NumPointers; ++j) {
-      // No need to check if two readonly pointers intersect.
-      if (!PtrRtCheck.IsWritePtr[i] && !PtrRtCheck.IsWritePtr[j])
-        continue;
-
-      // Only need to check pointers between two different dependency sets.
-      if (PtrRtCheck.DependencySetId[i] == PtrRtCheck.DependencySetId[j])
-       continue;
-      // Only need to check pointers in the same alias set.
-      if (PtrRtCheck.AliasSetId[i] != PtrRtCheck.AliasSetId[j])
+      if (!PtrRtCheck.needsChecking(i, j))
         continue;
 
       unsigned AS0 = Starts[i]->getType()->getPointerAddressSpace();