[polly] 8e06bf6 - [Polly] Ensure consistent Scop::InstStmtMap. NFC.
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 22 08:22:13 PDT 2020
Author: Michael Kruse
Date: 2020-08-22T10:14:20-05:00
New Revision: 8e06bf6b3a2e8d25e56cd52dca0cf3ff1b37b5d1
URL: https://github.com/llvm/llvm-project/commit/8e06bf6b3a2e8d25e56cd52dca0cf3ff1b37b5d1
DIFF: https://github.com/llvm/llvm-project/commit/8e06bf6b3a2e8d25e56cd52dca0cf3ff1b37b5d1.diff
LOG: [Polly] Ensure consistent Scop::InstStmtMap. NFC.
InstStmtMap became inconsistent with ScopStmt::getInstructions() after
the statement's instructions is modified, e.g. by being considered
unused by the Simplify pass or being moved by ForwardOpTree.
Change ScopStmt::setInstructions() to also update its parent's
InstStmtMap. Also add assertions checking the consistency.
Added:
Modified:
polly/include/polly/ScopInfo.h
polly/lib/Analysis/ScopInfo.cpp
Removed:
################################################################################
diff --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h
index b6fcddc6379a..7b6f13627826 100644
--- a/polly/include/polly/ScopInfo.h
+++ b/polly/include/polly/ScopInfo.h
@@ -1539,9 +1539,7 @@ class ScopStmt {
/// Set the list of instructions for this statement. It replaces the current
/// list.
- void setInstructions(ArrayRef<Instruction *> Range) {
- Instructions.assign(Range.begin(), Range.end());
- }
+ void setInstructions(ArrayRef<Instruction *> Range);
std::vector<Instruction *>::const_iterator insts_begin() const {
return Instructions.begin();
@@ -1949,7 +1947,7 @@ class Scop {
void addScopStmt(Region *R, StringRef Name, Loop *SurroundingLoop,
std::vector<Instruction *> EntryBlockInstructions);
- /// Removes @p Stmt from the StmtMap.
+ /// Removes @p Stmt from the StmtMap and InstStmtMap.
void removeFromStmtMap(ScopStmt &Stmt);
/// Removes all statements where the entry block of the statement does not
@@ -2362,6 +2360,12 @@ class Scop {
return InstStmtMap.lookup(Inst);
}
+ /// Update the content of InstStmtMap for @p Stmt. @p OldList contains the
+ /// previous instructions in @p Stmt and is updated to contain the
+ /// instructions in @p NewList.
+ void updateInstStmtMap(ArrayRef<Instruction *> OldList,
+ ArrayRef<Instruction *> NewList, ScopStmt *Stmt);
+
/// Return the number of statements in the SCoP.
size_t getSize() const { return Stmts.size(); }
diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index fdb06be00546..da3e618a4c4a 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -1249,6 +1249,11 @@ BasicBlock *ScopStmt::getEntryBlock() const {
unsigned ScopStmt::getNumIterators() const { return NestLoops.size(); }
+void ScopStmt::setInstructions(ArrayRef<Instruction *> Range) {
+ getParent()->updateInstStmtMap(Instructions, Range, this);
+ Instructions.assign(Range.begin(), Range.end());
+}
+
const char *ScopStmt::getBaseName() const { return BaseName.c_str(); }
Loop *ScopStmt::getLoopForDimension(unsigned Dimension) const {
@@ -1728,8 +1733,10 @@ Scop::Scop(Region &R, ScalarEvolution &ScalarEvolution, LoopInfo &LI,
Scop::~Scop() = default;
void Scop::removeFromStmtMap(ScopStmt &Stmt) {
- for (Instruction *Inst : Stmt.getInstructions())
+ for (Instruction *Inst : Stmt.getInstructions()) {
+ assert(!InstStmtMap.count(Inst) || InstStmtMap.lookup(Inst) == &Stmt);
InstStmtMap.erase(Inst);
+ }
if (Stmt.isRegionStmt()) {
for (BasicBlock *BB : Stmt.getRegion()->blocks()) {
@@ -1738,8 +1745,10 @@ void Scop::removeFromStmtMap(ScopStmt &Stmt) {
// part of the statement's instruction list.
if (BB == Stmt.getEntryBlock())
continue;
- for (Instruction &Inst : *BB)
+ for (Instruction &Inst : *BB) {
+ assert(!InstStmtMap.count(&Inst) || InstStmtMap.lookup(&Inst) == &Stmt);
InstStmtMap.erase(&Inst);
+ }
}
} else {
auto StmtMapIt = StmtMap.find(Stmt.getBasicBlock());
@@ -1747,9 +1756,16 @@ void Scop::removeFromStmtMap(ScopStmt &Stmt) {
StmtMapIt->second.erase(std::remove(StmtMapIt->second.begin(),
StmtMapIt->second.end(), &Stmt),
StmtMapIt->second.end());
- for (Instruction *Inst : Stmt.getInstructions())
+ for (Instruction *Inst : Stmt.getInstructions()) {
+ assert(!InstStmtMap.count(Inst) || InstStmtMap.lookup(Inst) == &Stmt);
InstStmtMap.erase(Inst);
+ }
}
+
+#ifndef NDEBUG
+ for (auto kv : InstStmtMap)
+ assert(kv.getSecond() != &Stmt);
+#endif
}
void Scop::removeStmts(std::function<bool(ScopStmt &)> ShouldDelete,
@@ -2471,6 +2487,19 @@ ArrayRef<ScopStmt *> Scop::getStmtListFor(Region *R) const {
return getStmtListFor(R->getEntry());
}
+void Scop::updateInstStmtMap(ArrayRef<Instruction *> OldList,
+ ArrayRef<Instruction *> NewList, ScopStmt *Stmt) {
+ for (Instruction *OldInst : OldList) {
+ assert(getStmtFor(OldInst) == Stmt);
+ InstStmtMap.erase(OldInst);
+ }
+
+ for (Instruction *NewInst : NewList) {
+ assert(InstStmtMap.lookup(NewInst) == nullptr);
+ InstStmtMap[NewInst] = Stmt;
+ }
+}
+
int Scop::getRelativeLoopDepth(const Loop *L) const {
if (!L || !R.contains(L))
return -1;
More information about the llvm-commits
mailing list