diff options
| author | Tobias Grosser <grosser@fim.uni-passau.de> | 2011-08-20 11:11:25 +0000 |
|---|---|---|
| committer | Tobias Grosser <grosser@fim.uni-passau.de> | 2011-08-20 11:11:25 +0000 |
| commit | b76f385334405e6517ee60b5dfdf569ff4e94f1f (patch) | |
| tree | f1bd4056fc00da863dd7ebdbb9967686883329ca | |
| parent | 15f5efff8f44ccbb3c1f184bbd858c2b7ff5be4f (diff) | |
| download | bcm5719-llvm-b76f385334405e6517ee60b5dfdf569ff4e94f1f.tar.gz bcm5719-llvm-b76f385334405e6517ee60b5dfdf569ff4e94f1f.zip | |
Free isl_ctx and fix several memory leaks
Because of me not understanding the LLVM pass structure well, I did not find a
good way to allocate isl_ctx and to free it later without getting issues with
reference counting. I now found this place, such that we can free isl_ctx. This
patch also fixes the memory leaks that were ignored beforehand.
llvm-svn: 138204
| -rw-r--r-- | polly/include/polly/Cloog.h | 1 | ||||
| -rwxr-xr-x | polly/include/polly/ScopInfo.h | 9 | ||||
| -rw-r--r-- | polly/lib/Analysis/Dependences.cpp | 32 | ||||
| -rw-r--r-- | polly/lib/Analysis/ScopInfo.cpp | 47 | ||||
| -rw-r--r-- | polly/lib/Cloog.cpp | 17 | ||||
| -rw-r--r-- | polly/lib/CodeGeneration.cpp | 3 | ||||
| -rwxr-xr-x | polly/lib/Exchange/JSONExporter.cpp | 6 | ||||
| -rw-r--r-- | polly/lib/Support/GICHelper.cpp | 1 |
8 files changed, 83 insertions, 33 deletions
diff --git a/polly/include/polly/Cloog.h b/polly/include/polly/Cloog.h index b84bd56fe47..e964261bec2 100644 --- a/polly/include/polly/Cloog.h +++ b/polly/include/polly/Cloog.h @@ -58,6 +58,7 @@ namespace polly { bool runOnScop(Scop &S); void printScop(llvm::raw_ostream &OS) const; virtual void getAnalysisUsage(AnalysisUsage &AU) const; + virtual void releaseMemory(); }; } #endif /* POLLY_CLOOG_H */ diff --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h index 1e4d79eefc7..b88ddbfcb74 100755 --- a/polly/include/polly/ScopInfo.h +++ b/polly/include/polly/ScopInfo.h @@ -296,7 +296,7 @@ public: /// /// @return The scattering function of this ScopStmt. isl_map *getScattering() const { return Scattering; } - void setScattering(isl_map *scattering) { Scattering = scattering; } + void setScattering(isl_map *scattering); /// @brief Get an isl string representing this scattering. std::string getScatteringStr() const; @@ -408,7 +408,7 @@ class Scop { /// Create the static control part with a region, max loop depth of this /// region and parameters used in this region. - Scop(TempScop &TempScop, LoopInfo &LI, ScalarEvolution &SE); + Scop(TempScop &TempScop, LoopInfo &LI, ScalarEvolution &SE, isl_ctx *ctx); /// @brief Check if a basic block is trivial. /// @@ -552,6 +552,7 @@ class ScopInfo : public RegionPass { // The Scop Scop *scop; + isl_ctx *ctx; void clear() { if (scop) { @@ -562,8 +563,8 @@ class ScopInfo : public RegionPass { public: static char ID; - explicit ScopInfo() : RegionPass(ID), scop(0) {} - ~ScopInfo() { clear(); } + explicit ScopInfo(); + ~ScopInfo(); /// @brief Try to build the Polly IR of static control part on the current /// SESE-Region. diff --git a/polly/lib/Analysis/Dependences.cpp b/polly/lib/Analysis/Dependences.cpp index 6e465e528cd..c9c2351fc97 100644 --- a/polly/lib/Analysis/Dependences.cpp +++ b/polly/lib/Analysis/Dependences.cpp @@ -213,25 +213,32 @@ bool Dependences::isValidScattering(StatementToIslMapTy *NewScattering) { temp_must_no_source = isl_union_map_coalesce(temp_must_no_source); temp_may_no_source = isl_union_map_coalesce(temp_may_no_source); + bool isValid = true; + if (!isl_union_map_is_equal(temp_must_dep, must_dep)) { DEBUG(dbgs().indent(4) << "\nEqual 1 calculated\n"); - return false; + isValid = false; } DEBUG(dbgs().indent(4) << "\nEqual 1 calculated\n"); if (!isl_union_map_is_equal(temp_may_dep, may_dep)) - return false; + isValid = false; DEBUG(dbgs().indent(4) << "\nEqual 2 calculated\n"); if (!isl_union_map_is_equal(temp_must_no_source, must_no_source)) - return false; + isValid = false; if (!isl_union_map_is_equal(temp_may_no_source, may_no_source)) - return false; + isValid = false; + + isl_union_map_free(temp_must_dep); + isl_union_map_free(temp_may_dep); + isl_union_map_free(temp_must_no_source); + isl_union_map_free(temp_may_no_source); - return true; + return isValid; } isl_union_map* getCombinedScheduleForDim(Scop *scop, unsigned dimLevel) { @@ -278,8 +285,7 @@ bool Dependences::isParallelDimension(isl_set *loopDomain, scheduleDeps_waw = isl_union_map_apply_range(isl_union_map_copy(waw_dep), isl_union_map_copy(schedule)); - scheduleDeps_waw = isl_union_map_apply_domain(scheduleDeps_waw, - isl_union_map_copy(schedule)); + scheduleDeps_waw = isl_union_map_apply_domain(scheduleDeps_waw, schedule); // Dependences need to originate and to terminate in the scheduling space // enumerated by this loop. @@ -300,7 +306,7 @@ bool Dependences::isParallelDimension(isl_set *loopDomain, restrictedDeps_waw = isl_union_map_intersect_domain(scheduleDeps_waw, isl_union_set_copy(scheduleSubset)); restrictedDeps_waw = isl_union_map_intersect_range(restrictedDeps_waw, - isl_union_set_copy(scheduleSubset)); + scheduleSubset); isl_union_set *distance_waw = isl_union_map_deltas(restrictedDeps_waw); @@ -353,10 +359,16 @@ bool Dependences::isParallelDimension(isl_set *loopDomain, isl_union_set *nonValid_waw = isl_union_set_subtract(distance_waw, validDistancesUS); - - return isl_union_set_is_empty(nonValid) + bool is_parallel = isl_union_set_is_empty(nonValid) && isl_union_set_is_empty(nonValid_war) && isl_union_set_is_empty(nonValid_waw); + + isl_dim_free(dim); + isl_union_set_free(nonValid); + isl_union_set_free(nonValid_war); + isl_union_set_free(nonValid_waw); + + return is_parallel; } bool Dependences::isParallelFor(const clast_for *f) { diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp index 91a8ea281a7..78d5789e63b 100644 --- a/polly/lib/Analysis/ScopInfo.cpp +++ b/polly/lib/Analysis/ScopInfo.cpp @@ -466,7 +466,12 @@ bool MemoryAccess::isStrideZero(const isl_set *domainSubset) const { bset = isl_basic_set_add_constraint(bset, c); isl_set *strideZero = isl_set_from_basic_set(bset); - return isl_set_is_equal(stride, strideZero); + bool isStrideZero = isl_set_is_equal(stride, strideZero); + + isl_set_free(strideZero); + isl_set_free(stride); + + return isStrideZero; } bool MemoryAccess::isStrideOne(const isl_set *domainSubset) const { @@ -484,16 +489,27 @@ bool MemoryAccess::isStrideOne(const isl_set *domainSubset) const { isl_basic_set *bset = isl_basic_set_universe(isl_set_get_dim(stride)); bset = isl_basic_set_add_constraint(bset, c); - isl_set *strideZero = isl_set_from_basic_set(bset); + isl_set *strideOne = isl_set_from_basic_set(bset); + + bool isStrideOne = isl_set_is_equal(stride, strideOne); + + isl_set_free(strideOne); + isl_set_free(stride); - return isl_set_is_equal(stride, strideZero); + return isStrideOne; } void MemoryAccess::setNewAccessFunction(isl_map *newAccess) { + isl_map_free(newAccessRelation); newAccessRelation = newAccess; } //===----------------------------------------------------------------------===// +void ScopStmt::setScattering(isl_map *scattering) { + isl_map_free(Scattering); + Scattering = scattering; +} + void ScopStmt::buildScattering(SmallVectorImpl<unsigned> &Scatter) { unsigned NumberOfIterators = getNumIterators(); unsigned ScatDim = Parent.getMaxLoopDepth() * 2 + 1; @@ -607,12 +623,12 @@ isl_set *ScopStmt::toUpperLoopBound(const SCEVAffFunc &UpperBound, isl_dim *Dim, isl_pw_aff *Bound = SCEVAffinator::getPwAff(this, UpperBound.OriginalSCEV, 0); isl_set *set = isl_pw_aff_le_set(BoundedDim, Bound); set = isl_set_set_tuple_name(set, isl_dim_get_tuple_name(Dim, isl_dim_set)); + isl_dim_free(Dim); return set; } void ScopStmt::buildIterationDomainFromLoops(TempScop &tempScop) { - isl_dim *dim = isl_dim_set_alloc(Parent.getCtx(), 0, - getNumIterators()); + isl_dim *dim = isl_dim_set_alloc(getIslContext(), 0, getNumIterators()); dim = isl_dim_set_tuple_name(dim, isl_dim_set, getBaseName()); Domain = isl_set_universe(isl_dim_copy(dim)); @@ -637,6 +653,7 @@ void ScopStmt::buildIterationDomainFromLoops(TempScop &tempScop) { Domain = isl_set_intersect(Domain, UpperBoundSet); } + isl_dim_free(dim); isl_int_clear(v); } @@ -843,11 +860,10 @@ void ScopStmt::dump() const { print(dbgs()); } //===----------------------------------------------------------------------===// /// Scop class implement -Scop::Scop(TempScop &tempScop, LoopInfo &LI, ScalarEvolution &ScalarEvolution) +Scop::Scop(TempScop &tempScop, LoopInfo &LI, ScalarEvolution &ScalarEvolution, + isl_ctx *ctx) : SE(&ScalarEvolution), R(tempScop.getMaxRegion()), MaxLoopDepth(tempScop.getMaxLoopDepth()) { - isl_ctx *ctx = isl_ctx_alloc(); - ParamSetType &Params = tempScop.getParamSet(); Parameters.insert(Parameters.begin(), Params.begin(), Params.end()); @@ -887,9 +903,6 @@ Scop::~Scop() { // Free the statements; for (iterator I = begin(), E = end(); I != E; ++I) delete *I; - - // Do we need a singleton to manage this? - //isl_ctx_free(ctx); } std::string Scop::getContextStr() const { @@ -993,6 +1006,16 @@ void Scop::buildScop(TempScop &tempScop, } //===----------------------------------------------------------------------===// +ScopInfo::ScopInfo() : RegionPass(ID), scop(0) { + ctx = isl_ctx_alloc(); +} + +ScopInfo::~ScopInfo() { + clear(); + isl_ctx_free(ctx); +} + + void ScopInfo::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<LoopInfo>(); @@ -1018,7 +1041,7 @@ bool ScopInfo::runOnRegion(Region *R, RGPassManager &RGM) { ++ScopFound; if (tempScop->getMaxLoopDepth() > 0) ++RichScopFound; - scop = new Scop(*tempScop, LI, SE); + scop = new Scop(*tempScop, LI, SE, ctx); return false; } diff --git a/polly/lib/Cloog.cpp b/polly/lib/Cloog.cpp index aa1ac9f5c58..cf403fc39b8 100644 --- a/polly/lib/Cloog.cpp +++ b/polly/lib/Cloog.cpp @@ -30,6 +30,7 @@ #include "llvm/Module.h" #include "cloog/isl/domain.h" +#include "cloog/isl/cloog.h" using namespace llvm; using namespace polly; @@ -61,14 +62,14 @@ public: }; Cloog::Cloog(Scop *Scop) : S(Scop) { - State = cloog_state_malloc(); + State = cloog_isl_state_malloc(Scop->getCtx()); buildCloogOptions(); ClastRoot = cloog_clast_create_from_input(buildCloogInput(), Options); } Cloog::~Cloog() { - cloog_options_free(Options); cloog_clast_free(ClastRoot); + cloog_options_free(Options); cloog_state_free(State); } @@ -164,10 +165,9 @@ CloogUnionDomain *Cloog::buildCloogUnionDomain() { cloog_domain_from_isl_set(Stmt->getDomain()); std::string entryName = Stmt->getBaseName(); - char *Name = (char*)malloc(sizeof(char) * (entryName.size() + 1)); - strcpy(Name, entryName.c_str()); - DU = cloog_union_domain_add_domain(DU, Name, Domain, Scattering, Stmt); + DU = cloog_union_domain_add_domain(DU, entryName.c_str(), Domain, + Scattering, Stmt); } return DU; @@ -265,6 +265,13 @@ const struct clast_root *CloogInfo::getClast() { return C->getClast(); } +void CloogInfo::releaseMemory() { + if (C) { + delete C; + C = 0; + } +} + bool CloogInfo::runOnScop(Scop &S) { if (C) delete C; diff --git a/polly/lib/CodeGeneration.cpp b/polly/lib/CodeGeneration.cpp index aa2dc11e7e6..cfede95a6af 100644 --- a/polly/lib/CodeGeneration.cpp +++ b/polly/lib/CodeGeneration.cpp @@ -1134,7 +1134,7 @@ public: map = isl_map_intersect(map, identity); isl_map *lexmax = isl_map_lexmax(isl_map_copy(map)); - isl_map *lexmin = isl_map_lexmin(isl_map_copy(map)); + isl_map *lexmin = isl_map_lexmin(map); isl_map *sub = isl_map_sum(lexmax, isl_map_neg(lexmin)); isl_set *elements = isl_map_range(sub); @@ -1149,6 +1149,7 @@ public: isl_point_get_coordinate(p, isl_dim_set, isl_set_n_dim(loopDomain) - 1, &v); int numberIterations = isl_int_get_si(v); isl_int_clear(v); + isl_point_free(p); return (numberIterations) / isl_int_get_si(f->stride) + 1; } diff --git a/polly/lib/Exchange/JSONExporter.cpp b/polly/lib/Exchange/JSONExporter.cpp index 72ecd3e4336..2653868ec1f 100755 --- a/polly/lib/Exchange/JSONExporter.cpp +++ b/polly/lib/Exchange/JSONExporter.cpp @@ -272,17 +272,21 @@ bool JSONImporter::runOnScop(Scop &scop) { if (!isl_map_has_equal_dim(currentAccessMap, newAccessMap)) { errs() << "JScop file contains access function with incompatible " << "dimensions\n"; + isl_map_free(newAccessMap); return false; } if (isl_map_dim(newAccessMap, isl_dim_out) != 1) { errs() << "New access map in JScop file should be single dimensional\n"; + isl_map_free(newAccessMap); return false; } if (!isl_map_is_equal(newAccessMap, currentAccessMap)) { // Statistics. ++NewAccessMapFound; - newAccessStrings.push_back(accesses.asCString()); + newAccessStrings.push_back(accesses.asCString()); (*MI)->setNewAccessFunction(newAccessMap); + } else { + isl_map_free(newAccessMap); } memoryAccessIdx++; } diff --git a/polly/lib/Support/GICHelper.cpp b/polly/lib/Support/GICHelper.cpp index 3d8b5f6a24d..46184f33f4b 100644 --- a/polly/lib/Support/GICHelper.cpp +++ b/polly/lib/Support/GICHelper.cpp @@ -48,6 +48,7 @@ APInt polly::APInt_from_MPZ (const mpz_t mpz) { if (p) { APInt A((unsigned)mpz_sizeinbase(mpz, 2), (unsigned)sz , p); A = A.zext(A.getBitWidth() + 1); + free(p); if (mpz_sgn(mpz) == -1) return -A; |

