ScopInfo: Remove not-in-DomainMap statements in separate function

This separates ScopBuilder internal and ScopBuilder external functionality.

llvm-svn: 308152
This commit is contained in:
Tobias Grosser 2017-07-16 23:55:38 +00:00
parent 5c8a50bddd
commit 21cbcf03d3
3 changed files with 46 additions and 19 deletions

View File

@ -2148,6 +2148,19 @@ private:
/// all memory accesses have been modeled and canonicalized.
void assumeNoOutOfBounds();
/// Remove statements from the list of scop statements.
///
/// @param ShouldDelete A function that returns true if the statement passed
/// to it should be deleted.
void removeStmts(std::function<bool(ScopStmt &)> ShouldDelete);
/// Removes @p Stmt from the StmtMap.
void removeFromStmtMap(ScopStmt &Stmt);
/// Removes all statements where the entry block of the statement does not
/// have a corresponding domain in the domain map.
void removeStmtNotInDomainMap();
/// Mark arrays that have memory accesses with FortranArrayDescriptor.
void markFortranArrays();

View File

@ -982,6 +982,7 @@ void ScopBuilder::buildScop(Region &R, AssumptionCache &AC) {
// Remove empty statements.
// Exit early in case there are no executable statements left in this scop.
scop->removeStmtNotInDomainMap();
scop->simplifySCoP(false);
if (scop->isEmpty())
return;

View File

@ -3728,13 +3728,37 @@ void Scop::assumeNoOutOfBounds() {
Access->assumeNoOutOfBound();
}
void Scop::simplifySCoP(bool AfterHoisting) {
for (auto StmtIt = Stmts.begin(), StmtEnd = Stmts.end(); StmtIt != StmtEnd;) {
ScopStmt &Stmt = *StmtIt;
void Scop::removeFromStmtMap(ScopStmt &Stmt) {
if (Stmt.isRegionStmt())
for (BasicBlock *BB : Stmt.getRegion()->blocks())
StmtMap.erase(BB);
else
StmtMap.erase(Stmt.getBasicBlock());
}
void Scop::removeStmts(std::function<bool(ScopStmt &)> ShouldDelete) {
for (auto StmtIt = Stmts.begin(), StmtEnd = Stmts.end(); StmtIt != StmtEnd;) {
if (!ShouldDelete(*StmtIt)) {
StmtIt++;
continue;
}
removeFromStmtMap(*StmtIt);
StmtIt = Stmts.erase(StmtIt);
}
}
void Scop::removeStmtNotInDomainMap() {
auto ShouldDelete = [this](ScopStmt &Stmt) -> bool {
return !this->DomainMap[Stmt.getEntryBlock()];
};
removeStmts(ShouldDelete);
}
void Scop::simplifySCoP(bool AfterHoisting) {
auto ShouldDelete = [AfterHoisting](ScopStmt &Stmt) -> bool {
bool RemoveStmt = Stmt.isEmpty();
if (!RemoveStmt)
RemoveStmt = !DomainMap[Stmt.getEntryBlock()];
// Remove read only statements only after invariant load hoisting.
if (!RemoveStmt && AfterHoisting) {
@ -3749,21 +3773,10 @@ void Scop::simplifySCoP(bool AfterHoisting) {
RemoveStmt = OnlyRead;
}
return RemoveStmt;
};
if (!RemoveStmt) {
StmtIt++;
continue;
}
// Remove the statement because it is unnecessary.
if (Stmt.isRegionStmt())
for (BasicBlock *BB : Stmt.getRegion()->blocks())
StmtMap.erase(BB);
else
StmtMap.erase(Stmt.getBasicBlock());
StmtIt = Stmts.erase(StmtIt);
}
removeStmts(ShouldDelete);
}
InvariantEquivClassTy *Scop::lookupInvariantEquivClass(Value *Val) {