[ScopInfo] Keep scalar acceess dictionaries up-to-data. NFC.

When removing a MemoryAccess, also remove it from maps pointing to it.
This was already done for InstructionToAccess, but not yet for
ValueReads, ValueWrites and PHIWrites as those were only used during
the ScopBuilder phase. Keeping them updated allows us to use them
later as well.

llvm-svn: 302836
This commit is contained in:
Michael Kruse 2017-05-11 22:56:12 +00:00
parent 43bbeb4c9f
commit e60eca7316
2 changed files with 27 additions and 0 deletions

View File

@ -1253,6 +1253,9 @@ private:
llvm::SmallVectorImpl<MemoryAccess *> &Loads);
//@}
/// Remove @p MA from dictionaries pointing to them.
void removeAccessData(MemoryAccess *MA);
public:
~ScopStmt();

View File

@ -1858,6 +1858,24 @@ void ScopStmt::print(raw_ostream &OS) const {
void ScopStmt::dump() const { print(dbgs()); }
void ScopStmt::removeAccessData(MemoryAccess *MA) {
if (MA->isRead() && MA->isOriginalValueKind()) {
bool Found = ValueReads.erase(MA->getAccessValue());
(void)Found;
assert(Found && "Expected access data not found");
}
if (MA->isWrite() && MA->isOriginalValueKind()) {
bool Found = ValueWrites.erase(cast<Instruction>(MA->getAccessValue()));
(void)Found;
assert(Found && "Expected access data not found");
}
if (MA->isWrite() && MA->isOriginalAnyPHIKind()) {
bool Found = PHIWrites.erase(cast<PHINode>(MA->getAccessInstruction()));
(void)Found;
assert(Found && "Expected access data not found");
}
}
void ScopStmt::removeMemoryAccess(MemoryAccess *MA) {
// Remove the memory accesses from this statement together with all scalar
// accesses that were caused by it. MemoryKind::Value READs have no access
@ -1868,6 +1886,10 @@ void ScopStmt::removeMemoryAccess(MemoryAccess *MA) {
auto Predicate = [&](MemoryAccess *Acc) {
return Acc->getAccessInstruction() == MA->getAccessInstruction();
};
for (auto *MA : MemAccs) {
if (Predicate(MA))
removeAccessData(MA);
}
MemAccs.erase(std::remove_if(MemAccs.begin(), MemAccs.end(), Predicate),
MemAccs.end());
InstructionToAccess.erase(MA->getAccessInstruction());
@ -1878,6 +1900,8 @@ void ScopStmt::removeSingleMemoryAccess(MemoryAccess *MA) {
assert(MAIt != MemAccs.end());
MemAccs.erase(MAIt);
removeAccessData(MA);
auto It = InstructionToAccess.find(MA->getAccessInstruction());
if (It != InstructionToAccess.end()) {
It->second.remove(MA);