22#ifndef LLVM_ANALYSIS_OBJCARCANALYSISUTILS_H
23#define LLVM_ANALYSIS_OBJCARCANALYSISUTILS_H
44 return M.getNamedValue(
"llvm.objc.retain") ||
45 M.getNamedValue(
"llvm.objc.release") ||
46 M.getNamedValue(
"llvm.objc.autorelease") ||
47 M.getNamedValue(
"llvm.objc.retainAutoreleasedReturnValue") ||
48 M.getNamedValue(
"llvm.objc.unsafeClaimAutoreleasedReturnValue") ||
49 M.getNamedValue(
"llvm.objc.retainBlock") ||
50 M.getNamedValue(
"llvm.objc.autoreleaseReturnValue") ||
51 M.getNamedValue(
"llvm.objc.autoreleasePoolPush") ||
52 M.getNamedValue(
"llvm.objc.loadWeakRetained") ||
53 M.getNamedValue(
"llvm.objc.loadWeak") ||
54 M.getNamedValue(
"llvm.objc.destroyWeak") ||
55 M.getNamedValue(
"llvm.objc.storeWeak") ||
56 M.getNamedValue(
"llvm.objc.initWeak") ||
57 M.getNamedValue(
"llvm.objc.moveWeak") ||
58 M.getNamedValue(
"llvm.objc.copyWeak") ||
59 M.getNamedValue(
"llvm.objc.retainedObject") ||
60 M.getNamedValue(
"llvm.objc.unretainedObject") ||
61 M.getNamedValue(
"llvm.objc.unretainedPointer") ||
62 M.getNamedValue(
"llvm.objc.clang.arc.noop.use") ||
63 M.getNamedValue(
"llvm.objc.clang.arc.use");
74 V = cast<CallInst>(V)->getArgOperand(0);
83 DenseMap<
const Value *, std::pair<WeakVH, WeakTrackingVH>> &Cache) {
85 auto InCache = Cache.lookup(V);
86 if (InCache.first && InCache.second)
87 return InCache.second;
91 std::make_pair(
const_cast<Value *
>(V),
const_cast<Value *
>(Computed));
112 V = V->stripPointerCasts();
115 V = cast<CallInst>(V)->getArgOperand(0);
136 return isa<ConstantPointerNull>(V) || isa<UndefValue>(V);
140 return isa<BitCastInst>(
I) ||
141 (isa<GetElementPtrInst>(
I) &&
142 cast<GetElementPtrInst>(
I)->hasAllZeroIndices());
149 if (isa<Constant>(
Op) || isa<AllocaInst>(
Op))
152 if (
const Argument *Arg = dyn_cast<Argument>(
Op))
153 if (Arg->hasPassPointeeByValueCopyAttr() || Arg->hasNestAttr() ||
154 Arg->hasStructRetAttr())
190 if (isa<CallInst>(V) || isa<InvokeInst>(V) ||
191 isa<Argument>(V) || isa<Constant>(V) ||
195 if (
const LoadInst *LI = dyn_cast<LoadInst>(V)) {
196 const Value *Pointer =
198 if (
const GlobalVariable *GV = dyn_cast<GlobalVariable>(Pointer)) {
201 if (GV->isConstant())
206 if (
Name.starts_with(
"\01l_objc_msgSend_fixup_"))
210 if (Section.contains(
"__message_refs") ||
211 Section.contains(
"__objc_classrefs") ||
212 Section.contains(
"__objc_superrefs") ||
213 Section.contains(
"__objc_methname") || Section.contains(
"__cstring"))
232 std::optional<unsigned> ImpreciseReleaseMDKind;
235 std::optional<unsigned> CopyOnEscapeMDKind;
238 std::optional<unsigned> NoObjCARCExceptionsMDKind;
243 ImpreciseReleaseMDKind = std::nullopt;
244 CopyOnEscapeMDKind = std::nullopt;
245 NoObjCARCExceptionsMDKind = std::nullopt;
251 if (!ImpreciseReleaseMDKind)
252 ImpreciseReleaseMDKind =
253 M->getContext().getMDKindID(
"clang.imprecise_release");
254 return *ImpreciseReleaseMDKind;
256 if (!CopyOnEscapeMDKind)
258 M->getContext().getMDKindID(
"clang.arc.copy_on_escape");
259 return *CopyOnEscapeMDKind;
261 if (!NoObjCARCExceptionsMDKind)
262 NoObjCARCExceptionsMDKind =
263 M->getContext().getMDKindID(
"clang.arc.no_objc_arc_exceptions");
264 return *NoObjCARCExceptionsMDKind;
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.
This class represents an Operation in the Expression.
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.
unsigned get(ARCMDKindID ID)
#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 ModuleHasARC(const Module &M)
Test if the given module looks interesting to run ARC optimization on.
ARCInstKind GetCallSiteClass(const CallBase &CB)
Helper for GetARCInstKind.
bool IsNullOrUndef(const Value *V)
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.
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.
bool IsNoopInstruction(const Instruction *I)
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.
Value * GetArgRCIdentityRoot(Value *Inst)
Assuming the given instruction is one of the special calls such as objc_retain or objc_release,...
const Value * GetUnderlyingObjCPtr(const Value *V)
This is a wrapper around getUnderlyingObject which also knows how to look through objc_retain and obj...
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...
This is an optimization pass for GlobalISel generic memory operations.
const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=6)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
@ Mod
The access may modify the value stored in memory.