[PATCH] D60752: [NFCI] Use less memory by storing the Loop* as visited instead of storing each BasicBlock* in the block as visited.

Nick Lewycky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 16 00:38:53 PDT 2019


nicholas created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
nicholas added a parent revision: D60357: Improve visited block tracking in isPotentiallyReachable..

https://reviews.llvm.org/D60752

Files:
  llvm/lib/Analysis/CFG.cpp


Index: llvm/lib/Analysis/CFG.cpp
===================================================================
--- llvm/lib/Analysis/CFG.cpp
+++ llvm/lib/Analysis/CFG.cpp
@@ -153,6 +153,7 @@
   // times on large CFGs without hampering sensible code. Arbitrarily chosen.
   unsigned Limit = 32;
   SmallPtrSet<const BasicBlock*, 32> Visited;
+  SmallPtrSet<const Loop*, 32> VisitedLoops;
   do {
     BasicBlock *BB = Worklist.pop_back_val();
     if (!Visited.insert(BB).second)
@@ -169,12 +170,17 @@
     const Loop *Outer = nullptr;
     if (LI) {
       Outer = getOutermostLoop(LI, BB);
+
       // If we're in a loop with a hole, not all blocks in the loop are
       // reachable from all other blocks. That implies we can't simply jump to
       // the loop's exit blocks, as that exit might need to pass through an
       // excluded block. Clear Outer so we process BB's successors.
       if (LoopsWithHoles.count(Outer))
         Outer = nullptr;
+
+      if (Outer && !VisitedLoops.insert(Outer).second)
+        continue;
+
       if (StopLoop && Outer == StopLoop)
         return true;
     }
@@ -189,7 +195,6 @@
       // All blocks in a single loop are reachable from all other blocks. From
       // any of these blocks, we can skip directly to the exits of the loop,
       // ignoring any other blocks inside the loop body.
-      Visited.insert(Outer->block_begin(), Outer->block_end());
       Outer->getExitBlocks(Worklist);
     } else if (DTN) {
       // The dominance check effectively visits all blocks dominated by BB. Skip


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60752.195305.patch
Type: text/x-patch
Size: 1543 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190416/d6048194/attachment.bin>


More information about the llvm-commits mailing list