[polly] r308630 - [ScopInfo] Use map for lookupPHIReadOf. NFC.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 20 09:47:57 PDT 2017


Author: meinersbur
Date: Thu Jul 20 09:47:57 2017
New Revision: 308630

URL: http://llvm.org/viewvc/llvm-project?rev=308630&view=rev
Log:
[ScopInfo] Use map for lookupPHIReadOf. NFC.

Introduce previously missing PHIReads analogous the the already existing
PHIWrites/ValueWrites/ValueReads maps. PHIReads was initially not
required and the later introduced lookupPHIReadOf() used a linear
search instead.

With PHIReads, lookupPHIReadOf() can now also do a map lookup and remove
any surprising performance/behaviour differences to lookupPHIWriteOf(),
lookupValueWriteOf() and lookupValueReadOf().

Modified:
    polly/trunk/include/polly/ScopInfo.h
    polly/trunk/lib/Analysis/ScopInfo.cpp

Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=308630&r1=308629&r2=308630&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Thu Jul 20 09:47:57 2017
@@ -1253,6 +1253,9 @@ private:
   /// will be inserted.
   DenseMap<PHINode *, MemoryAccess *> PHIWrites;
 
+  /// Map from PHI nodes to its read access in this statement.
+  DenseMap<PHINode *, MemoryAccess *> PHIReads;
+
   //@}
 
   /// A SCoP statement represents either a basic block (affine/precise case) or
@@ -1497,7 +1500,10 @@ public:
 
   /// Return the MemoryAccess that loads a PHINode value, or nullptr if not
   /// existing, respectively not yet added.
-  MemoryAccess *lookupPHIReadOf(PHINode *PHI) const;
+  MemoryAccess *lookupPHIReadOf(PHINode *PHI) const {
+    assert(isBlockStmt() || R->getEntry() == PHI->getParent());
+    return PHIReads.lookup(PHI);
+  }
 
   /// Return the PHI write MemoryAccess for the incoming values from any
   ///        basic block in this ScopStmt, or nullptr if not existing,

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=308630&r1=308629&r2=308630&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Thu Jul 20 09:47:57 2017
@@ -1309,19 +1309,6 @@ void ScopStmt::buildAccessRelations() {
   }
 }
 
-MemoryAccess *ScopStmt::lookupPHIReadOf(PHINode *PHI) const {
-  for (auto *MA : *this) {
-    if (!MA->isRead())
-      continue;
-    if (!MA->isOriginalAnyPHIKind())
-      continue;
-
-    if (MA->getAccessInstruction() == PHI)
-      return MA;
-  }
-  return nullptr;
-}
-
 void ScopStmt::addAccess(MemoryAccess *Access) {
   Instruction *AccessInst = Access->getAccessInstruction();
 
@@ -1344,6 +1331,11 @@ void ScopStmt::addAccess(MemoryAccess *A
     assert(!PHIWrites.lookup(PHI));
 
     PHIWrites[PHI] = Access;
+  } else if (Access->isAnyPHIKind() && Access->isRead()) {
+    PHINode *PHI = cast<PHINode>(Access->getAccessValue());
+    assert(!PHIReads.lookup(PHI));
+
+    PHIReads[PHI] = Access;
   }
 
   MemAccs.push_back(Access);
@@ -2017,6 +2009,11 @@ void ScopStmt::removeAccessData(MemoryAc
     (void)Found;
     assert(Found && "Expected access data not found");
   }
+  if (MA->isRead() && MA->isOriginalAnyPHIKind()) {
+    bool Found = PHIReads.erase(cast<PHINode>(MA->getAccessInstruction()));
+    (void)Found;
+    assert(Found && "Expected access data not found");
+  }
 }
 
 void ScopStmt::removeMemoryAccess(MemoryAccess *MA) {




More information about the llvm-commits mailing list