LLVM: include/llvm/Analysis/ObjCARCAnalysisUtils.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#ifndef LLVM_ANALYSIS_OBJCARCANALYSISUTILS_H
23#define LLVM_ANALYSIS_OBJCARCANALYSISUTILS_H
24
30#include
31
32namespace llvm {
33
35
37
38
40
41
42
44 std::initializer_listIntrinsic::ID Intrinsics = {
45 Intrinsic::objc_retain,
46 Intrinsic::objc_release,
47 Intrinsic::objc_autorelease,
48 Intrinsic::objc_retainAutoreleasedReturnValue,
49 Intrinsic::objc_retainBlock,
50 Intrinsic::objc_autoreleaseReturnValue,
51 Intrinsic::objc_autoreleasePoolPush,
52 Intrinsic::objc_loadWeakRetained,
53 Intrinsic::objc_loadWeak,
54 Intrinsic::objc_destroyWeak,
55 Intrinsic::objc_initWeak,
56 Intrinsic::objc_copyWeak,
57 Intrinsic::objc_retainedObject,
58 Intrinsic::objc_unretainedObject,
59 Intrinsic::objc_unretainedPointer,
60 Intrinsic::objc_clang_arc_noop_use,
61 Intrinsic::objc_clang_arc_use,
62 };
63#ifndef NDEBUG
66 "Can only check non-overloaded intrinsics");
67#endif
70 return true;
71 return false;
72}
73
74
75
76
78 for (;;) {
81 break;
83 }
84
85 return V;
86}
87
88
91 DenseMap<const Value *, std::pair<WeakVH, WeakTrackingVH>> &Cache) {
92
93 auto InCache = Cache.lookup(V);
94 if (InCache.first && InCache.second)
95 return InCache.second;
96
98 Cache[V] =
99 std::make_pair(const_cast<Value *>(V), const_cast<Value *>(Computed));
100 return Computed;
101}
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
119 for (;;) {
120 V = V->stripPointerCasts();
122 break;
124 }
125 return V;
126}
127
128
129
130
131
135
136
137
138
142
146
152
153
155
156
158 return false;
159
161 if (Arg->hasPassPointeeByValueCopyAttr() || Arg->hasNestAttr() ||
162 Arg->hasStructRetAttr())
163 return false;
164
165
166
167
168
170 if (!Ty)
171 return false;
172
173
174 return true;
175}
176
178
179
180
182 for (const Use &U : CB.args())
185
187}
188
189
190
191
192
193
195
196
197
201 return true;
202
204 const Value *Pointer =
207
208
209 if (GV->isConstant())
210 return true;
212
213
214 if (Name.starts_with("\01l_objc_msgSend_fixup_"))
215 return true;
216
217 StringRef Section = GV->getSection();
218 if (Section.contains("__message_refs") ||
219 Section.contains("__objc_classrefs") ||
220 Section.contains("__objc_superrefs") ||
221 Section.contains("__objc_methname") || Section.contains("__cstring"))
222 return true;
223 }
224 }
225
226 return false;
227}
228
234
235
238
239
240 std::optional ImpreciseReleaseMDKind;
241
242
243 std::optional CopyOnEscapeMDKind;
244
245
246 std::optional NoObjCARCExceptionsMDKind;
247
248public:
251 ImpreciseReleaseMDKind = std::nullopt;
252 CopyOnEscapeMDKind = std::nullopt;
253 NoObjCARCExceptionsMDKind = std::nullopt;
254 }
255
257 switch (ID) {
259 if (!ImpreciseReleaseMDKind)
260 ImpreciseReleaseMDKind =
261 M->getContext().getMDKindID("clang.imprecise_release");
262 return *ImpreciseReleaseMDKind;
264 if (!CopyOnEscapeMDKind)
265 CopyOnEscapeMDKind =
266 M->getContext().getMDKindID("clang.arc.copy_on_escape");
267 return *CopyOnEscapeMDKind;
269 if (!NoObjCARCExceptionsMDKind)
270 NoObjCARCExceptionsMDKind =
271 M->getContext().getMDKindID("clang.arc.no_objc_arc_exceptions");
272 return *NoObjCARCExceptionsMDKind;
273 }
275 }
276};
277
278}
279}
280
281#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
This class represents an incoming formal argument to a Function.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool onlyReadsMemory(unsigned OpNo) const
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
An instruction for reading from memory.
A Module instance is used to store all the information related to an LLVM module.
Class to represent pointers.
StringRef - Represent a constant reference to a string, i.e.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
A cache of MDKinds used by various ARC optimizations.
Definition ObjCARCAnalysisUtils.h:236
unsigned get(ARCMDKindID ID)
Definition ObjCARCAnalysisUtils.h:256
void init(Module *Mod)
Definition ObjCARCAnalysisUtils.h:249
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Abstract Attribute helper functions.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)
Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.
LLVM_ABI bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
bool IsPotentialRetainableObjPtr(const Value *Op)
Test whether the given value is possible a retainable object pointer.
Definition ObjCARCAnalysisUtils.h:154
bool ModuleHasARC(const Module &M)
Test if the given module looks interesting to run ARC optimization on.
Definition ObjCARCAnalysisUtils.h:43
ARCInstKind GetCallSiteClass(const CallBase &CB)
Helper for GetARCInstKind.
Definition ObjCARCAnalysisUtils.h:181
bool IsNullOrUndef(const Value *V)
Definition ObjCARCAnalysisUtils.h:143
ARCInstKind
Equivalence classes of instructions in the ARC Model.
@ CallOrUser
could call objc_release and/or "use" pointers
@ None
anything that is inert from an ARC perspective.
@ User
could "use" a pointer
@ Call
could call objc_release
bool IsObjCIdentifiedObject(const Value *V)
Return true if this value refers to a distinct and identifiable object.
Definition ObjCARCAnalysisUtils.h:194
bool EnableARCOpts
A handy option to enable/disable all ARC Optimizations.
bool IsForwarding(ARCInstKind Class)
Test if the given class represents instructions which return their argument verbatim.
ARCMDKindID
Definition ObjCARCAnalysisUtils.h:229
@ CopyOnEscape
Definition ObjCARCAnalysisUtils.h:231
@ ImpreciseRelease
Definition ObjCARCAnalysisUtils.h:230
@ NoObjCARCExceptions
Definition ObjCARCAnalysisUtils.h:232
bool IsNoopInstruction(const Instruction *I)
Definition ObjCARCAnalysisUtils.h:147
ARCInstKind GetBasicARCInstKind(const Value *V)
Determine which objc runtime call instruction class V belongs to.
const Value * GetUnderlyingObjCPtrCached(const Value *V, DenseMap< const Value *, std::pair< WeakVH, WeakTrackingVH > > &Cache)
A wrapper for GetUnderlyingObjCPtr used for results memoization.
Definition ObjCARCAnalysisUtils.h:89
Value * GetArgRCIdentityRoot(Value *Inst)
Assuming the given instruction is one of the special calls such as objc_retain or objc_release,...
Definition ObjCARCAnalysisUtils.h:139
const Value * GetUnderlyingObjCPtr(const Value *V)
This is a wrapper around getUnderlyingObject which also knows how to look through objc_retain and obj...
Definition ObjCARCAnalysisUtils.h:77
const Value * GetRCIdentityRoot(const Value *V)
The RCIdentity root of a value V is a dominating value U for which retaining or releasing U is equiva...
Definition ObjCARCAnalysisUtils.h:118
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.
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
@ Mod
The access may modify the value stored in memory.
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
LLVM_ABI const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=MaxLookupSearchDepth)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....