[llvm] 2b28275 - [CaptureTracking] Make MaxUsesToExplore cheaper (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 26 00:57:01 PDT 2020
Author: Nikita Popov
Date: 2020-04-26T09:54:15+02:00
New Revision: 2b2827552ad7e0fbd30597d714e751516f83e0f9
URL: https://github.com/llvm/llvm-project/commit/2b2827552ad7e0fbd30597d714e751516f83e0f9
DIFF: https://github.com/llvm/llvm-project/commit/2b2827552ad7e0fbd30597d714e751516f83e0f9.diff
LOG: [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
Added:
Modified:
llvm/include/llvm/Analysis/CaptureTracking.h
llvm/lib/Analysis/CaptureTracking.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/CaptureTracking.h b/llvm/include/llvm/Analysis/CaptureTracking.h
index f14149ac86d1..62d226401d49 100644
--- a/llvm/include/llvm/Analysis/CaptureTracking.h
+++ b/llvm/include/llvm/Analysis/CaptureTracking.h
@@ -33,12 +33,12 @@ namespace llvm {
/// counts as capturing it or not. The boolean StoreCaptures specified
/// whether storing the value (or part of it) into memory anywhere
/// 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".
+ /// MaxUsesToExplore specifies how many uses the analysis should explore for
+ /// one value before giving up due too "too many uses". If MaxUsesToExplore
+ /// is zero, a default value is assumed.
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures,
bool StoreCaptures,
- unsigned MaxUsesToExplore =
- getDefaultMaxUsesToExploreForCaptureTracking());
+ unsigned MaxUsesToExplore = 0);
/// PointerMayBeCapturedBefore - Return true if this pointer value may be
/// captured by the enclosing function (which is required to exist). If a
@@ -50,13 +50,13 @@ namespace llvm {
/// (or part of it) into memory anywhere automatically counts as capturing it
/// or not. Captures by the provided instruction are considered if the
/// final parameter is true.
- /// MaxUsesToExplore specifies how many uses should the analysis explore for
- /// one value before giving up due too "too many uses".
+ /// MaxUsesToExplore specifies how many uses the analysis should explore for
+ /// one value before giving up due too "too many uses". If MaxUsesToExplore
+ /// is zero, a default value is assumed.
bool PointerMayBeCapturedBefore(
const Value *V, bool ReturnCaptures, bool StoreCaptures,
const Instruction *I, const DominatorTree *DT, bool IncludeI = false,
- unsigned MaxUsesToExplore =
- getDefaultMaxUsesToExploreForCaptureTracking());
+ unsigned MaxUsesToExplore = 0);
/// This callback is used in conjunction with PointerMayBeCaptured. In
/// addition to the interface here, you'll need to provide your own getters
@@ -89,11 +89,11 @@ namespace llvm {
/// PointerMayBeCaptured - Visit the value and the values derived from it and
/// find values which appear to be capturing the pointer value. This feeds
/// results into and is controlled by the CaptureTracker object.
- /// MaxUsesToExplore specifies how many uses should the analysis explore for
- /// one value before giving up due too "too many uses".
+ /// MaxUsesToExplore specifies how many uses the analysis should explore for
+ /// one value before giving up due too "too many uses". If MaxUsesToExplore
+ /// is zero, a default value is assumed.
void PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
- unsigned MaxUsesToExplore =
- getDefaultMaxUsesToExploreForCaptureTracking());
+ unsigned MaxUsesToExplore = 0);
} // end namespace llvm
#endif
diff --git a/llvm/lib/Analysis/CaptureTracking.cpp b/llvm/lib/Analysis/CaptureTracking.cpp
index df35ccfaea02..d7ddb7d9e0a5 100644
--- a/llvm/lib/Analysis/CaptureTracking.cpp
+++ b/llvm/lib/Analysis/CaptureTracking.cpp
@@ -230,6 +230,9 @@ bool llvm::PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
unsigned MaxUsesToExplore) {
assert(V->getType()->isPointerTy() && "Capture is for pointers only!");
+ if (MaxUsesToExplore == 0)
+ MaxUsesToExplore = DefaultMaxUsesToExplore;
+
SmallVector<const Use *, 20> Worklist;
Worklist.reserve(getDefaultMaxUsesToExploreForCaptureTracking());
SmallSet<const Use *, 20> Visited;
More information about the llvm-commits
mailing list