[ScopInfo] Use statement lists for entry blocks of region statements
By using statement lists in the entry blocks of region statements, instruction
level analyses also work on region statements.
We currently only model the entry block of a region statements, as this is
sufficient for most transformations the known-passes currently execute. Modeling
instructions in the presence of control flow (e.g. infinite loops) is left
out to not increase code complexity too much. It can be added when good use
cases are found.
This change set is reapplied, after a memory corruption issue had been fixed.
llvm-svn: 312210
diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index 68e624a..18461d0 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -1676,9 +1676,11 @@
ConditionSets);
}
-ScopStmt::ScopStmt(Scop &parent, Region &R, Loop *SurroundingLoop)
+ScopStmt::ScopStmt(Scop &parent, Region &R, Loop *SurroundingLoop,
+ std::vector<Instruction *> EntryBlockInstructions)
: Parent(parent), InvalidDomain(nullptr), Domain(nullptr), R(&R),
- Build(nullptr), SurroundingLoop(SurroundingLoop) {
+ Build(nullptr), SurroundingLoop(SurroundingLoop),
+ Instructions(EntryBlockInstructions) {
BaseName = getIslCompatibleName(
"Stmt", R.getNameStr(), parent.getNextStmtIdx(), "", UseInstructionNames);
}
@@ -1779,7 +1781,7 @@
for (MemoryAccess *Access : MemAccs)
Access->print(OS);
- if (PrintInstructions && isBlockStmt())
+ if (PrintInstructions)
printInstructions(OS.indent(12));
}
@@ -3588,16 +3590,21 @@
}
void Scop::removeFromStmtMap(ScopStmt &Stmt) {
- if (Stmt.isRegionStmt())
+ for (Instruction *Inst : Stmt.getInstructions())
+ InstStmtMap.erase(Inst);
+
+ if (Stmt.isRegionStmt()) {
for (BasicBlock *BB : Stmt.getRegion()->blocks()) {
StmtMap.erase(BB);
+ // Skip entry basic block, as its instructions are already deleted as
+ // part of the statement's instruction list.
+ if (BB == Stmt.getEntryBlock())
+ continue;
for (Instruction &Inst : *BB)
InstStmtMap.erase(&Inst);
}
- else {
+ } else {
StmtMap.erase(Stmt.getBasicBlock());
- for (Instruction *Inst : Stmt.getInstructions())
- InstStmtMap.erase(Inst);
}
}
@@ -4681,12 +4688,22 @@
}
}
-void Scop::addScopStmt(Region *R, Loop *SurroundingLoop) {
+void Scop::addScopStmt(Region *R, Loop *SurroundingLoop,
+ std::vector<Instruction *> Instructions) {
assert(R && "Unexpected nullptr!");
- Stmts.emplace_back(*this, *R, SurroundingLoop);
+ Stmts.emplace_back(*this, *R, SurroundingLoop, Instructions);
auto *Stmt = &Stmts.back();
+
+ for (Instruction *Inst : Instructions) {
+ assert(!InstStmtMap.count(Inst) &&
+ "Unexpected statement corresponding to the instruction.");
+ InstStmtMap[Inst] = Stmt;
+ }
+
for (BasicBlock *BB : R->blocks()) {
StmtMap[BB].push_back(Stmt);
+ if (BB == R->getEntry())
+ continue;
for (Instruction &Inst : *BB) {
assert(!InstStmtMap.count(&Inst) &&
"Unexpected statement corresponding to the instruction.");