[polly] r254305 - ScopInfo: Replace while/iterator construct with std::remove_if

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 30 09:20:41 PST 2015


Author: grosser
Date: Mon Nov 30 11:20:40 2015
New Revision: 254305

URL: http://llvm.org/viewvc/llvm-project?rev=254305&view=rev
Log:
ScopInfo: Replace while/iterator construct with std::remove_if

The use of C++'s high-level iterator functionality instead of two while loops
and explicit iterator handling improves readability of this code.

Proposed-by: Michael Kruse <llvm at meinersbur.de>

Differential Revision: http://reviews.llvm.org/D15068

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

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=254305&r1=254304&r2=254305&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Mon Nov 30 11:20:40 2015
@@ -1464,29 +1464,17 @@ void ScopStmt::print(raw_ostream &OS) co
 void ScopStmt::dump() const { print(dbgs()); }
 
 void ScopStmt::removeMemoryAccesses(MemoryAccessList &InvMAs) {
-
-  // Remove all memory accesses in @p InvMAs from this statement together
-  // with all scalar accesses that were caused by them. The tricky iteration
-  // order uses is needed because the MemAccs is a vector and the order in
-  // which the accesses of each memory access list (MAL) are stored in this
-  // vector is reversed.
+  // Remove all memory accesses in @p InvMAs from this statement
+  // together with all scalar accesses that were caused by them.
   for (MemoryAccess *MA : InvMAs) {
-    auto &MAL = *lookupAccessesFor(MA->getAccessInstruction());
-    MAL.reverse();
-
-    auto MALIt = MAL.begin();
-    auto MALEnd = MAL.end();
-    auto MemAccsIt = MemAccs.begin();
-    while (MALIt != MALEnd) {
-      while (*MemAccsIt != *MALIt)
-        MemAccsIt++;
-
-      MALIt++;
-      MemAccs.erase(MemAccsIt);
-    }
-
+    auto Predicate = [&](MemoryAccess *Acc) {
+      return Acc == MA ||
+             Acc->getAccessInstruction() == MA->getAccessInstruction();
+    };
+    MemAccs.erase(std::remove_if(MemAccs.begin(), MemAccs.end(), Predicate),
+                  MemAccs.end());
     InstructionToAccess.erase(MA->getAccessInstruction());
-    delete &MAL;
+    delete lookupAccessesFor(MA->getAccessInstruction());
   }
 }
 




More information about the llvm-commits mailing list