LLVM: lib/Transforms/ObjCARC/PtrState.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
24#include
25#include
26#include
27
28using namespace llvm;
30
31#define DEBUG_TYPE "objc-arc-ptr-state"
32
33
34
35
36
38 switch (S) {
40 return OS << "S_None";
42 return OS << "S_Retain";
44 return OS << "S_CanRelease";
46 return OS << "S_Use";
48 return OS << "S_MovableRelease";
50 return OS << "S_Stop";
51 }
53}
54
55
56
57
58
60
62 return A;
65
68 if (TopDown) {
69
72 return B;
73 } else {
74
77 return A;
78
80 return A;
81 }
82
84}
85
86
87
88
89
98
100
103
104
108
109
111
112
113
117 return Partial;
118}
119
120
121
122
123
128
133
136 << "\n");
137 Seq = NewSeq;
138}
139
146
150
151
154 RRI.clear();
156
157
158
159
161 } else {
162
163
164
165
167 }
168}
169
170
171
172
173
175
176
177
178
179
180
181
182 bool NestingDetected = false;
185 dbgs() << " Found nested releases (i.e. a release pair)\n");
186 NestingDetected = true;
187 }
188
189 MDNode *ReleaseMetadata =
193 if (NewSeq == S_Stop)
200 return NestingDetected;
201}
202
205
207 switch (OldSeq) {
211
212
215 [[fallthrough]];
217 return true;
219 return false;
222 }
224}
225
227 const Value *Ptr,
231
232
234 return false;
235
236 LLVM_DEBUG(dbgs() << " CanAlterRefCount: Seq: " << S << "; "
237 << *Ptr << "\n");
238 switch (S) {
241 return true;
246 return false;
249 }
251}
252
254 const Value *Ptr,
257 auto SetSeqAndInsertReverseInsertPt = [&](Sequence NewSeq){
260
261
262
266 InsertAfter = IP == BB->end() ? std::prev(BB->end()) : IP;
268
269
270
272 } else {
273 InsertAfter = std::next(Inst->getIterator());
274 }
275
276 if (InsertAfter != BB->end())
278
280
281
282
283
287 };
288
289
292 if (CanUse(Inst, Ptr, PA, Class)) {
294 << *Ptr << "\n");
295 SetSeqAndInsertReverseInsertPt(S_Use);
299 << *Ptr << "\n");
300 SetSeqAndInsertReverseInsertPt(S_Stop);
301 }
302 }
303 break;
305 if (CanUse(Inst, Ptr, PA, Class)) {
307 << "; " << *Ptr << "\n");
309 }
310 break;
314 break;
317 }
318}
319
320
321
322
323
325 bool NestingDetected = false;
326
327
328
330
331
332
333
334
335
336
338 NestingDetected = true;
339
343 }
344
346 return NestingDetected;
347}
348
352
354
355 MDNode *ReleaseMetadata =
357
358 switch (OldSeq) {
361 if (OldSeq == S_Retain || ReleaseMetadata != nullptr)
363 [[fallthrough]];
367 return true;
369 return false;
373 }
375}
376
380
381
384 return false;
385
387 << *Ptr << "\n");
394
395
396
397
398 if (BundledRVs.contains(Inst))
400
401
402
403
404 return true;
408 return false;
412 }
414}
415
419
422 if ((Inst, Ptr, PA, Class))
423 return;
425 << *Ptr << "\n");
427 return;
431 return;
435 }
436}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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)
Definition PtrState.cpp:59
LLVM Basic Block Representation.
LLVM_ABI 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.
bool contains(const Instruction *I) const
See if an instruction is a bundled retainRV/claimRV call.
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()
Definition PtrState.cpp:124
bool HasKnownPositiveRefCount() const
void InsertReverseInsertPt(Instruction *I)
bool HasReverseInsertPts() const
void SetTailCallRelease(const bool NewValue)
void ClearKnownPositiveRefCount()
Definition PtrState.cpp:129
void SetReleaseMetadata(MDNode *NewValue)
void InsertCall(Instruction *I)
void ResetSequenceProgress(Sequence NewSeq)
Definition PtrState.cpp:140
void SetSeq(Sequence NewSeq)
Definition PtrState.cpp:134
void SetKnownSafe(const bool NewValue)
void Merge(const PtrState &Other, bool TopDown)
Definition PtrState.cpp:147
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.
This file defines common definitions/declarations used by the ObjC ARC Optimizer.
#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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
LLVM_ABI BasicBlock::iterator skipDebugIntrinsics(BasicBlock::iterator It)
Advance It while it points to a debug instruction and return the result.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
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)
Definition PtrState.cpp:226
bool InitBottomUp(ARCMDKindCache &Cache, Instruction *I)
(Re-)Initialize this bottom up pointer returning true if we detected a pointer with nested releases.
Definition PtrState.cpp:174
bool MatchWithRetain()
Return true if this set of releases can be paired with a release.
Definition PtrState.cpp:203
void HandlePotentialUse(BasicBlock *BB, Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)
Definition PtrState.cpp:253
bool Merge(const RRInfo &Other)
Conservatively merge the two RRInfo.
Definition PtrState.cpp:99
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.
void clear()
Definition PtrState.cpp:90
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.
Definition PtrState.cpp:349
bool InitTopDown(ARCInstKind Kind, Instruction *I)
(Re-)Initialize this bottom up pointer returning true if we detected a pointer with nested releases.
Definition PtrState.cpp:324
bool HandlePotentialAlterRefCount(Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class, const BundledRetainClaimRVs &BundledRVs)
Definition PtrState.cpp:377
void HandlePotentialUse(Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)
Definition PtrState.cpp:416