[PATCH] D90487: [CFG] Replace hardcoded max BBs explored as CL option. NFC.

Anna Thomas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 30 11:07:35 PDT 2020


anna created this revision.
anna added reviewers: apilipenko, skatkov, jdoerfert.
Herald added subscribers: dantrushin, hiraditya.
Herald added a project: LLVM.
anna requested review of this revision.

This option was hardcoded to 32. Changing this as a CL option since we
have seen some cases downstream where increasing this limit allows us to
disprove reachability.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90487

Files:
  llvm/lib/Analysis/CFG.cpp


Index: llvm/lib/Analysis/CFG.cpp
===================================================================
--- llvm/lib/Analysis/CFG.cpp
+++ llvm/lib/Analysis/CFG.cpp
@@ -14,9 +14,18 @@
 #include "llvm/Analysis/CFG.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/IR/Dominators.h"
+#include "llvm/Support/CommandLine.h"
 
 using namespace llvm;
 
+// The max number of basic blocks explored during reachability analysis between
+// two basic blocks. This is kept reasonably small to limit compile time when
+// repeatedly used by clients of this analysis (such as captureTracking).
+static cl::opt<unsigned> DefaultMaxBBsToExplore(
+    "dom-tree-reachability-max-bbs-to-explore", cl::Hidden,
+    cl::desc("Max number of BBs to explore for reachability analysis"),
+    cl::init(32));
+
 /// FindFunctionBackedges - Analyze the specified function to find all of the
 /// loop backedges in the function and return them.  This is a relatively cheap
 /// (compared to computing dominators and loop info) analysis.
@@ -152,9 +161,7 @@
 
   const Loop *StopLoop = LI ? getOutermostLoop(LI, 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;
+  unsigned Count = 0;
   SmallPtrSet<const BasicBlock*, 32> Visited;
   do {
     BasicBlock *BB = Worklist.pop_back_val();
@@ -180,7 +187,7 @@
         return true;
     }
 
-    if (!--Limit) {
+    if (++Count >= DefaultMaxBBsToExplore) {
       // We haven't been able to prove it one way or the other. Conservatively
       // answer true -- that there is potentially a path.
       return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90487.301965.patch
Type: text/x-patch
Size: 1694 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201030/89ba0efc/attachment.bin>


More information about the llvm-commits mailing list