diff --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h index a08ccc0fc38c..ac8157d57533 100755 --- a/polly/include/polly/ScopInfo.h +++ b/polly/include/polly/ScopInfo.h @@ -295,7 +295,7 @@ public: /// @brief Get the scattering function of this ScopStmt. /// /// @return The scattering function of this ScopStmt. - isl_map *getScattering() const { return Scattering; } + isl_map *getScattering() const; void setScattering(isl_map *scattering); /// @brief Get an isl string representing this scattering. diff --git a/polly/lib/Analysis/Dependences.cpp b/polly/lib/Analysis/Dependences.cpp index 14f5f6c217fb..4f7e31579f34 100644 --- a/polly/lib/Analysis/Dependences.cpp +++ b/polly/lib/Analysis/Dependences.cpp @@ -106,8 +106,7 @@ bool Dependences::runOnScop(Scop &S) { else must_source = isl_union_map_add_map(must_source, accdom); } - isl_map *scattering = isl_map_copy(Stmt->getScattering()); - schedule = isl_union_map_add_map(schedule, scattering); + schedule = isl_union_map_add_map(schedule, Stmt->getScattering()); } DEBUG( @@ -163,7 +162,7 @@ bool Dependences::isValidScattering(StatementToIslMapTy *NewScattering) { isl_map *scattering; if (NewScattering->find(*SI) == NewScattering->end()) - scattering = isl_map_copy(Stmt->getScattering()); + scattering = Stmt->getScattering(); else scattering = isl_map_copy((*NewScattering)[Stmt]); @@ -242,11 +241,11 @@ isl_union_map* getCombinedScheduleForSpace(Scop *scop, unsigned dimLevel) { for (Scop::iterator SI = scop->begin(), SE = scop->end(); SI != SE; ++SI) { ScopStmt *Stmt = *SI; - isl_map *scattering = isl_map_copy(Stmt->getScattering()); - unsigned remainingDimensions = isl_map_n_out(scattering) - dimLevel; - scattering = isl_map_project_out(scattering, isl_dim_out, dimLevel, - remainingDimensions); - schedule = isl_union_map_add_map(schedule, scattering); + unsigned remainingDimensions = Stmt->getNumScattering() - dimLevel; + isl_map *Scattering = isl_map_project_out(Stmt->getScattering(), + isl_dim_out, dimLevel, + remainingDimensions); + schedule = isl_union_map_add_map(schedule, Scattering); } return schedule; diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp index 54249573d29c..9e26179abed6 100644 --- a/polly/lib/Analysis/ScopInfo.cpp +++ b/polly/lib/Analysis/ScopInfo.cpp @@ -426,7 +426,7 @@ static isl_map *getEqualAndLarger(isl_space *setDomain) { isl_set *MemoryAccess::getStride(const isl_set *domainSubset) const { isl_map *accessRelation = isl_map_copy(getAccessFunction()); isl_set *scatteringDomain = isl_set_copy(const_cast(domainSubset)); - isl_map *scattering = isl_map_copy(getStatement()->getScattering()); + isl_map *scattering = getStatement()->getScattering(); scattering = isl_map_reverse(scattering); int difference = isl_map_n_in(scattering) - isl_set_n_dim(scatteringDomain); @@ -512,9 +512,14 @@ void MemoryAccess::setNewAccessFunction(isl_map *newAccess) { } //===----------------------------------------------------------------------===// -void ScopStmt::setScattering(isl_map *scattering) { + +isl_map *ScopStmt::getScattering() const { + return isl_map_copy(Scattering); +} + +void ScopStmt::setScattering(isl_map *NewScattering) { isl_map_free(Scattering); - Scattering = scattering; + Scattering = NewScattering; } void ScopStmt::buildScattering(SmallVectorImpl &Scatter) { @@ -784,7 +789,7 @@ std::string ScopStmt::getDomainStr() const { } std::string ScopStmt::getScatteringStr() const { - return stringFromIslObj(getScattering()); + return stringFromIslObj(Scattering); } unsigned ScopStmt::getNumParams() const { diff --git a/polly/lib/Cloog.cpp b/polly/lib/Cloog.cpp index 423e85399108..c985e98ed701 100644 --- a/polly/lib/Cloog.cpp +++ b/polly/lib/Cloog.cpp @@ -159,10 +159,11 @@ CloogUnionDomain *Cloog::buildCloogUnionDomain() { if (Stmt->isFinalRead()) continue; - CloogScattering *Scattering= - cloog_scattering_from_isl_map(isl_map_copy(Stmt->getScattering())); - CloogDomain *Domain = - cloog_domain_from_isl_set(Stmt->getDomain()); + CloogScattering *Scattering; + CloogDomain *Domain; + + Scattering = cloog_scattering_from_isl_map(Stmt->getScattering()); + Domain = cloog_domain_from_isl_set(Stmt->getDomain()); std::string entryName = Stmt->getBaseName(); diff --git a/polly/lib/Exchange/OpenScopExporter.cpp b/polly/lib/Exchange/OpenScopExporter.cpp index 177dd9d1d06d..aa5c5e230258 100755 --- a/polly/lib/Exchange/OpenScopExporter.cpp +++ b/polly/lib/Exchange/OpenScopExporter.cpp @@ -146,8 +146,11 @@ openscop_statement_p OpenScop::initializeStatement(ScopStmt *stmt) { // Domain & Schedule isl_set *domain = stmt->getDomain(); Stmt->domain = domainToMatrix(domain); - Stmt->schedule = scatteringToMatrix(stmt->getScattering()); + isl_map *Scattering = stmt->getScattering(); + Stmt->schedule = scatteringToMatrix(Scattering); isl_set_free(domain); + isl_map_free(Scattering); + // Statement name const char* entryName = stmt->getBaseName(); diff --git a/polly/lib/Exchange/ScopLib.cpp b/polly/lib/Exchange/ScopLib.cpp index fb111bd25db4..05294e25bb0e 100644 --- a/polly/lib/Exchange/ScopLib.cpp +++ b/polly/lib/Exchange/ScopLib.cpp @@ -93,7 +93,9 @@ scoplib_statement_p ScopLib::initializeStatement(ScopStmt *stmt) { Stmt->domain = scoplib_matrix_list_malloc(); Stmt->domain->elt = domainToMatrix(domain); Stmt->domain->next = NULL; - Stmt->schedule = scatteringToMatrix(stmt->getScattering()); + isl_map *Scattering = stmt->getScattering; + Stmt->schedule = scatteringToMatrix(Scattering); + isl_map_free(Scattering); isl_set_free(domain); // Statement name diff --git a/polly/lib/Pocc.cpp b/polly/lib/Pocc.cpp index fbf78a6bfb84..34ac0f9244bf 100644 --- a/polly/lib/Pocc.cpp +++ b/polly/lib/Pocc.cpp @@ -179,7 +179,7 @@ bool Pocc::runOnScop(Scop &S) { if ((*SI)->isFinalRead()) continue; - isl_map *scat = isl_map_copy((*SI)->getScattering()); + isl_map *scat = (*SI)->getScattering(); isl_map *projected = isl_map_project_out(scat, isl_dim_out, lastLoop, scatterDims - lastLoop); @@ -199,11 +199,9 @@ bool Pocc::runOnScop(Scop &S) { for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) { if ((*SI)->isFinalRead()) continue; - isl_map *scat = (*SI)->getScattering(); - - int scatDims = isl_map_n_out(scat); - isl_space *Space= isl_space_alloc(S.getCtx(), S.getNumParams(), scatDims, - scatDims + 1); + int scatDims = (*SI)->getNumScattering(); + isl_space *Space = isl_space_alloc(S.getCtx(), S.getNumParams(), scatDims, + scatDims + 1); isl_basic_map *map = isl_basic_map_universe(isl_space_copy(Space)); for (int i = 0; i <= lastLoop - 1; i++) { diff --git a/polly/lib/ScheduleOptimizer.cpp b/polly/lib/ScheduleOptimizer.cpp index a2aeb963f1bc..0a01ee0adf8b 100644 --- a/polly/lib/ScheduleOptimizer.cpp +++ b/polly/lib/ScheduleOptimizer.cpp @@ -67,38 +67,41 @@ static int getSingleMap(__isl_take isl_map *map, void *user) { return 0; } -static void extendScattering(Scop &S, unsigned scatDimensions) { +static void extendScattering(Scop &S, unsigned NewDimensions) { for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) { - ScopStmt *stmt = *SI; + ScopStmt *Stmt = *SI; - if (stmt->isFinalRead()) + if (Stmt->isFinalRead()) continue; - isl_map *scattering = stmt->getScattering(); - isl_space *Space = isl_space_alloc(isl_map_get_ctx(scattering), 0, - isl_map_n_out(scattering), scatDimensions); - isl_basic_map *changeScattering = isl_basic_map_universe( - isl_space_copy(Space)); + unsigned OldDimensions = Stmt->getNumScattering(); + isl_space *Space; + isl_basic_map *ChangeScattering; + + Space = isl_space_alloc(Stmt->getIslCtx(), 0, OldDimensions, NewDimensions); + ChangeScattering = isl_basic_map_universe(isl_space_copy(Space)); isl_local_space *LocalSpace = isl_local_space_from_space(Space); - for (unsigned i = 0; i < isl_map_n_out(scattering); i++) { + for (unsigned i = 0; i < OldDimensions; i++) { isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LocalSpace)); isl_constraint_set_coefficient_si(c, isl_dim_in, i, 1); isl_constraint_set_coefficient_si(c, isl_dim_out, i, -1); - changeScattering = isl_basic_map_add_constraint(changeScattering, c); + ChangeScattering = isl_basic_map_add_constraint(ChangeScattering, c); } - for (unsigned i = isl_map_n_out(scattering); i < scatDimensions; i++) { + for (unsigned i = OldDimensions; i < NewDimensions; i++) { isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LocalSpace)); isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1); - changeScattering = isl_basic_map_add_constraint(changeScattering, c); + ChangeScattering = isl_basic_map_add_constraint(ChangeScattering, c); } - isl_map *changeScatteringMap = isl_map_from_basic_map(changeScattering); + isl_map *ChangeScatteringMap = isl_map_from_basic_map(ChangeScattering); - isl_space *SpaceModel = isl_map_get_space(scattering); - changeScatteringMap = isl_map_align_params(changeScatteringMap, SpaceModel); - stmt->setScattering(isl_map_apply_range(scattering, changeScatteringMap)); + ChangeScatteringMap = isl_map_align_params(ChangeScatteringMap, + S.getParamSpace()); + isl_map *NewScattering = isl_map_apply_range(Stmt->getScattering(), + ChangeScatteringMap); + Stmt->setScattering(NewScattering); isl_local_space_free(LocalSpace); } } @@ -391,7 +394,7 @@ bool ScheduleOptimizer::runOnScop(Scop &S) { isl_union_set_from_set(domain)); isl_map *stmtSchedule; isl_union_map_foreach_map(stmtBand, getSingleMap, &stmtSchedule); - stmt->setScattering(isl_map_copy(stmtSchedule)); + stmt->setScattering(stmtSchedule); isl_union_map_free(stmtBand); } @@ -401,7 +404,7 @@ bool ScheduleOptimizer::runOnScop(Scop &S) { unsigned maxScatDims = 0; for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) - maxScatDims = std::max(isl_map_n_out((*SI)->getScattering()), maxScatDims); + maxScatDims = std::max((*SI)->getNumScattering(), maxScatDims); extendScattering(S, maxScatDims); return false;