Skip to content

Commit 6881ec7

Browse files
committed
[CaptureTracking] Allow passing LI to PointerMayBeCapturedBefore (NFC).
isPotentiallyReachable can use LoopInfo to return earlier. This patch allows passing an optional LI to PointerMayBeCapturedBefore. Used in D109844. Reviewed By: nikic, asbirlea Differential Revision: https://reviews.llvm.org/D109978 (cherry-picked from 7f6a482)
1 parent c829ca3 commit 6881ec7

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

llvm/include/llvm/Analysis/CaptureTracking.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace llvm {
2222
class DataLayout;
2323
class Instruction;
2424
class DominatorTree;
25+
class LoopInfo;
2526

2627
/// getDefaultMaxUsesToExploreForCaptureTracking - Return default value of
2728
/// the maximal number of uses to explore before giving up. It is used by
@@ -55,10 +56,12 @@ namespace llvm {
5556
/// MaxUsesToExplore specifies how many uses the analysis should explore for
5657
/// one value before giving up due too "too many uses". If MaxUsesToExplore
5758
/// is zero, a default value is assumed.
58-
bool PointerMayBeCapturedBefore(
59-
const Value *V, bool ReturnCaptures, bool StoreCaptures,
60-
const Instruction *I, const DominatorTree *DT, bool IncludeI = false,
61-
unsigned MaxUsesToExplore = 0);
59+
bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
60+
bool StoreCaptures, const Instruction *I,
61+
const DominatorTree *DT,
62+
bool IncludeI = false,
63+
unsigned MaxUsesToExplore = 0,
64+
const LoopInfo *LI = nullptr);
6265

6366
/// This callback is used in conjunction with PointerMayBeCaptured. In
6467
/// addition to the interface here, you'll need to provide your own getters

llvm/lib/Analysis/CaptureTracking.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ namespace {
9898
/// as the given instruction and the use.
9999
struct CapturesBefore : public CaptureTracker {
100100

101-
CapturesBefore(bool ReturnCaptures, const Instruction *I, const DominatorTree *DT,
102-
bool IncludeI)
103-
: BeforeHere(I), DT(DT),
104-
ReturnCaptures(ReturnCaptures), IncludeI(IncludeI), Captured(false) {}
101+
CapturesBefore(bool ReturnCaptures, const Instruction *I,
102+
const DominatorTree *DT, bool IncludeI, const LoopInfo *LI)
103+
: BeforeHere(I), DT(DT), ReturnCaptures(ReturnCaptures),
104+
IncludeI(IncludeI), Captured(false), LI(LI) {}
105105

106106
void tooManyUses() override { Captured = true; }
107107

@@ -115,7 +115,7 @@ namespace {
115115
return true;
116116

117117
// Check whether there is a path from I to BeforeHere.
118-
return !isPotentiallyReachable(I, BeforeHere, nullptr, DT);
118+
return !isPotentiallyReachable(I, BeforeHere, nullptr, DT, LI);
119119
}
120120

121121
bool captured(const Use *U) override {
@@ -140,6 +140,8 @@ namespace {
140140
bool IncludeI;
141141

142142
bool Captured;
143+
144+
const LoopInfo *LI;
143145
};
144146
}
145147

@@ -183,7 +185,8 @@ bool llvm::PointerMayBeCaptured(const Value *V,
183185
bool llvm::PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
184186
bool StoreCaptures, const Instruction *I,
185187
const DominatorTree *DT, bool IncludeI,
186-
unsigned MaxUsesToExplore) {
188+
unsigned MaxUsesToExplore,
189+
const LoopInfo *LI) {
187190
assert(!isa<GlobalValue>(V) &&
188191
"It doesn't make sense to ask whether a global is captured.");
189192

@@ -194,7 +197,7 @@ bool llvm::PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
194197
// TODO: See comment in PointerMayBeCaptured regarding what could be done
195198
// with StoreCaptures.
196199

197-
CapturesBefore CB(ReturnCaptures, I, DT, IncludeI);
200+
CapturesBefore CB(ReturnCaptures, I, DT, IncludeI, LI);
198201
PointerMayBeCaptured(V, &CB, MaxUsesToExplore);
199202
if (CB.Captured)
200203
++NumCapturedBefore;

0 commit comments

Comments
 (0)