[PATCH] D35663: [Polly] Remove dependency of `Scop::getStmtFor(Inst)` on `getStmtFor(BB)`. [NFC].
Nandini Singhal via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 20 00:57:09 PDT 2017
nandini12396 created this revision.
nandini12396 added a project: Polly.
Herald added a reviewer: bollu.
We are working towards removing uses of `Scop::getStmtFor(BB)`. In this patch, we remove dependency of `Scop::getStmtFor(Inst)` on `getStmtFor(BB)`. To do so, we introduce a map of instructions to their corresponding scop statements and use it to get the instructions' statement.
https://reviews.llvm.org/D35663
Files:
include/polly/ScopInfo.h
lib/Analysis/ScopInfo.cpp
Index: lib/Analysis/ScopInfo.cpp
===================================================================
--- lib/Analysis/ScopInfo.cpp
+++ lib/Analysis/ScopInfo.cpp
@@ -3726,10 +3726,16 @@
void Scop::removeFromStmtMap(ScopStmt &Stmt) {
if (Stmt.isRegionStmt())
- for (BasicBlock *BB : Stmt.getRegion()->blocks())
+ for (BasicBlock *BB : Stmt.getRegion()->blocks()) {
StmtMap.erase(BB);
- else
+ for (Instruction &Inst : *BB)
+ InstStmtMap.erase(&Inst);
+ }
+ else {
StmtMap.erase(Stmt.getBasicBlock());
+ for (Instruction &Inst : *Stmt.getBasicBlock())
+ InstStmtMap.erase(&Inst);
+ }
}
void Scop::removeStmts(std::function<bool(ScopStmt &)> ShouldDelete) {
@@ -4749,14 +4755,19 @@
Stmts.emplace_back(*this, *BB, SurroundingLoop, Instructions);
auto *Stmt = &Stmts.back();
StmtMap[BB].push_back(Stmt);
+ for (Instruction &Inst : *BB)
+ InstStmtMap[&Inst] = Stmt;
}
void Scop::addScopStmt(Region *R, Loop *SurroundingLoop) {
assert(R && "Unexpected nullptr!");
Stmts.emplace_back(*this, *R, SurroundingLoop);
auto *Stmt = &Stmts.back();
- for (BasicBlock *BB : R->blocks())
+ for (BasicBlock *BB : R->blocks()) {
StmtMap[BB].push_back(Stmt);
+ for (Instruction &Inst : *BB)
+ InstStmtMap[&Inst] = Stmt;
+ }
}
ScopStmt *Scop::addScopStmt(__isl_take isl_map *SourceRel,
@@ -4912,6 +4923,13 @@
return StmtMapIt->second.front();
}
+ScopStmt *Scop::getStmtFor(Instruction *Inst) const {
+ auto InstStmtMapIt = InstStmtMap.find(Inst);
+ if (InstStmtMapIt == InstStmtMap.end())
+ return nullptr;
+ return InstStmtMapIt->second;
+}
+
ScopStmt *Scop::getStmtFor(RegionNode *RN) const {
if (RN->isSubRegion())
return getStmtFor(RN->getNodeAs<Region>());
Index: include/polly/ScopInfo.h
===================================================================
--- include/polly/ScopInfo.h
+++ include/polly/ScopInfo.h
@@ -1689,6 +1689,9 @@
/// vector comprises only of a single statement.
DenseMap<BasicBlock *, std::vector<ScopStmt *>> StmtMap;
+ /// A map from instructions to SCoP statements.
+ DenseMap<Instruction *, ScopStmt *> InstStmtMap;
+
/// A map from basic blocks to their domains.
DenseMap<BasicBlock *, isl::set> DomainMap;
@@ -2629,9 +2632,7 @@
/// Return the ScopStmt an instruction belongs to, or nullptr if it
/// does not belong to any statement in this Scop.
- ScopStmt *getStmtFor(Instruction *Inst) const {
- return getStmtFor(Inst->getParent());
- }
+ ScopStmt *getStmtFor(Instruction *Inst) const;
/// Return the number of statements in the SCoP.
size_t getSize() const { return Stmts.size(); }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35663.107456.patch
Type: text/x-patch
Size: 2667 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170720/79602d2a/attachment.bin>
More information about the llvm-commits
mailing list