37 explicit SimpleCaptureTracker(
bool ReturnCaptures)
38 : ReturnCaptures(ReturnCaptures), Captured(
false) {}
40 void tooManyUses()
override { Captured =
true; }
42 bool captured(
const Use *U)
override {
43 if (isa<ReturnInst>(U->getUser()) && !ReturnCaptures)
55 struct NumberedInstCache {
61 NumberedInstCache(
const BasicBlock *BasicB) : LastInstPos(0), BB(BasicB) {
62 LastInstFound = BB->end();
69 assert(!(LastInstFound == BB->end() && LastInstPos != 0) &&
70 "Instruction supposed to be in NumberedInsts");
73 auto II = BB->begin();
75 if (LastInstFound !=
IE)
76 II = std::next(LastInstFound);
79 for (++LastInstPos; II !=
IE; ++II, ++LastInstPos) {
80 Inst = cast<Instruction>(II);
81 NumberedInsts[Inst] = LastInstPos;
82 if (Inst == A || Inst == B)
86 assert(II !=
IE &&
"Instruction not found?");
97 "Instructions must be in the same basic block!");
99 unsigned NA = NumberedInsts.lookup(A);
100 unsigned NB = NumberedInsts.lookup(B);
108 return A == find(A, B);
120 : LocalInstCache(I->
getParent()), BeforeHere(I), DT(DT),
121 ReturnCaptures(ReturnCaptures), IncludeI(IncludeI), Captured(
false) {}
123 void tooManyUses()
override { Captured =
true; }
129 if (BeforeHere != I && !DT->isReachableFromEntry(BB))
143 if (isa<InvokeInst>(BeforeHere) || isa<PHINode>(
I) || I == BeforeHere)
145 if (!LocalInstCache.dominates(BeforeHere, I))
169 if (BeforeHere != I && DT->dominates(BeforeHere, I) &&
176 bool shouldExplore(
const Use *U)
override {
179 if (BeforeHere == I && !IncludeI)
182 if (isSafeToPrune(I))
188 bool captured(
const Use *U)
override {
189 if (isa<ReturnInst>(U->getUser()) && !ReturnCaptures)
192 if (!shouldExplore(U))
199 NumberedInstCache LocalInstCache;
218 bool ReturnCaptures,
bool StoreCaptures) {
219 assert(!isa<GlobalValue>(V) &&
220 "It doesn't make sense to ask whether a global is captured.");
228 SimpleCaptureTracker SCT(ReturnCaptures);
245 assert(!isa<GlobalValue>(V) &&
246 "It doesn't make sense to ask whether a global is captured.");
254 CapturesBefore CB(ReturnCaptures, I, DT, IncludeI);
270 for (
const Use &U : V->
uses()) {
278 Worklist.push_back(&U);
281 while (!Worklist.empty()) {
282 const Use *U = Worklist.pop_back_val();
288 case Instruction::Invoke: {
314 case Instruction::VAArg:
324 case Instruction::BitCast:
325 case Instruction::GetElementPtr:
328 case Instruction::AddrSpaceCast:
337 if (Visited.
insert(&UU).second)
339 Worklist.push_back(&UU);
342 case Instruction::ICmp:
347 dyn_cast<ConstantPointerNull>(I->
getOperand(1)))
348 if (CPN->getType()->getAddressSpace() == 0)
iterator_range< use_iterator > uses()
virtual void tooManyUses()=0
tooManyUses - The depth of traversal has breached a limit.
This callback is used in conjunction with PointerMayBeCaptured.
virtual bool shouldExplore(const Use *U)
shouldExplore - This is the use of a value derived from the pointer.
const Function * getParent() const
Return the enclosing method, or null if none.
bool isNoAliasCall(const Value *V)
isNoAliasCall - Return true if this pointer is returned by a noalias function.
virtual ~CaptureTracker()
A Use represents the edge between a Value definition and its users.
bool doesNotThrow() const
Determine if the call cannot unwind.
virtual bool captured(const Use *U)=0
captured - Information about the pointer was captured by the user of use U.
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Interval::succ_iterator succ_end(Interval *I)
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
LLVM Basic Block Representation.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Value * getOperand(unsigned i) const
bool isPotentiallyReachable(const Instruction *From, const Instruction *To, const DominatorTree *DT=nullptr, const LoopInfo *LI=nullptr)
Determine whether instruction 'To' is reachable from 'From', returning true if uncertain.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, bool StoreCaptures)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
ConstantPointerNull - a constant pointer value that points to null.
const BasicBlock & getEntryBlock() const
bool doesNotCapture(unsigned ArgNo) const
Determine whether this argument is not captured.
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
LLVM Value Representation.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
static const Function * getParent(const Value *V)
bool isPotentiallyReachableFromMany(SmallVectorImpl< BasicBlock * > &Worklist, BasicBlock *StopBB, const DominatorTree *DT=nullptr, const LoopInfo *LI=nullptr)
Determine whether there is at least one path from a block in 'Worklist' to 'StopBB', returning true if uncertain.
IterTy arg_begin() const
arg_begin/arg_end - Return iterators corresponding to the actual argument list for a call site...
const BasicBlock * getParent() const
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures, bool StoreCaptures, const Instruction *I, DominatorTree *DT, bool IncludeI=false)
PointerMayBeCapturedBefore - Return true if this pointer value may be captured by the enclosing funct...