diff --git a/llvm/include/llvm/Analysis/CaptureTracking.h b/llvm/include/llvm/Analysis/CaptureTracking.h --- a/llvm/include/llvm/Analysis/CaptureTracking.h +++ b/llvm/include/llvm/Analysis/CaptureTracking.h @@ -22,6 +22,7 @@ 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 @@ /// 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 diff --git a/llvm/lib/Analysis/CaptureTracking.cpp b/llvm/lib/Analysis/CaptureTracking.cpp --- a/llvm/lib/Analysis/CaptureTracking.cpp +++ b/llvm/lib/Analysis/CaptureTracking.cpp @@ -98,10 +98,10 @@ /// 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 @@ 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 @@ bool IncludeI; bool Captured; + + const LoopInfo *LI; }; } @@ -183,7 +185,8 @@ 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(V) && "It doesn't make sense to ask whether a global is captured."); @@ -194,7 +197,7 @@ // 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;