Index: llvm/include/llvm/Analysis/CaptureTracking.h =================================================================== --- llvm/include/llvm/Analysis/CaptureTracking.h +++ llvm/include/llvm/Analysis/CaptureTracking.h @@ -21,13 +21,7 @@ class Instruction; class DominatorTree; - /// The default value for MaxUsesToExplore argument. It's relatively small to - /// keep the cost of analysis reasonable for clients like BasicAliasAnalysis, - /// where the results can't be cached. - /// 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 +32,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 +49,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 +89,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 Index: llvm/lib/Analysis/CaptureTracking.cpp =================================================================== --- llvm/lib/Analysis/CaptureTracking.cpp +++ llvm/lib/Analysis/CaptureTracking.cpp @@ -28,6 +28,21 @@ using namespace llvm; +static cl::opt +DefaultMaxUsesToExplore("capture-tracking-max-uses-to-explore", cl::Hidden, + cl::desc("Maximal number of uses to explore."), + cl::init(20)); + +/// The default value for MaxUsesToExplore argument. It's relatively small to +/// keep the cost of analysis reasonable for clients like BasicAliasAnalysis, +/// where the results can't be cached. +/// 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 llvm::getDefaultMaxUsesToExploreForCaptureTracking() { + return DefaultMaxUsesToExplore; +} + CaptureTracker::~CaptureTracker() {} bool CaptureTracker::shouldExplore(const Use *U) { return true; } @@ -215,8 +230,9 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker, unsigned MaxUsesToExplore) { assert(V->getType()->isPointerTy() && "Capture is for pointers only!"); - SmallVector Worklist; - SmallSet Visited; + SmallVector Worklist; + Worklist.reserve(getDefaultMaxUsesToExploreForCaptureTracking()); + SmallSet Visited; auto AddUses = [&](const Value *V) { unsigned Count = 0; 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 PotentialCopies; - unsigned RemainingUsesToExplore = DefaultMaxUsesToExplore; + unsigned RemainingUsesToExplore = + getDefaultMaxUsesToExploreForCaptureTracking(); AACaptureUseTracker Tracker(A, *this, IsDeadAA, T, PotentialCopies, RemainingUsesToExplore);