Skip to content

Commit 2b28275

Browse files
committed
[CaptureTracking] Make MaxUsesToExplore cheaper (NFC)
The change in D78624 had a noticeable negative compile-time impact. It seems that going through a function call for the MaxUsesToExplore default is fairly expensive, at least if LLVM is not built with LTO. This patch makes MaxUsesToExpore default to 0 and assigns the actual default in the implementation instead. This recovers most of the regression. Differential Revision: https://reviews.llvm.org/D78734
1 parent 164845c commit 2b28275

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

llvm/include/llvm/Analysis/CaptureTracking.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ namespace llvm {
3333
/// counts as capturing it or not. The boolean StoreCaptures specified
3434
/// whether storing the value (or part of it) into memory anywhere
3535
/// automatically counts as capturing it or not.
36-
/// MaxUsesToExplore specifies how many uses should the analysis explore for
37-
/// one value before giving up due too "too many uses".
36+
/// MaxUsesToExplore specifies how many uses the analysis should explore for
37+
/// one value before giving up due too "too many uses". If MaxUsesToExplore
38+
/// is zero, a default value is assumed.
3839
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures,
3940
bool StoreCaptures,
40-
unsigned MaxUsesToExplore =
41-
getDefaultMaxUsesToExploreForCaptureTracking());
41+
unsigned MaxUsesToExplore = 0);
4242

4343
/// PointerMayBeCapturedBefore - Return true if this pointer value may be
4444
/// captured by the enclosing function (which is required to exist). If a
@@ -50,13 +50,13 @@ namespace llvm {
5050
/// (or part of it) into memory anywhere automatically counts as capturing it
5151
/// or not. Captures by the provided instruction are considered if the
5252
/// final parameter is true.
53-
/// MaxUsesToExplore specifies how many uses should the analysis explore for
54-
/// one value before giving up due too "too many uses".
53+
/// MaxUsesToExplore specifies how many uses the analysis should explore for
54+
/// one value before giving up due too "too many uses". If MaxUsesToExplore
55+
/// is zero, a default value is assumed.
5556
bool PointerMayBeCapturedBefore(
5657
const Value *V, bool ReturnCaptures, bool StoreCaptures,
5758
const Instruction *I, const DominatorTree *DT, bool IncludeI = false,
58-
unsigned MaxUsesToExplore =
59-
getDefaultMaxUsesToExploreForCaptureTracking());
59+
unsigned MaxUsesToExplore = 0);
6060

6161
/// This callback is used in conjunction with PointerMayBeCaptured. In
6262
/// addition to the interface here, you'll need to provide your own getters
@@ -89,11 +89,11 @@ namespace llvm {
8989
/// PointerMayBeCaptured - Visit the value and the values derived from it and
9090
/// find values which appear to be capturing the pointer value. This feeds
9191
/// results into and is controlled by the CaptureTracker object.
92-
/// MaxUsesToExplore specifies how many uses should the analysis explore for
93-
/// one value before giving up due too "too many uses".
92+
/// MaxUsesToExplore specifies how many uses the analysis should explore for
93+
/// one value before giving up due too "too many uses". If MaxUsesToExplore
94+
/// is zero, a default value is assumed.
9495
void PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
95-
unsigned MaxUsesToExplore =
96-
getDefaultMaxUsesToExploreForCaptureTracking());
96+
unsigned MaxUsesToExplore = 0);
9797
} // end namespace llvm
9898

9999
#endif

llvm/lib/Analysis/CaptureTracking.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ bool llvm::PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
230230
void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
231231
unsigned MaxUsesToExplore) {
232232
assert(V->getType()->isPointerTy() && "Capture is for pointers only!");
233+
if (MaxUsesToExplore == 0)
234+
MaxUsesToExplore = DefaultMaxUsesToExplore;
235+
233236
SmallVector<const Use *, 20> Worklist;
234237
Worklist.reserve(getDefaultMaxUsesToExploreForCaptureTracking());
235238
SmallSet<const Use *, 20> Visited;

0 commit comments

Comments
 (0)