[PATCH] D60357: Improve visited block tracking is isPotentiallyReachable.

Nick Lewycky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 5 21:22:29 PDT 2019


nicholas created this revision.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
nicholas added a parent revision: D60356: Accelerate isPotentiallyReachable when a DominatorTree is available..

The outermost loop check and dominator check cover multiple blocks, but we only entered one of the blocks in Visited. Add all blocks we really checked to avoid visiting them again.

      

In one sense there's no functionality change, but this does change how the accounting towards the threshold is handled. Skipping a visited block does not count towards the block limit.


https://reviews.llvm.org/D60357

Files:
  llvm/lib/Analysis/CFG.cpp


Index: llvm/lib/Analysis/CFG.cpp
===================================================================
--- llvm/lib/Analysis/CFG.cpp
+++ llvm/lib/Analysis/CFG.cpp
@@ -147,6 +147,8 @@
 
   const Loop *StopLoop = LI ? getOutermostLoop(LI, StopBB) : nullptr;
 
+  const DomTreeNode *StopNode = DT ? DT->getNode(StopBB) : nullptr;
+
   // Limit the number of blocks we visit. The goal is to avoid run-away compile
   // times on large CFGs without hampering sensible code. Arbitrarily chosen.
   unsigned Limit = 32;
@@ -159,7 +161,9 @@
       return true;
     if (ExclusionSet && ExclusionSet->count(BB))
       continue;
-    if (DT && DT->dominates(BB, StopBB))
+
+    DomTreeNode *DTN = StopNode ? DT->getNode(BB) : nullptr;
+    if (StopNode && DTN && DT->dominates(DTN, StopNode))
       return true;
 
     const Loop *Outer = nullptr;
@@ -185,7 +189,24 @@
       // 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
+      // over the domtree-descendants of the block to visit their successors.
+      for (auto I = df_begin(DTN), E = df_end(DTN); I != E;) {
+        for (auto Succ : successors(I->getBlock())) {
+          if (!DT->dominates(DTN, DT->getNode(Succ)))
+            Worklist.push_back(Succ);
+        }
+        ++I;
+        while (I != E && !Visited.insert(I->getBlock()).second) {
+          // Don't enqueue any domtree-descendants of a visited block. We've
+          // already either visited its descendants or enqueued them.
+          // I.skipChildren() implicitly performs ++I.
+          I.skipChildren();
+        }
+      }
     } else {
       Worklist.append(succ_begin(BB), succ_end(BB));
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60357.194003.patch
Type: text/x-patch
Size: 1997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190406/0fcfcd44/attachment.bin>


More information about the llvm-commits mailing list