39 explicit SimpleCaptureTracker(
bool ReturnCaptures)
40 : ReturnCaptures(ReturnCaptures), Captured(
false) {}
45 if (isa<ReturnInst>(U->getUser()) && !ReturnCaptures)
65 : OrderedBB(IC), BeforeHere(I), DT(DT),
66 ReturnCaptures(ReturnCaptures), IncludeI(IncludeI), Captured(
false) {}
88 if (isa<InvokeInst>(BeforeHere) || isa<PHINode>(
I) || I == BeforeHere)
90 if (!OrderedBB->dominates(BeforeHere, I))
111 if (BeforeHere != I && DT->
dominates(BeforeHere, I) &&
121 if (BeforeHere == I && !IncludeI)
124 if (isSafeToPrune(I))
131 if (isa<ReturnInst>(U->getUser()) && !ReturnCaptures)
160 bool ReturnCaptures,
bool StoreCaptures,
161 unsigned MaxUsesToExplore) {
162 assert(!isa<GlobalValue>(V) &&
163 "It doesn't make sense to ask whether a global is captured.");
171 SimpleCaptureTracker SCT(ReturnCaptures);
190 unsigned MaxUsesToExplore) {
191 assert(!isa<GlobalValue>(V) &&
192 "It doesn't make sense to ask whether a global is captured.");
193 bool UseNewOBB = OBB ==
nullptr;
204 CapturesBefore CB(ReturnCaptures, I, DT, IncludeI, OBB);
213 unsigned MaxUsesToExplore) {
218 auto AddUses = [&](
const Value *V) {
220 for (
const Use &U : V->
uses()) {
223 if (Count++ >= MaxUsesToExplore)
225 if (!Visited.
insert(&U).second)
229 Worklist.push_back(&U);
234 while (!Worklist.empty()) {
235 const Use *U = Worklist.pop_back_val();
241 case Instruction::Invoke: {
242 auto *Call = cast<CallBase>(
I);
246 if (Call->onlyReadsMemory() && Call->doesNotThrow() &&
247 Call->getType()->isVoidTy())
262 if (
auto *
MI = dyn_cast<MemIntrinsic>(Call))
263 if (
MI->isVolatile())
274 for (
auto IdxOpPair :
enumerate(Call->data_ops())) {
275 int Idx = IdxOpPair.index();
276 Value *A = IdxOpPair.value();
277 if (A == V && !Call->doesNotCapture(Idx))
286 if (cast<LoadInst>(I)->isVolatile())
290 case Instruction::VAArg:
300 case Instruction::AtomicRMW: {
306 auto *ARMWI = cast<AtomicRMWInst>(
I);
307 if (ARMWI->getValOperand() == V || ARMWI->isVolatile())
312 case Instruction::AtomicCmpXchg: {
318 auto *ACXI = cast<AtomicCmpXchgInst>(
I);
319 if (ACXI->getCompareOperand() == V || ACXI->getNewValOperand() == V ||
325 case Instruction::BitCast:
326 case Instruction::GetElementPtr:
327 case Instruction::PHI:
329 case Instruction::AddrSpaceCast:
333 case Instruction::ICmp: {
338 dyn_cast<ConstantPointerNull>(I->
getOperand(1)))
339 if (CPN->getType()->getAddressSpace() == 0)
345 unsigned OtherIndex = (I->
getOperand(0) == V) ? 1 : 0;
347 if (LI && isa<GlobalVariable>(LI->getPointerOperand()))
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.
This class represents lattice values for constants.
bool isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(const CallBase *Call)
virtual bool shouldExplore(const Use *U)
shouldExplore - This is the use of a value derived from the pointer.
bool isNoAliasCall(const Value *V)
Return true if this pointer is returned by a noalias function.
An instruction for reading from memory.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
virtual ~CaptureTracker()
A Use represents the edge between a Value definition and its users.
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...
Type * getType() const
All values are typed, get the type of this value.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures, bool StoreCaptures, const Instruction *I, const DominatorTree *DT, bool IncludeI=false, OrderedBasicBlock *OBB=nullptr, unsigned MaxUsesToExplore=DefaultMaxUsesToExplore)
PointerMayBeCapturedBefore - Return true if this pointer value may be captured by the enclosing funct...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
Value * getOperand(unsigned i) const
Interval::succ_iterator succ_end(Interval *I)
const BasicBlock & getEntryBlock() const
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...
bool isPointerTy() const
True if this is an instance of PointerType.
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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
A constant pointer value that points to null.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
static bool isVolatile(Instruction *Inst)
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.
detail::enumerator< R > enumerate(R &&TheRange)
Given an input range, returns a new range whose values are are pair (A,B) such that A is the 0-based ...
const BasicBlock * getParent() const
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, bool StoreCaptures, unsigned MaxUsesToExplore=DefaultMaxUsesToExplore)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...