17 using namespace llvm::objcarc;
19 #define DEBUG_TYPE "objc-arc-ptr-state"
28 return OS <<
"S_None";
30 return OS <<
"S_Retain";
32 return OS <<
"S_CanRelease";
36 return OS <<
"S_Release";
38 return OS <<
"S_MovableRelease";
40 return OS <<
"S_Stop";
117 DEBUG(
dbgs() <<
" Setting Known Positive.\n");
122 DEBUG(
dbgs() <<
" Clearing Known Positive.\n");
132 DEBUG(
dbgs() <<
" Resetting sequence progress.\n");
173 bool NestingDetected =
false;
175 DEBUG(
dbgs() <<
" Found nested releases (i.e. a release pair)\n");
176 NestingDetected =
true;
188 return NestingDetected;
225 DEBUG(
dbgs() <<
" CanAlterRefCount: Seq: " << S <<
"; " << *Ptr
247 auto SetSeqAndInsertReverseInsertPt = [&](
Sequence NewSeq){
253 if (isa<InvokeInst>(Inst))
263 if (
CanUse(Inst, Ptr, PA, Class)) {
266 SetSeqAndInsertReverseInsertPt(
S_Use);
271 SetSeqAndInsertReverseInsertPt(
S_Stop);
276 SetSeqAndInsertReverseInsertPt(
S_Stop);
281 if (
CanUse(Inst, Ptr, PA, Class)) {
301 bool NestingDetected =
false;
314 NestingDetected =
true;
322 return NestingDetected;
337 if (OldSeq ==
S_Retain || ReleaseMetadata !=
nullptr)
395 if (!
CanUse(Inst, Ptr, PA, Class))
bool Merge(const RRInfo &Other)
Conservatively merge the two RRInfo.
This file declares special dependency analysis routines used in Objective C ARC Optimizations.
bool IsUser(ARCInstKind Class)
Test if the given class is a kind of user.
SmallPtrSet< Instruction *, 2 > Calls
For a top-down sequence, the set of objc_retains or objc_retainBlocks.
void ClearReverseInsertPts()
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 ...
bool HandlePotentialAlterRefCount(Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)
bool MatchWithRelease(ARCMDKindCache &Cache, Instruction *Release)
Return true if this set of retains can be paired with the given release.
void SetKnownSafe(const bool NewValue)
bool HasReverseInsertPts() const
SmallPtrSet< Instruction *, 2 > ReverseInsertPts
The set of optimal insert positions for moving calls in the opposite sequence.
unsigned char Seq
The current position in the sequence.
void InsertReverseInsertPt(Instruction *I)
void InsertCall(Instruction *I)
This class summarizes several per-pointer runtime properties which are propagated through the flow gr...
unsigned get(ARCMDKindID ID)
bool IsTailCallRelease
True of the objc_release calls are all marked with the "tail" keyword.
bool InitBottomUp(ARCMDKindCache &Cache, Instruction *I)
(Re-)Initialize this bottom up pointer returning true if we detected a pointer with nested releases...
objc_retainAutoreleasedReturnValue
void ClearKnownPositiveRefCount()
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...
raw_ostream & operator<<(raw_ostream &OS, const ARCInstKind Class)
void HandlePotentialUse(Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)
RRInfo RRI
Unidirectional information about the current sequence.
LLVM Basic Block Representation.
bool KnownPositiveRefCount
True if the reference count is known to be incremented.
void Merge(const PtrState &Other, bool TopDown)
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
like S_Release, but code motion is stopped.
self_iterator getIterator()
A cache of MDKinds used by various ARC optimizations.
bool MatchWithRetain()
Return true if this set of releases can be paired with a release.
void ResetSequenceProgress(Sequence NewSeq)
bool CFGHazardAfflicted
If this is true, we cannot perform code motion but can still remove retain/release pairs...
ARCInstKind GetBasicARCInstKind(const Value *V)
Determine which objc runtime call instruction class V belongs to.
objc_release(x), !clang.imprecise_release.
void SetReleaseMetadata(MDNode *NewValue)
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.
bool Partial
True if we've seen an opportunity for partial RR elimination, such as pushing calls into a CFG triang...
ARCInstKind
Equivalence classes of instructions in the ARC Model.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
bool HandlePotentialAlterRefCount(Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)
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.
MDNode * ReleaseMetadata
If the Calls are objc_release calls and they all have a clang.imprecise_release tag, this is the metadata tag.
void SetTailCallRelease(const bool NewValue)
llvm_unreachable("Unknown RegBank!")
void ClearSequenceProgress()
static Sequence MergeSeqs(Sequence A, Sequence B, bool TopDown)
Sequence
A sequence of states that a pointer may go through in which an objc_retain and objc_release are actua...
void SetKnownPositiveRefCount()
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...
void SetSeq(Sequence NewSeq)
bool IsTrackingImpreciseReleases() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
foo(x) – x could possibly see a ref count decrement.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
bool KnownSafe
After an objc_retain, the reference count of the referenced object is known to be positive...
This class implements an extremely fast bulk output stream that can only output to a stream...
This is similar to BasicAliasAnalysis, and it uses many of the same techniques, except it uses specia...
bool InitTopDown(ARCInstKind Kind, Instruction *I)
(Re-)Initialize this bottom up pointer returning true if we detected a pointer with nested releases...
bool HasKnownPositiveRefCount() const