[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().

llvm-svn: 308630
This commit is contained in:
Michael Kruse 2017-07-20 16:47:57 +00:00
parent 4d4624c20c
commit 3562f272cf
2 changed files with 17 additions and 14 deletions

View File

@ -1253,6 +1253,9 @@ private:
/// will be inserted. /// will be inserted.
DenseMap<PHINode *, MemoryAccess *> PHIWrites; 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 /// 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 /// Return the MemoryAccess that loads a PHINode value, or nullptr if not
/// existing, respectively not yet added. /// 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 /// Return the PHI write MemoryAccess for the incoming values from any
/// basic block in this ScopStmt, or nullptr if not existing, /// basic block in this ScopStmt, or nullptr if not existing,

View File

@ -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) { void ScopStmt::addAccess(MemoryAccess *Access) {
Instruction *AccessInst = Access->getAccessInstruction(); Instruction *AccessInst = Access->getAccessInstruction();
@ -1344,6 +1331,11 @@ void ScopStmt::addAccess(MemoryAccess *Access) {
assert(!PHIWrites.lookup(PHI)); assert(!PHIWrites.lookup(PHI));
PHIWrites[PHI] = Access; 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); MemAccs.push_back(Access);
@ -2017,6 +2009,11 @@ void ScopStmt::removeAccessData(MemoryAccess *MA) {
(void)Found; (void)Found;
assert(Found && "Expected access data not 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) { void ScopStmt::removeMemoryAccess(MemoryAccess *MA) {