31#define DEBUG_TYPE "objc-arc-dependency"
39 case ARCInstKind::Autorelease:
40 case ARCInstKind::AutoreleaseRV:
41 case ARCInstKind::IntrinsicUser:
42 case ARCInstKind::User:
48 const auto *
Call = cast<CallBase>(Inst);
84 if (Class == ARCInstKind::Call)
89 if (
const ICmpInst *ICI = dyn_cast<ICmpInst>(Inst)) {
95 }
else if (
const auto *CS = dyn_cast<CallBase>(Inst)) {
97 for (
const Value *
Op : CS->args())
101 }
else if (
const StoreInst *SI = dyn_cast<StoreInst>(Inst)) {
132 case ARCInstKind::AutoreleasepoolPop:
133 case ARCInstKind::AutoreleasepoolPush:
134 case ARCInstKind::None:
137 return CanUse(Inst, Arg, PA, Class);
144 case ARCInstKind::AutoreleasepoolPop:
145 case ARCInstKind::AutoreleasepoolPush:
157 case ARCInstKind::AutoreleasepoolPop:
160 case ARCInstKind::AutoreleasepoolPush:
161 case ARCInstKind::None:
170 case ARCInstKind::AutoreleasepoolPop:
171 case ARCInstKind::AutoreleasepoolPush:
175 case ARCInstKind::Retain:
176 case ARCInstKind::RetainRV:
187 case ARCInstKind::Retain:
188 case ARCInstKind::RetainRV:
214 Worklist.
push_back(std::make_pair(StartBB, StartPos));
216 std::pair<BasicBlock *, BasicBlock::iterator> Pair =
222 if (LocalStartPos == StartBBBegin) {
228 if (Visited.
insert(PredBB).second)
229 Worklist.
push_back(std::make_pair(PredBB, PredBB->end()));
234 if (
Depends(Flavor, Inst, Arg, PA)) {
235 DependingInsts.
insert(Inst);
239 }
while (!Worklist.
empty());
248 if (Succ != StartBB && !Visited.
count(Succ))
262 if (!
findDependencies(Flavor, Arg, StartBB, StartInst, DependingInsts, PA) ||
263 DependingInsts.
size() != 1)
265 return *DependingInsts.
begin();
static bool findDependencies(DependenceKind Flavor, const Value *Arg, BasicBlock *StartBB, Instruction *StartInst, SmallPtrSetImpl< Instruction * > &DependingInsts, ProvenanceAnalysis &PA)
Walk up the CFG from StartPos (which is in StartBB) and find local and non-local dependencies on Arg.
This file declares special dependency analysis routines used in Objective C ARC Optimizations.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This file declares a special form of Alias Analysis called Provenance Analysis''.
MemoryEffects getMemoryEffects(const CallBase *Call)
Return the behavior of the given call site.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
InstListType::iterator iterator
Instruction iterators...
This class represents an Operation in the Expression.
This instruction compares its operands according to the predicate given to the constructor.
bool onlyAccessesArgPointees() const
Whether this function only (at most) accesses argument memory.
bool onlyReadsMemory() const
Whether this function only (at most) reads memory.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
self_iterator getIterator()
This is similar to BasicAliasAnalysis, and it uses many of the same techniques, except it uses specia...
bool related(const Value *A, const Value *B)
AAResults * getAA() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool IsPotentialRetainableObjPtr(const Value *Op)
Test whether the given value is possible a retainable object pointer.
bool CanAlterRefCount(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)
Test whether the given instruction can result in a reference count modification (positive or negative...
DependenceKind
Defines different dependence kinds among various ARC constructs.
@ RetainAutoreleaseDep
Blocks objc_retainAutorelease.
@ AutoreleasePoolBoundary
@ NeedsPositiveRetainCount
@ RetainAutoreleaseRVDep
Blocks objc_retainAutoreleaseReturnValue.
ARCInstKind
Equivalence classes of instructions in the ARC Model.
@ Call
could call objc_release
llvm::Instruction * findSingleDependency(DependenceKind Flavor, const Value *Arg, BasicBlock *StartBB, Instruction *StartInst, ProvenanceAnalysis &PA)
Find dependent instructions.
ARCInstKind GetBasicARCInstKind(const Value *V)
Determine which objc runtime call instruction class V belongs to.
ARCInstKind GetARCInstKind(const Value *V)
Map V to its ARCInstKind equivalence class.
bool Depends(DependenceKind Flavor, Instruction *Inst, const Value *Arg, ProvenanceAnalysis &PA)
Test if there can be dependencies on Inst through Arg.
bool CanInterruptRV(ARCInstKind Class)
Test whether the given instruction can autorelease any pointer or cause an autoreleasepool pop.
Value * GetArgRCIdentityRoot(Value *Inst)
Assuming the given instruction is one of the special calls such as objc_retain or objc_release,...
bool CanDecrementRefCount(ARCInstKind Kind)
Returns false if conservatively we can prove that any instruction mapped to this kind can not decreme...
const Value * GetUnderlyingObjCPtr(const Value *V)
This is a wrapper around getUnderlyingObject which also knows how to look through objc_retain and obj...
bool CanUse(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)
Test whether the given instruction can "use" the given pointer's object in a way that requires the re...
This is an optimization pass for GlobalISel generic memory operations.
auto successors(const MachineBasicBlock *BB)
auto predecessors(const MachineBasicBlock *BB)
bool pred_empty(const BasicBlock *BB)