[PATCH] D78624: [CaptureTracking] Replace hardcoded constant to option. NFC.

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 22 09:13:26 PDT 2020


skatkov updated this revision to Diff 259316.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D78624/new/

https://reviews.llvm.org/D78624

Files:
  llvm/include/llvm/Analysis/CaptureTracking.h
  llvm/lib/Analysis/CaptureTracking.cpp
  llvm/lib/Transforms/IPO/AttributorAttributes.cpp


Index: llvm/lib/Transforms/IPO/AttributorAttributes.cpp
===================================================================
--- llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -4170,7 +4170,8 @@
   // defined in AACaptureUseTracker, that can look at in-flight abstract
   // attributes and directly updates the assumed state.
   SmallVector<const Value *, 4> PotentialCopies;
-  unsigned RemainingUsesToExplore = DefaultMaxUsesToExplore;
+  unsigned RemainingUsesToExplore =
+      getDefaultMaxUsesToExploreForCaptureTracking();
   AACaptureUseTracker Tracker(A, *this, IsDeadAA, T, PotentialCopies,
                               RemainingUsesToExplore);
 
Index: llvm/lib/Analysis/CaptureTracking.cpp
===================================================================
--- llvm/lib/Analysis/CaptureTracking.cpp
+++ llvm/lib/Analysis/CaptureTracking.cpp
@@ -28,6 +28,15 @@
 
 using namespace llvm;
 
+static cl::opt<unsigned>
+DefaultMaxUsesToExplore("capture-tracking-max-uses-to-explore", cl::Hidden,
+                        cl::desc("Maximal number of uses to explore."),
+                        cl::init(20));
+
+unsigned llvm::getDefaultMaxUsesToExploreForCaptureTracking() {
+  return DefaultMaxUsesToExplore;
+}
+
 CaptureTracker::~CaptureTracker() {}
 
 bool CaptureTracker::shouldExplore(const Use *U) { return true; }
@@ -215,8 +224,9 @@
 void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
                                 unsigned MaxUsesToExplore) {
   assert(V->getType()->isPointerTy() && "Capture is for pointers only!");
-  SmallVector<const Use *, DefaultMaxUsesToExplore> Worklist;
-  SmallSet<const Use *, DefaultMaxUsesToExplore> Visited;
+  SmallVector<const Use *, 20> Worklist;
+  Worklist.reserve(getDefaultMaxUsesToExploreForCaptureTracking());
+  SmallSet<const Use *, 20> Visited;
 
   auto AddUses = [&](const Value *V) {
     unsigned Count = 0;
Index: llvm/include/llvm/Analysis/CaptureTracking.h
===================================================================
--- llvm/include/llvm/Analysis/CaptureTracking.h
+++ llvm/include/llvm/Analysis/CaptureTracking.h
@@ -27,7 +27,7 @@
   /// TODO: we should probably introduce a caching CaptureTracking analysis and
   /// use it where possible. The caching version can use much higher limit or
   /// don't have this cap at all.
-  unsigned constexpr DefaultMaxUsesToExplore = 20;
+  unsigned getDefaultMaxUsesToExploreForCaptureTracking();
 
   /// PointerMayBeCaptured - Return true if this pointer value may be captured
   /// by the enclosing function (which is required to exist).  This routine can
@@ -38,10 +38,10 @@
   /// automatically counts as capturing it or not.
   /// MaxUsesToExplore specifies how many uses should the analysis explore for
   /// one value before giving up due too "too many uses".
-  bool PointerMayBeCaptured(const Value *V,
-                            bool ReturnCaptures,
+  bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures,
                             bool StoreCaptures,
-                            unsigned MaxUsesToExplore = DefaultMaxUsesToExplore);
+                            unsigned MaxUsesToExplore =
+                                getDefaultMaxUsesToExploreForCaptureTracking());
 
   /// PointerMayBeCapturedBefore - Return true if this pointer value may be
   /// captured by the enclosing function (which is required to exist). If a
@@ -55,10 +55,11 @@
   /// final parameter is true.
   /// MaxUsesToExplore specifies how many uses should the analysis explore for
   /// one value before giving up due too "too many uses".
-  bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
-                                  bool StoreCaptures, const Instruction *I,
-                                  const DominatorTree *DT, bool IncludeI = false,
-                                  unsigned MaxUsesToExplore = DefaultMaxUsesToExplore);
+  bool PointerMayBeCapturedBefore(
+      const Value *V, bool ReturnCaptures, bool StoreCaptures,
+      const Instruction *I, const DominatorTree *DT, bool IncludeI = false,
+      unsigned MaxUsesToExplore =
+          getDefaultMaxUsesToExploreForCaptureTracking());
 
   /// This callback is used in conjunction with PointerMayBeCaptured. In
   /// addition to the interface here, you'll need to provide your own getters
@@ -94,7 +95,8 @@
   /// MaxUsesToExplore specifies how many uses should the analysis explore for
   /// one value before giving up due too "too many uses".
   void PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
-                            unsigned MaxUsesToExplore = DefaultMaxUsesToExplore);
+                            unsigned MaxUsesToExplore =
+                                getDefaultMaxUsesToExploreForCaptureTracking());
 } // end namespace llvm
 
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78624.259316.patch
Type: text/x-patch
Size: 4886 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200422/9a09ac2d/attachment.bin>


More information about the llvm-commits mailing list