aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/CaptureTracking.cpp
diff options
context:
space:
mode:
authorArtur Pilipenko <apilipenko@azulsystems.com>2018-11-29 20:08:12 +0000
committerArtur Pilipenko <apilipenko@azulsystems.com>2018-11-29 20:08:12 +0000
commiteba2365f23db0cae29e9a187ec16bb64e49be5d6 (patch)
tree6550e834d54e03fc777769d0c3a02e15d642c38c /llvm/lib/Analysis/CaptureTracking.cpp
parent0f90191faa95fe5d63b34e19b2051fbaf00c76a7 (diff)
downloadllvm-eba2365f23db0cae29e9a187ec16bb64e49be5d6.zip
llvm-eba2365f23db0cae29e9a187ec16bb64e49be5d6.tar.gz
llvm-eba2365f23db0cae29e9a187ec16bb64e49be5d6.tar.bz2
Introduce MaxUsesToExplore argument to capture tracking
Currently CaptureTracker gives up if it encounters a value with more than 20 uses. The motivation for this cap is to keep it relatively cheap for BasicAliasAnalysis use case, where the results can't be cached. Although, other clients of CaptureTracker might be ok with higher cost. This patch introduces an argument for PointerMayBeCaptured functions to specify the max number of uses to explore. The motivation for this change is a downstream user of CaptureTracker, but I believe upstream clients of CaptureTracker might also benefit from more fine grained cap. Reviewed By: hfinkel Differential Revision: https://reviews.llvm.org/D55042 llvm-svn: 347910
Diffstat (limited to 'llvm/lib/Analysis/CaptureTracking.cpp')
-rw-r--r--llvm/lib/Analysis/CaptureTracking.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/llvm/lib/Analysis/CaptureTracking.cpp b/llvm/lib/Analysis/CaptureTracking.cpp
index 2596789..7c74c65 100644
--- a/llvm/lib/Analysis/CaptureTracking.cpp
+++ b/llvm/lib/Analysis/CaptureTracking.cpp
@@ -158,7 +158,8 @@ namespace {
/// storing the value (or part of it) into memory anywhere automatically
/// counts as capturing it or not.
bool llvm::PointerMayBeCaptured(const Value *V,
- bool ReturnCaptures, bool StoreCaptures) {
+ bool ReturnCaptures, bool StoreCaptures,
+ unsigned MaxUsesToExplore) {
assert(!isa<GlobalValue>(V) &&
"It doesn't make sense to ask whether a global is captured.");
@@ -186,7 +187,8 @@ bool llvm::PointerMayBeCaptured(const Value *V,
bool llvm::PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
bool StoreCaptures, const Instruction *I,
const DominatorTree *DT, bool IncludeI,
- OrderedBasicBlock *OBB) {
+ OrderedBasicBlock *OBB,
+ unsigned MaxUsesToExplore) {
assert(!isa<GlobalValue>(V) &&
"It doesn't make sense to ask whether a global is captured.");
bool UseNewOBB = OBB == nullptr;
@@ -207,22 +209,18 @@ bool llvm::PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
return CB.Captured;
}
-/// TODO: Write a new FunctionPass AliasAnalysis so that it can keep
-/// a cache. Then we can move the code from BasicAliasAnalysis into
-/// that path, and remove this threshold.
-static unsigned const Threshold = 20;
-
-void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker) {
+void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
+ unsigned MaxUsesToExplore) {
assert(V->getType()->isPointerTy() && "Capture is for pointers only!");
- SmallVector<const Use *, Threshold> Worklist;
- SmallSet<const Use *, Threshold> Visited;
+ SmallVector<const Use *, DefaultMaxUsesToExplore> Worklist;
+ SmallSet<const Use *, DefaultMaxUsesToExplore> Visited;
auto AddUses = [&](const Value *V) {
unsigned Count = 0;
for (const Use &U : V->uses()) {
// If there are lots of uses, conservatively say that the value
// is captured to avoid taking too much compile time.
- if (Count++ >= Threshold)
+ if (Count++ >= MaxUsesToExplore)
return Tracker->tooManyUses();
if (!Visited.insert(&U).second)
continue;