[polly] r239050 - Store ArrayShape in shared_ptr and MemAccs as actual objects

Tobias Grosser tobias at grosser.es
Thu Jun 4 09:03:17 PDT 2015


Author: grosser
Date: Thu Jun  4 11:03:16 2015
New Revision: 239050

URL: http://llvm.org/viewvc/llvm-project?rev=239050&view=rev
Log:
Store ArrayShape in shared_ptr and MemAccs as actual objects

This fixes two more memory leaks.

Modified:
    polly/trunk/include/polly/ScopDetection.h
    polly/trunk/lib/Analysis/ScopDetection.cpp
    polly/trunk/lib/Analysis/TempScopInfo.cpp

Modified: polly/trunk/include/polly/ScopDetection.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopDetection.h?rev=239050&r1=239049&r2=239050&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopDetection.h (original)
+++ polly/trunk/include/polly/ScopDetection.h Thu Jun  4 11:03:16 2015
@@ -52,6 +52,7 @@
 #include "llvm/Analysis/AliasSetTracker.h"
 #include "llvm/Pass.h"
 #include <map>
+#include <memory>
 #include <set>
 
 using namespace llvm;
@@ -89,16 +90,16 @@ struct MemAcc {
   const Instruction *Insn;
 
   // A pointer to the shape description of the array.
-  ArrayShape *Shape;
+  std::shared_ptr<ArrayShape> Shape;
 
   // Subscripts computed by delinearization.
   SmallVector<const SCEV *, 4> DelinearizedSubscripts;
 
-  MemAcc(const Instruction *I, ArrayShape *S)
+  MemAcc(const Instruction *I, std::shared_ptr<ArrayShape> S)
       : Insn(I), Shape(S), DelinearizedSubscripts() {}
 };
 
-typedef std::map<const Instruction *, MemAcc *> MapInsnToMemAcc;
+typedef std::map<const Instruction *, MemAcc> MapInsnToMemAcc;
 typedef std::pair<const Instruction *, const SCEV *> PairInstSCEV;
 typedef std::vector<PairInstSCEV> AFs;
 typedef std::map<const SCEVUnknown *, AFs> BaseToAFs;

Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=239050&r1=239049&r2=239050&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Thu Jun  4 11:03:16 2015
@@ -471,7 +471,7 @@ bool ScopDetection::hasAffineMemoryAcces
 
   for (const SCEVUnknown *BasePointer : Context.NonAffineAccesses) {
     Value *BaseValue = BasePointer->getValue();
-    ArrayShape *Shape = new ArrayShape(BasePointer);
+    auto Shape = std::shared_ptr<ArrayShape>(new ArrayShape(BasePointer));
     bool BasePtrHasNonAffine = false;
 
     // First step: collect parametric terms in all array references.
@@ -527,8 +527,10 @@ bool ScopDetection::hasAffineMemoryAcces
       const Instruction *Insn = Pair.first;
       const SCEVAddRecExpr *AF = dyn_cast<SCEVAddRecExpr>(Pair.second);
       bool IsNonAffine = false;
-      MemAcc *Acc = new MemAcc(Insn, Shape);
-      TempMemoryAccesses.insert({Insn, Acc});
+      TempMemoryAccesses.emplace(std::piecewise_construct,
+                                 std::forward_as_tuple(Insn),
+                                 std::forward_as_tuple(Insn, Shape));
+      MemAcc *Acc = &TempMemoryAccesses.find(Insn)->second;
 
       if (!AF) {
         if (isAffineExpr(&CurRegion, Pair.second, *SE, BaseValue))

Modified: polly/trunk/lib/Analysis/TempScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/TempScopInfo.cpp?rev=239050&r1=239049&r2=239050&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/TempScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/TempScopInfo.cpp Thu Jun  4 11:03:16 2015
@@ -237,10 +237,11 @@ TempScopInfo::buildIRAccess(Instruction
   assert(BasePointer && "Could not find base pointer");
   AccessFunction = SE->getMinusSCEV(AccessFunction, BasePointer);
 
-  MemAcc *Acc = InsnToMemAcc[Inst];
-  if (PollyDelinearize && Acc)
+  auto AccItr = InsnToMemAcc.find(Inst);
+  if (PollyDelinearize && AccItr != InsnToMemAcc.end())
     return IRAccess(Type, BasePointer->getValue(), AccessFunction, Size, true,
-                    Acc->DelinearizedSubscripts, Acc->Shape->DelinearizedSizes);
+                    AccItr->second.DelinearizedSubscripts,
+                    AccItr->second.Shape->DelinearizedSizes);
 
   // Check if the access depends on a loop contained in a non-affine subregion.
   bool isVariantInNonAffineLoop = false;





More information about the llvm-commits mailing list