[PATCH] D15068: ScopInfo: Replace while/iterator construct with std::remove_if

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 29 21:36:26 PST 2015


grosser created this revision.
grosser added reviewers: jdoerfert, Meinersbur.
grosser added subscribers: llvm-commits, pollydev.

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

This passes LNT -polly-process-unprofitable for me.

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

http://reviews.llvm.org/D15068

Files:
  lib/Analysis/ScopInfo.cpp

Index: lib/Analysis/ScopInfo.cpp
===================================================================
--- lib/Analysis/ScopInfo.cpp
+++ lib/Analysis/ScopInfo.cpp
@@ -1464,28 +1464,18 @@
 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 = [MA](MemoryAccess *Acc) -> bool {
+      return (Acc == MA) ||
+             (Acc->isWrite() &&
+              Acc->getAccessInstruction() == MA->getAccessInstruction());
+    };
+    MemAccs.erase(std::remove_if(MemAccs.begin(), MemAccs.end(), Predicate),
+                  MemAccs.end());
     InstructionToAccess.erase(MA->getAccessInstruction());
+    auto &MAL = *lookupAccessesFor(MA->getAccessInstruction());
     delete &MAL;
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15068.41367.patch
Type: text/x-patch
Size: 1604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151130/c5007606/attachment-0001.bin>


More information about the llvm-commits mailing list