From ab8405d6c38b7e94c4c906a59480d1c25561578a Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Thu, 20 Jul 2017 16:47:57 +0000 Subject: [PATCH] [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(). git-svn-id: https://llvm.org/svn/llvm-project/polly/trunk@308630 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/polly/ScopInfo.h | 8 +++++++- lib/Analysis/ScopInfo.cpp | 23 ++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/polly/ScopInfo.h b/include/polly/ScopInfo.h index 8671de60..1c31396e 100644 --- a/include/polly/ScopInfo.h +++ b/include/polly/ScopInfo.h @@ -1253,6 +1253,9 @@ private: /// will be inserted. DenseMap PHIWrites; + /// Map from PHI nodes to its read access in this statement. + DenseMap 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, diff --git a/lib/Analysis/ScopInfo.cpp b/lib/Analysis/ScopInfo.cpp index b89ed718..80286cfc 100644 --- a/lib/Analysis/ScopInfo.cpp +++ b/lib/Analysis/ScopInfo.cpp @@ -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 *Access) { assert(!PHIWrites.lookup(PHI)); PHIWrites[PHI] = Access; + } else if (Access->isAnyPHIKind() && Access->isRead()) { + PHINode *PHI = cast(Access->getAccessValue()); + assert(!PHIReads.lookup(PHI)); + + PHIReads[PHI] = Access; } MemAccs.push_back(Access); @@ -2017,6 +2009,11 @@ void ScopStmt::removeAccessData(MemoryAccess *MA) { (void)Found; assert(Found && "Expected access data not found"); } + if (MA->isRead() && MA->isOriginalAnyPHIKind()) { + bool Found = PHIReads.erase(cast(MA->getAccessInstruction())); + (void)Found; + assert(Found && "Expected access data not found"); + } } void ScopStmt::removeMemoryAccess(MemoryAccess *MA) { -- 2.11.4.GIT