45 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(O))
46 if (
GEP->isInBounds())
54 explicit SimpleCaptureTracker(
bool ReturnCaptures)
55 : ReturnCaptures(ReturnCaptures), Captured(
false) {}
60 if (isa<ReturnInst>(U->getUser()) && !ReturnCaptures)
80 : OrderedBB(IC), BeforeHere(I), DT(DT),
81 ReturnCaptures(ReturnCaptures), IncludeI(IncludeI), Captured(
false) {}
103 if (isa<InvokeInst>(BeforeHere) || isa<PHINode>(
I) || I == BeforeHere)
105 if (!OrderedBB->dominates(BeforeHere, I))
126 if (BeforeHere != I && DT->
dominates(BeforeHere, I) &&
136 if (BeforeHere == I && !IncludeI)
139 if (isSafeToPrune(I))
146 if (isa<ReturnInst>(U->getUser()) && !ReturnCaptures)
175 bool ReturnCaptures,
bool StoreCaptures,
176 unsigned MaxUsesToExplore) {
177 assert(!isa<GlobalValue>(V) &&
178 "It doesn't make sense to ask whether a global is captured.");
186 SimpleCaptureTracker SCT(ReturnCaptures);
205 unsigned MaxUsesToExplore) {
206 assert(!isa<GlobalValue>(V) &&
207 "It doesn't make sense to ask whether a global is captured.");
208 bool UseNewOBB = OBB ==
nullptr;
219 CapturesBefore CB(ReturnCaptures, I, DT, IncludeI, OBB);
228 unsigned MaxUsesToExplore) {
233 auto AddUses = [&](
const Value *V) {
235 for (
const Use &U : V->
uses()) {
238 if (Count++ >= MaxUsesToExplore)
240 if (!Visited.
insert(&U).second)
244 Worklist.push_back(&U);
249 while (!Worklist.empty()) {
250 const Use *U = Worklist.pop_back_val();
256 case Instruction::Invoke: {
257 auto *Call = cast<CallBase>(
I);
261 if (Call->onlyReadsMemory() && Call->doesNotThrow() &&
262 Call->getType()->isVoidTy())
278 if (
auto *
MI = dyn_cast<MemIntrinsic>(Call))
279 if (
MI->isVolatile())
290 for (
auto IdxOpPair :
enumerate(Call->data_ops())) {
291 int Idx = IdxOpPair.index();
292 Value *A = IdxOpPair.value();
293 if (A == V && !Call->doesNotCapture(Idx))
302 if (cast<LoadInst>(I)->isVolatile())
306 case Instruction::VAArg:
316 case Instruction::AtomicRMW: {
322 auto *ARMWI = cast<AtomicRMWInst>(
I);
323 if (ARMWI->getValOperand() == V || ARMWI->isVolatile())
328 case Instruction::AtomicCmpXchg: {
334 auto *ACXI = cast<AtomicCmpXchgInst>(
I);
335 if (ACXI->getCompareOperand() == V || ACXI->getNewValOperand() == V ||
341 case Instruction::BitCast:
342 case Instruction::GetElementPtr:
343 case Instruction::PHI:
345 case Instruction::AddrSpaceCast:
349 case Instruction::ICmp: {
350 unsigned Idx = (I->
getOperand(0) == V) ? 0 : 1;
351 unsigned OtherIdx = 1 - Idx;
352 if (
auto *CPN = dyn_cast<ConstantPointerNull>(I->
getOperand(OtherIdx))) {
356 if (CPN->getType()->getAddressSpace() == 0)
372 if (LI && isa<GlobalVariable>(LI->getPointerOperand()))
A parsed version of the target data layout string in and methods for querying it. ...
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 isPotentiallyReachable(const Instruction *From, const Instruction *To, const SmallPtrSetImpl< BasicBlock *> *ExclusionSet=nullptr, const DominatorTree *DT=nullptr, const LoopInfo *LI=nullptr)
Determine whether instruction 'To' is reachable from 'From', without passing through any blocks in Ex...
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()
bool isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(const CallBase *Call, bool MustPreserveNullness)
{launder,strip}.invariant.group returns pointer that aliases its argument, and it only captures point...
virtual bool isDereferenceableOrNull(Value *O, const DataLayout &DL)
isDereferenceableOrNull - Overload to allow clients with additional knowledge about pointer dereferen...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
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.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
const Function * getFunction() const
Return the function this instruction belongs to.
const Value * stripPointerCastsSameRepresentation() const
Strip off pointer casts, all-zero GEPs and address space casts but ensures the representation of the ...
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.
uint64_t getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull) const
Returns the number of bytes known to be dereferenceable for the pointer value.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
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 nullPointerIsDefined() const
Check if null pointer dereferencing is considered undefined behavior for the function.
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...