forked from OSchip/llvm-project
[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
This commit is contained in:
parent
4b80f0125a
commit
7f6a4826ac
|
@ -22,6 +22,7 @@ namespace llvm {
|
|||
class DataLayout;
|
||||
class Instruction;
|
||||
class DominatorTree;
|
||||
class LoopInfo;
|
||||
|
||||
/// getDefaultMaxUsesToExploreForCaptureTracking - Return default value of
|
||||
/// the maximal number of uses to explore before giving up. It is used by
|
||||
|
@ -55,10 +56,12 @@ namespace llvm {
|
|||
/// 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 = 0);
|
||||
bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
|
||||
bool StoreCaptures, const Instruction *I,
|
||||
const DominatorTree *DT,
|
||||
bool IncludeI = false,
|
||||
unsigned MaxUsesToExplore = 0,
|
||||
const LoopInfo *LI = nullptr);
|
||||
|
||||
/// This callback is used in conjunction with PointerMayBeCaptured. In
|
||||
/// addition to the interface here, you'll need to provide your own getters
|
||||
|
|
|
@ -98,10 +98,10 @@ namespace {
|
|||
/// as the given instruction and the use.
|
||||
struct CapturesBefore : public CaptureTracker {
|
||||
|
||||
CapturesBefore(bool ReturnCaptures, const Instruction *I, const DominatorTree *DT,
|
||||
bool IncludeI)
|
||||
: BeforeHere(I), DT(DT),
|
||||
ReturnCaptures(ReturnCaptures), IncludeI(IncludeI), Captured(false) {}
|
||||
CapturesBefore(bool ReturnCaptures, const Instruction *I,
|
||||
const DominatorTree *DT, bool IncludeI, const LoopInfo *LI)
|
||||
: BeforeHere(I), DT(DT), ReturnCaptures(ReturnCaptures),
|
||||
IncludeI(IncludeI), Captured(false), LI(LI) {}
|
||||
|
||||
void tooManyUses() override { Captured = true; }
|
||||
|
||||
|
@ -115,7 +115,7 @@ namespace {
|
|||
return true;
|
||||
|
||||
// Check whether there is a path from I to BeforeHere.
|
||||
return !isPotentiallyReachable(I, BeforeHere, nullptr, DT);
|
||||
return !isPotentiallyReachable(I, BeforeHere, nullptr, DT, LI);
|
||||
}
|
||||
|
||||
bool captured(const Use *U) override {
|
||||
|
@ -140,6 +140,8 @@ namespace {
|
|||
bool IncludeI;
|
||||
|
||||
bool Captured;
|
||||
|
||||
const LoopInfo *LI;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -183,7 +185,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,
|
||||
unsigned MaxUsesToExplore) {
|
||||
unsigned MaxUsesToExplore,
|
||||
const LoopInfo *LI) {
|
||||
assert(!isa<GlobalValue>(V) &&
|
||||
"It doesn't make sense to ask whether a global is captured.");
|
||||
|
||||
|
@ -194,7 +197,7 @@ bool llvm::PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures,
|
|||
// TODO: See comment in PointerMayBeCaptured regarding what could be done
|
||||
// with StoreCaptures.
|
||||
|
||||
CapturesBefore CB(ReturnCaptures, I, DT, IncludeI);
|
||||
CapturesBefore CB(ReturnCaptures, I, DT, IncludeI, LI);
|
||||
PointerMayBeCaptured(V, &CB, MaxUsesToExplore);
|
||||
if (CB.Captured)
|
||||
++NumCapturedBefore;
|
||||
|
|
Loading…
Reference in New Issue