[polly] r243245 - Remove explicit heap allocation to fix and prevent memory leaks
Johannes Doerfert
doerfert at cs.uni-saarland.de
Sun Jul 26 06:14:39 PDT 2015
Author: jdoerfert
Date: Sun Jul 26 08:14:38 2015
New Revision: 243245
URL: http://llvm.org/viewvc/llvm-project?rev=243245&view=rev
Log:
Remove explicit heap allocation to fix and prevent memory leaks
Modified:
polly/trunk/include/polly/ScopInfo.h
polly/trunk/lib/Analysis/ScopInfo.cpp
polly/trunk/lib/CodeGen/IslAst.cpp
Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=243245&r1=243244&r2=243245&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Sun Jul 26 08:14:38 2015
@@ -715,7 +715,7 @@ public:
/// @brief Pair of minimal/maximal access vectors representing
/// read write and read only accesses
- using MinMaxVectorPairTy = std::pair<MinMaxVectorTy *, MinMaxVectorTy *>;
+ using MinMaxVectorPairTy = std::pair<MinMaxVectorTy, MinMaxVectorTy>;
/// @brief Vector of pair of minimal/maximal access vectors representing
/// non read only and read only accesses for each alias group.
Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=243245&r1=243244&r2=243245&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Sun Jul 26 08:14:38 2015
@@ -1469,7 +1469,7 @@ static __isl_give isl_set *getAccessDoma
static bool calculateMinMaxAccess(__isl_take isl_union_map *Accesses,
__isl_take isl_union_set *Domains,
__isl_take isl_set *AssumedContext,
- Scop::MinMaxVectorTy *MinMaxAccesses) {
+ Scop::MinMaxVectorTy &MinMaxAccesses) {
Accesses = isl_union_map_intersect_domain(Accesses, Domains);
isl_union_set *Locations = isl_union_map_range(Accesses);
@@ -1477,7 +1477,7 @@ static bool calculateMinMaxAccess(__isl_
Locations = isl_union_set_coalesce(Locations);
Locations = isl_union_set_detect_equalities(Locations);
bool Valid = (0 == isl_union_set_foreach_set(Locations, buildMinMaxAccess,
- MinMaxAccesses));
+ &MinMaxAccesses));
isl_union_set_free(Locations);
return Valid;
}
@@ -1594,8 +1594,11 @@ bool Scop::buildAliasGroups(AliasAnalysi
}
// Calculate minimal and maximal accesses for non read only accesses.
- MinMaxVectorTy *MinMaxAccessesNonReadOnly = new MinMaxVectorTy();
- MinMaxAccessesNonReadOnly->reserve(AG.size());
+ MinMaxAliasGroups.emplace_back();
+ MinMaxVectorPairTy &pair = MinMaxAliasGroups.back();
+ MinMaxVectorTy &MinMaxAccessesNonReadOnly = pair.first;
+ MinMaxVectorTy &MinMaxAccessesReadOnly = pair.second;
+ MinMaxAccessesNonReadOnly.reserve(AG.size());
isl_union_map *Accesses = isl_union_map_empty(getParamSpace());
@@ -1609,19 +1612,12 @@ bool Scop::buildAliasGroups(AliasAnalysi
// Bail out if the number of values we need to compare is too large.
// This is important as the number of comparisions grows quadratically with
// the number of values we need to compare.
- if (!Valid || (MinMaxAccessesNonReadOnly->size() + !ReadOnlyPairs.empty() >
- RunTimeChecksMaxArraysPerGroup)) {
- for (MinMaxAccessTy &MMA : *(MinMaxAccessesNonReadOnly)) {
- isl_pw_multi_aff_free(MMA.first);
- isl_pw_multi_aff_free(MMA.second);
- }
+ if (!Valid || (MinMaxAccessesNonReadOnly.size() + !ReadOnlyPairs.empty() >
+ RunTimeChecksMaxArraysPerGroup))
return false;
- }
// Calculate minimal and maximal accesses for read only accesses.
- MinMaxVectorTy *MinMaxAccessesReadOnly = new MinMaxVectorTy();
- MinMaxAccessesReadOnly->reserve(ReadOnlyPairs.size());
-
+ MinMaxAccessesReadOnly.reserve(ReadOnlyPairs.size());
Accesses = isl_union_map_empty(getParamSpace());
for (const auto &ReadOnlyPair : ReadOnlyPairs)
@@ -1630,8 +1626,6 @@ bool Scop::buildAliasGroups(AliasAnalysi
Valid = calculateMinMaxAccess(Accesses, getDomains(), getAssumedContext(),
MinMaxAccessesReadOnly);
- MinMaxVectorPairTy pair(MinMaxAccessesNonReadOnly, MinMaxAccessesReadOnly);
- MinMaxAliasGroups.push_back(pair);
if (!Valid)
return false;
@@ -1698,16 +1692,14 @@ Scop::~Scop() {
// Free the alias groups
for (MinMaxVectorPairTy &MinMaxAccessPair : MinMaxAliasGroups) {
- for (MinMaxAccessTy &MMA : *(MinMaxAccessPair.first)) {
+ for (MinMaxAccessTy &MMA : MinMaxAccessPair.first) {
isl_pw_multi_aff_free(MMA.first);
isl_pw_multi_aff_free(MMA.second);
}
- for (MinMaxAccessTy &MMA : *(MinMaxAccessPair.second)) {
+ for (MinMaxAccessTy &MMA : MinMaxAccessPair.second) {
isl_pw_multi_aff_free(MMA.first);
isl_pw_multi_aff_free(MMA.second);
}
- delete MinMaxAccessPair.first;
- delete MinMaxAccessPair.second;
}
}
@@ -1789,10 +1781,10 @@ void Scop::printContext(raw_ostream &OS)
void Scop::printAliasAssumptions(raw_ostream &OS) const {
int noOfGroups = 0;
for (const MinMaxVectorPairTy &Pair : MinMaxAliasGroups) {
- if (Pair.second->size() == 0)
+ if (Pair.second.size() == 0)
noOfGroups += 1;
else
- noOfGroups += Pair.second->size();
+ noOfGroups += Pair.second.size();
}
OS.indent(4) << "Alias Groups (" << noOfGroups << "):\n";
@@ -1804,19 +1796,19 @@ void Scop::printAliasAssumptions(raw_ost
for (const MinMaxVectorPairTy &Pair : MinMaxAliasGroups) {
// If the group has no read only accesses print the write accesses.
- if (Pair.second->empty()) {
+ if (Pair.second.empty()) {
OS.indent(8) << "[[";
- for (MinMaxAccessTy &MMANonReadOnly : *(Pair.first)) {
+ for (const MinMaxAccessTy &MMANonReadOnly : Pair.first) {
OS << " <" << MMANonReadOnly.first << ", " << MMANonReadOnly.second
<< ">";
}
OS << " ]]\n";
}
- for (MinMaxAccessTy &MMAReadOnly : *(Pair.second)) {
+ for (const MinMaxAccessTy &MMAReadOnly : Pair.second) {
OS.indent(8) << "[[";
OS << " <" << MMAReadOnly.first << ", " << MMAReadOnly.second << ">";
- for (MinMaxAccessTy &MMANonReadOnly : *(Pair.first)) {
+ for (const MinMaxAccessTy &MMANonReadOnly : Pair.first) {
OS << " <" << MMANonReadOnly.first << ", " << MMANonReadOnly.second
<< ">";
}
Modified: polly/trunk/lib/CodeGen/IslAst.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslAst.cpp?rev=243245&r1=243244&r2=243245&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslAst.cpp (original)
+++ polly/trunk/lib/CodeGen/IslAst.cpp Sun Jul 26 08:14:38 2015
@@ -304,9 +304,9 @@ static __isl_give isl_ast_node *AtEachDo
}
// Build alias check condition given a pair of minimal/maximal access.
-static __isl_give isl_ast_expr *buildCondition(__isl_keep isl_ast_build *Build,
- Scop::MinMaxAccessTy *It0,
- Scop::MinMaxAccessTy *It1) {
+static __isl_give isl_ast_expr *
+buildCondition(__isl_keep isl_ast_build *Build, const Scop::MinMaxAccessTy *It0,
+ const Scop::MinMaxAccessTy *It1) {
isl_ast_expr *NonAliasGroup, *MinExpr, *MaxExpr;
MinExpr = isl_ast_expr_address_of(isl_ast_build_access_from_pw_multi_aff(
Build, isl_pw_multi_aff_copy(It0->first)));
@@ -334,16 +334,16 @@ void IslAst::buildRunCondition(__isl_kee
// This operation is by construction quadratic in the read-write pointers and
// linear int the read only pointers in each alias group.
for (const Scop::MinMaxVectorPairTy &MinMaxAccessPair : S->getAliasGroups()) {
- auto *MinMaxReadWrite = MinMaxAccessPair.first;
- auto *MinMaxReadOnly = MinMaxAccessPair.second;
- auto RWAccEnd = MinMaxReadWrite->end();
+ auto &MinMaxReadWrite = MinMaxAccessPair.first;
+ auto &MinMaxReadOnly = MinMaxAccessPair.second;
+ auto RWAccEnd = MinMaxReadWrite.end();
- for (auto RWAccIt0 = MinMaxReadWrite->begin(); RWAccIt0 != RWAccEnd;
+ for (auto RWAccIt0 = MinMaxReadWrite.begin(); RWAccIt0 != RWAccEnd;
++RWAccIt0) {
for (auto RWAccIt1 = RWAccIt0 + 1; RWAccIt1 != RWAccEnd; ++RWAccIt1)
RunCondition = isl_ast_expr_and(
RunCondition, buildCondition(Build, RWAccIt0, RWAccIt1));
- for (Scop::MinMaxAccessTy &ROAccIt : *MinMaxReadOnly)
+ for (const Scop::MinMaxAccessTy &ROAccIt : MinMaxReadOnly)
RunCondition = isl_ast_expr_and(
RunCondition, buildCondition(Build, RWAccIt0, &ROAccIt));
}
More information about the llvm-commits
mailing list