31#define DEBUG_TYPE "objc-arc-ptr-state"
40 return OS <<
"S_None";
42 return OS <<
"S_Retain";
44 return OS <<
"S_CanRelease";
48 return OS <<
"S_MovableRelease";
50 return OS <<
"S_Stop";
182 bool NestingDetected =
false;
185 dbgs() <<
" Found nested releases (i.e. a release pair)\n");
186 NestingDetected =
true;
200 return NestingDetected;
257 auto SetSeqAndInsertReverseInsertPt = [&](
Sequence NewSeq){
264 if (isa<InvokeInst>(Inst)) {
266 InsertAfter = IP == BB->
end() ? std::prev(BB->
end()) : IP;
267 if (isa<CatchSwitchInst>(InsertAfter))
276 if (InsertAfter != BB->
end())
284 if (
auto *CB = dyn_cast<CallBase>(Inst))
295 SetSeqAndInsertReverseInsertPt(
S_Use);
300 SetSeqAndInsertReverseInsertPt(
S_Stop);
307 <<
"; " << *
Ptr <<
"\n");
325 bool NestingDetected =
false;
338 NestingDetected =
true;
346 return NestingDetected;
361 if (OldSeq ==
S_Retain || ReleaseMetadata !=
nullptr)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file declares special dependency analysis routines used in Objective C ARC Optimizations.
This file defines common analysis utilities used by the ObjC ARC Optimizer.
This file defines ARC utility functions which are used by various parts of the compiler.
static Sequence MergeSeqs(Sequence A, Sequence B, bool TopDown)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Basic Block Representation.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
InstListType::iterator iterator
Instruction iterators...
LLVM Value Representation.
self_iterator getIterator()
A cache of MDKinds used by various ARC optimizations.
unsigned get(ARCMDKindID ID)
bool contains(const Instruction *I) const
See if an instruction is a bundled retainRV/claimRV call.
This is similar to BasicAliasAnalysis, and it uses many of the same techniques, except it uses specia...
This class summarizes several per-pointer runtime properties which are propagated through the flow gr...
bool KnownPositiveRefCount
True if the reference count is known to be incremented.
unsigned char Seq
The current position in the sequence.
void SetCFGHazardAfflicted(const bool NewValue)
RRInfo RRI
Unidirectional information about the current sequence.
void ClearReverseInsertPts()
void SetKnownPositiveRefCount()
bool HasKnownPositiveRefCount() const
void InsertReverseInsertPt(Instruction *I)
bool HasReverseInsertPts() const
void SetTailCallRelease(const bool NewValue)
void ClearKnownPositiveRefCount()
void SetReleaseMetadata(MDNode *NewValue)
void InsertCall(Instruction *I)
void ResetSequenceProgress(Sequence NewSeq)
void SetSeq(Sequence NewSeq)
void SetKnownSafe(const bool NewValue)
void Merge(const PtrState &Other, bool TopDown)
void ClearSequenceProgress()
bool Partial
True if we've seen an opportunity for partial RR elimination, such as pushing calls into a CFG triang...
bool IsTrackingImpreciseReleases() const
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static const Instruction * getreturnRVOperand(const Instruction &Inst, ARCInstKind Class)
If Inst is a ReturnRV and its operand is a call or invoke, return the operand.
raw_ostream & operator<<(raw_ostream &OS, const ARCInstKind Class)
ARCInstKind
Equivalence classes of instructions in the ARC Model.
@ RetainRV
objc_retainAutoreleasedReturnValue
@ Call
could call objc_release
@ IntrinsicUser
llvm.objc.clang.arc.use
Sequence
A sequence of states that a pointer may go through in which an objc_retain and objc_release are actua...
@ S_CanRelease
foo(x) – x could possibly see a ref count decrement.
@ S_Retain
objc_retain(x).
@ S_Stop
code motion is stopped.
@ S_MovableRelease
objc_release(x), !clang.imprecise_release.
ARCInstKind GetBasicARCInstKind(const Value *V)
Determine which objc runtime call instruction class V belongs to.
bool CanDecrementRefCount(ARCInstKind Kind)
Returns false if conservatively we can prove that any instruction mapped to this kind can not decreme...
bool hasAttachedCallOpBundle(const CallBase *CB)
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.
BasicBlock::iterator skipDebugIntrinsics(BasicBlock::iterator It)
Advance It while it points to a debug instruction and return the result.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
bool HandlePotentialAlterRefCount(Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)
bool InitBottomUp(ARCMDKindCache &Cache, Instruction *I)
(Re-)Initialize this bottom up pointer returning true if we detected a pointer with nested releases.
bool MatchWithRetain()
Return true if this set of releases can be paired with a release.
void HandlePotentialUse(BasicBlock *BB, Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)
Unidirectional information about either a retain-decrement-use-release sequence or release-use-decrem...
bool Merge(const RRInfo &Other)
Conservatively merge the two RRInfo.
bool KnownSafe
After an objc_retain, the reference count of the referenced object is known to be positive.
SmallPtrSet< Instruction *, 2 > Calls
For a top-down sequence, the set of objc_retains or objc_retainBlocks.
MDNode * ReleaseMetadata
If the Calls are objc_release calls and they all have a clang.imprecise_release tag,...
bool CFGHazardAfflicted
If this is true, we cannot perform code motion but can still remove retain/release pairs.
bool IsTailCallRelease
True of the objc_release calls are all marked with the "tail" keyword.
SmallPtrSet< Instruction *, 2 > ReverseInsertPts
The set of optimal insert positions for moving calls in the opposite sequence.
bool MatchWithRelease(ARCMDKindCache &Cache, Instruction *Release)
Return true if this set of retains can be paired with the given release.
bool InitTopDown(ARCInstKind Kind, Instruction *I)
(Re-)Initialize this bottom up pointer returning true if we detected a pointer with nested releases.
bool HandlePotentialAlterRefCount(Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class, const BundledRetainClaimRVs &BundledRVs)
void HandlePotentialUse(Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)