[polly] r255777 - ScopInfo: Directly store MemoryAccessList in InstructionToAccess

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 08:14:04 PST 2015


Author: grosser
Date: Wed Dec 16 10:14:03 2015
New Revision: 255777

URL: http://llvm.org/viewvc/llvm-project?rev=255777&view=rev
Log:
ScopInfo: Directly store MemoryAccessList in InstructionToAccess

This avoids the need for explicit memory management, simplifies the code and
also fixes a memory leak in removeMemoryAccesses.

Modified:
    polly/trunk/include/polly/ScopInfo.h
    polly/trunk/lib/Analysis/ScopInfo.cpp

Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=255777&r1=255776&r2=255777&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Wed Dec 16 10:14:03 2015
@@ -827,7 +827,7 @@ private:
   MemoryAccessVec MemAccs;
 
   /// @brief Mapping from instructions to (scalar) memory accesses.
-  DenseMap<const Instruction *, MemoryAccessList *> InstructionToAccess;
+  DenseMap<const Instruction *, MemoryAccessList> InstructionToAccess;
 
   //@}
 
@@ -957,14 +957,6 @@ public:
   /// @brief Return true if this statement does not contain any accesses.
   bool isEmpty() const { return MemAccs.empty(); }
 
-  /// @brief Return the (scalar) memory accesses for @p Inst if any.
-  MemoryAccessList *lookupAccessesFor(const Instruction *Inst) const {
-    auto It = InstructionToAccess.find(Inst);
-    if (It == InstructionToAccess.end())
-      return nullptr;
-    return It->getSecond()->empty() ? nullptr : It->getSecond();
-  }
-
   /// @brief Return the only array access for @p Inst.
   ///
   /// @param Inst The instruction for which to look up the access.
@@ -973,13 +965,10 @@ public:
     auto It = InstructionToAccess.find(Inst);
     assert(It != InstructionToAccess.end() &&
            "No memory accesses found for instruction");
-    auto *Accesses = It->getSecond();
-
-    assert(Accesses && "No memory accesses found for instruction");
 
     MemoryAccess *ArrayAccess = nullptr;
 
-    for (auto Access : *Accesses) {
+    for (auto Access : It->getSecond()) {
       if (!Access->isArrayKind())
         continue;
 
@@ -1002,12 +991,7 @@ public:
     if (It == InstructionToAccess.end())
       return 0;
 
-    auto *Accesses = It->getSecond();
-
-    if (!Accesses)
-      return 0;
-
-    for (auto Access : *Accesses) {
+    for (auto Access : It->getSecond()) {
       if (Access->isArrayKind())
         NumAccesses++;
     }
@@ -1015,14 +999,6 @@ public:
     return NumAccesses;
   }
 
-  /// @brief Return the __first__ (scalar) memory access for @p Inst if any.
-  MemoryAccess *lookupAccessFor(const Instruction *Inst) const {
-    auto It = InstructionToAccess.find(Inst);
-    if (It == InstructionToAccess.end())
-      return nullptr;
-    return It->getSecond()->empty() ? nullptr : It->getSecond()->front();
-  }
-
   void setBasicBlock(BasicBlock *Block) {
     // TODO: Handle the case where the statement is a region statement, thus
     //       the entry block was split and needs to be changed in the region R.

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=255777&r1=255776&r2=255777&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Wed Dec 16 10:14:03 2015
@@ -899,11 +899,9 @@ void ScopStmt::buildAccessRelations() {
 void ScopStmt::addAccess(MemoryAccess *Access) {
   Instruction *AccessInst = Access->getAccessInstruction();
 
-  MemoryAccessList *&MAL = InstructionToAccess[AccessInst];
-  if (!MAL)
-    MAL = new MemoryAccessList();
-  MAL->emplace_front(Access);
-  MemAccs.push_back(MAL->front());
+  MemoryAccessList &MAL = InstructionToAccess[AccessInst];
+  MAL.emplace_front(Access);
+  MemAccs.push_back(MAL.front());
 }
 
 void ScopStmt::realignParams() {
@@ -1435,10 +1433,7 @@ __isl_give isl_id *ScopStmt::getDomainId
   return isl_set_get_tuple_id(Domain);
 }
 
-ScopStmt::~ScopStmt() {
-  DeleteContainerSeconds(InstructionToAccess);
-  isl_set_free(Domain);
-}
+ScopStmt::~ScopStmt() { isl_set_free(Domain); }
 
 void ScopStmt::print(raw_ostream &OS) const {
   OS << "\t" << getBaseName() << "\n";
@@ -1472,7 +1467,6 @@ void ScopStmt::removeMemoryAccesses(Memo
     MemAccs.erase(std::remove_if(MemAccs.begin(), MemAccs.end(), Predicate),
                   MemAccs.end());
     InstructionToAccess.erase(MA->getAccessInstruction());
-    delete lookupAccessesFor(MA->getAccessInstruction());
   }
 }
 




More information about the llvm-commits mailing list