Use unique_ptr to clarify ownership of ScopStmt

llvm-svn: 238090
This commit is contained in:
Tobias Grosser 2015-05-23 05:14:09 +00:00
parent 5df78fa35b
commit 679dfafd33
7 changed files with 38 additions and 47 deletions

View File

@ -766,7 +766,7 @@ private:
/// Max loop depth.
unsigned MaxLoopDepth;
typedef std::vector<ScopStmt *> StmtSet;
typedef std::vector<std::unique_ptr<ScopStmt>> StmtSet;
/// The statements in this Scop.
StmtSet Stmts;

View File

@ -79,12 +79,12 @@ static void collectInfo(Scop &S, isl_union_map **Read, isl_union_map **Write,
*StmtSchedule = isl_union_map_empty(Space);
SmallPtrSet<const Value *, 8> ReductionBaseValues;
for (ScopStmt *Stmt : S)
for (auto &Stmt : S)
for (MemoryAccess *MA : *Stmt)
if (MA->isReductionLike())
ReductionBaseValues.insert(MA->getBaseAddr());
for (ScopStmt *Stmt : S) {
for (auto &Stmt : S) {
for (MemoryAccess *MA : *Stmt) {
isl_set *domcp = Stmt->getDomain();
isl_map *accdom = MA->getAccessRelation();
@ -361,7 +361,7 @@ void Dependences::calculateDependences(Scop &S) {
// Step 1)
RED = isl_union_map_empty(isl_union_map_get_space(RAW));
for (ScopStmt *Stmt : S) {
for (auto &Stmt : S) {
for (MemoryAccess *MA : *Stmt) {
if (!MA->isReductionLike())
continue;
@ -404,7 +404,7 @@ void Dependences::calculateDependences(Scop &S) {
// We then move this portion of reduction dependences back to the statement ->
// statement space and add a mapping from the memory access to these
// dependences.
for (ScopStmt *Stmt : S) {
for (auto &Stmt : S) {
for (MemoryAccess *MA : *Stmt) {
if (!MA->isReductionLike())
continue;
@ -476,13 +476,13 @@ bool Dependences::isValidSchedule(Scop &S,
isl_space *ScheduleSpace = nullptr;
for (ScopStmt *Stmt : S) {
for (auto &Stmt : S) {
isl_map *StmtScat;
if (NewSchedule->find(Stmt) == NewSchedule->end())
if (NewSchedule->find(&*Stmt) == NewSchedule->end())
StmtScat = Stmt->getSchedule();
else
StmtScat = isl_map_copy((*NewSchedule)[Stmt]);
StmtScat = isl_map_copy((*NewSchedule)[&*Stmt]);
if (!ScheduleSpace)
ScheduleSpace = isl_space_range(isl_map_get_space(StmtScat));

View File

@ -1349,7 +1349,7 @@ void Scop::realignParams() {
// Align the parameters of all data structures to the model.
Context = isl_set_align_params(Context, Space);
for (ScopStmt *Stmt : *this)
for (auto &Stmt : *this)
Stmt->realignParams();
}
@ -1476,7 +1476,7 @@ bool Scop::buildAliasGroups(AliasAnalysis &AA) {
DenseMap<Value *, MemoryAccess *> PtrToAcc;
DenseSet<Value *> HasWriteAccess;
for (ScopStmt *Stmt : *this) {
for (auto &Stmt : *this) {
// Skip statements with an empty domain as they will never be executed.
isl_set *StmtDomain = Stmt->getDomain();
@ -1666,7 +1666,7 @@ void Scop::dropConstantScheduleDims() {
isl_val_free(FixedVal);
}
for (auto *S : *this) {
for (auto &S : *this) {
isl_map *Schedule = S->getSchedule();
Schedule = isl_map_apply_range(Schedule, isl_map_copy(DropDimMap));
S->setSchedule(Schedule);
@ -1704,10 +1704,6 @@ Scop::~Scop() {
isl_set_free(Context);
isl_set_free(AssumedContext);
// Free the statements;
for (ScopStmt *Stmt : *this)
delete Stmt;
// Free the ScopArrayInfo objects.
for (auto &ScopArrayInfoPair : arrays())
delete ScopArrayInfoPair.second;
@ -1817,7 +1813,7 @@ void Scop::printAliasAssumptions(raw_ostream &OS) const {
void Scop::printStatements(raw_ostream &OS) const {
OS << "Statements {\n";
for (ScopStmt *Stmt : *this)
for (auto &Stmt : *this)
OS.indent(4) << *Stmt;
OS.indent(4) << "}\n";
@ -1850,7 +1846,7 @@ isl_ctx *Scop::getIslCtx() const { return IslCtx; }
__isl_give isl_union_set *Scop::getDomains() {
isl_union_set *Domain = isl_union_set_empty(getParamSpace());
for (ScopStmt *Stmt : *this)
for (auto &Stmt : *this)
Domain = isl_union_set_add_set(Domain, Stmt->getDomain());
return Domain;
@ -1859,7 +1855,7 @@ __isl_give isl_union_set *Scop::getDomains() {
__isl_give isl_union_map *Scop::getMustWrites() {
isl_union_map *Write = isl_union_map_empty(this->getParamSpace());
for (ScopStmt *Stmt : *this) {
for (auto &Stmt : *this) {
for (MemoryAccess *MA : *Stmt) {
if (!MA->isMustWrite())
continue;
@ -1876,7 +1872,7 @@ __isl_give isl_union_map *Scop::getMustWrites() {
__isl_give isl_union_map *Scop::getMayWrites() {
isl_union_map *Write = isl_union_map_empty(this->getParamSpace());
for (ScopStmt *Stmt : *this) {
for (auto &Stmt : *this) {
for (MemoryAccess *MA : *Stmt) {
if (!MA->isMayWrite())
continue;
@ -1893,7 +1889,7 @@ __isl_give isl_union_map *Scop::getMayWrites() {
__isl_give isl_union_map *Scop::getWrites() {
isl_union_map *Write = isl_union_map_empty(this->getParamSpace());
for (ScopStmt *Stmt : *this) {
for (auto &Stmt : *this) {
for (MemoryAccess *MA : *Stmt) {
if (!MA->isWrite())
continue;
@ -1910,7 +1906,7 @@ __isl_give isl_union_map *Scop::getWrites() {
__isl_give isl_union_map *Scop::getReads() {
isl_union_map *Read = isl_union_map_empty(getParamSpace());
for (ScopStmt *Stmt : *this) {
for (auto &Stmt : *this) {
for (MemoryAccess *MA : *Stmt) {
if (!MA->isRead())
continue;
@ -1928,7 +1924,7 @@ __isl_give isl_union_map *Scop::getReads() {
__isl_give isl_union_map *Scop::getSchedule() {
isl_union_map *Schedule = isl_union_map_empty(getParamSpace());
for (ScopStmt *Stmt : *this)
for (auto &Stmt : *this)
Schedule = isl_union_map_add_map(Schedule, Stmt->getSchedule());
return isl_union_map_coalesce(Schedule);
@ -1936,7 +1932,7 @@ __isl_give isl_union_map *Scop::getSchedule() {
bool Scop::restrictDomains(__isl_take isl_union_set *Domain) {
bool Changed = false;
for (ScopStmt *Stmt : *this) {
for (auto &Stmt : *this) {
isl_union_set *StmtDomain = isl_union_set_from_set(Stmt->getDomain());
isl_union_set *NewStmtDomain = isl_union_set_intersect(
isl_union_set_copy(StmtDomain), isl_union_set_copy(Domain));
@ -1975,22 +1971,23 @@ void Scop::addScopStmt(BasicBlock *BB, Region *R, TempScop &tempScop,
const Region &CurRegion,
SmallVectorImpl<Loop *> &NestLoops,
SmallVectorImpl<unsigned> &ScheduleVec) {
ScopStmt *Stmt;
std::unique_ptr<ScopStmt> Stmt;
if (BB) {
Stmt =
new ScopStmt(*this, tempScop, CurRegion, *BB, NestLoops, ScheduleVec);
StmtMap[BB] = Stmt;
Stmt = std::unique_ptr<ScopStmt>(
new ScopStmt(*this, tempScop, CurRegion, *BB, NestLoops, ScheduleVec));
StmtMap[BB] = &*Stmt;
} else {
assert(R && "Either a basic block or a region is needed to "
"create a new SCoP stmt.");
Stmt = new ScopStmt(*this, tempScop, CurRegion, *R, NestLoops, ScheduleVec);
Stmt = std::unique_ptr<ScopStmt>(
new ScopStmt(*this, tempScop, CurRegion, *R, NestLoops, ScheduleVec));
for (BasicBlock *BB : R->blocks())
StmtMap[BB] = Stmt;
StmtMap[BB] = &*Stmt;
}
// Insert all statements into the statement map and the statement vector.
Stmts.push_back(Stmt);
Stmts.push_back(std::move(Stmt));
// Increasing the Schedule function is OK for the moment, because
// we are using a depth first iterator and the program is well structured.

View File

@ -59,7 +59,7 @@ void ScopAnnotator::buildAliasScopes(Scop &S) {
OtherAliasScopeListMap.clear();
SetVector<Value *> BasePtrs;
for (ScopStmt *Stmt : S)
for (auto &Stmt : S)
for (MemoryAccess *MA : *Stmt)
BasePtrs.insert(MA->getBaseAddr());

View File

@ -37,7 +37,7 @@ BasicBlock *polly::executeScopConditionally(Scop &S, Pass *P, Value *RTC) {
std::string OldName = OldBlock->getName();
// Update ScopInfo.
for (ScopStmt *Stmt : S)
for (auto &Stmt : S)
if (Stmt->getBasicBlock() == OldBlock) {
Stmt->setBasicBlock(NewBlock);
break;

View File

@ -102,9 +102,7 @@ Json::Value JSONExporter::getJSON(Scop &S) const {
root["location"] = Location;
root["statements"];
for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
ScopStmt *Stmt = *SI;
for (auto &Stmt : S) {
Json::Value statement;
statement["name"] = Stmt->getBaseName();
@ -234,10 +232,10 @@ bool JSONImporter::runOnScop(Scop &S) {
int index = 0;
for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
for (auto &Stmt : S) {
Json::Value schedule = jscop["statements"][index]["schedule"];
isl_map *m = isl_map_read_from_str(S.getIslCtx(), schedule.asCString());
isl_space *Space = (*SI)->getDomainSpace();
isl_space *Space = Stmt->getDomainSpace();
// Copy the old tuple id. This is necessary to retain the user pointer,
// that stores the reference to the ScopStmt this schedule belongs to.
@ -248,7 +246,7 @@ bool JSONImporter::runOnScop(Scop &S) {
m = isl_map_set_dim_id(m, isl_dim_param, i, id);
}
isl_space_free(Space);
NewSchedule[*SI] = m;
NewSchedule[&*Stmt] = m;
index++;
}
@ -262,17 +260,13 @@ bool JSONImporter::runOnScop(Scop &S) {
return false;
}
for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
ScopStmt *Stmt = *SI;
if (NewSchedule.find(Stmt) != NewSchedule.end())
Stmt->setSchedule(NewSchedule[Stmt]);
for (auto &Stmt : S) {
if (NewSchedule.find(&*Stmt) != NewSchedule.end())
Stmt->setSchedule(NewSchedule[&*Stmt]);
}
int statementIdx = 0;
for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
ScopStmt *Stmt = *SI;
for (auto &Stmt : S) {
int memoryAccessIdx = 0;
for (MemoryAccess *MA : *Stmt) {
Json::Value accesses = jscop["statements"][statementIdx]["accesses"]

View File

@ -467,7 +467,7 @@ bool IslScheduleOptimizer::runOnScop(Scop &S) {
S.markAsOptimized();
for (ScopStmt *Stmt : S) {
for (auto &Stmt : S) {
isl_map *StmtSchedule;
isl_set *Domain = Stmt->getDomain();
isl_union_map *StmtBand;