xref: /aosp_15_r20/external/llvm/lib/Transforms/ObjCARC/DependencyAnalysis.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===- DependencyAnalysis.h - ObjC ARC Optimization ---*- C++ -*-----------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker /// \file
10*9880d681SAndroid Build Coastguard Worker ///
11*9880d681SAndroid Build Coastguard Worker /// This file declares special dependency analysis routines used in Objective C
12*9880d681SAndroid Build Coastguard Worker /// ARC Optimizations.
13*9880d681SAndroid Build Coastguard Worker ///
14*9880d681SAndroid Build Coastguard Worker /// WARNING: This file knows about certain library functions. It recognizes them
15*9880d681SAndroid Build Coastguard Worker /// by name, and hardwires knowledge of their semantics.
16*9880d681SAndroid Build Coastguard Worker ///
17*9880d681SAndroid Build Coastguard Worker /// WARNING: This file knows about how certain Objective-C library functions are
18*9880d681SAndroid Build Coastguard Worker /// used. Naive LLVM IR transformations which would otherwise be
19*9880d681SAndroid Build Coastguard Worker /// behavior-preserving may break these assumptions.
20*9880d681SAndroid Build Coastguard Worker ///
21*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
22*9880d681SAndroid Build Coastguard Worker 
23*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
24*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
25*9880d681SAndroid Build Coastguard Worker 
26*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallPtrSet.h"
27*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/ObjCARCInstKind.h"
28*9880d681SAndroid Build Coastguard Worker 
29*9880d681SAndroid Build Coastguard Worker namespace llvm {
30*9880d681SAndroid Build Coastguard Worker   class BasicBlock;
31*9880d681SAndroid Build Coastguard Worker   class Instruction;
32*9880d681SAndroid Build Coastguard Worker   class Value;
33*9880d681SAndroid Build Coastguard Worker }
34*9880d681SAndroid Build Coastguard Worker 
35*9880d681SAndroid Build Coastguard Worker namespace llvm {
36*9880d681SAndroid Build Coastguard Worker namespace objcarc {
37*9880d681SAndroid Build Coastguard Worker 
38*9880d681SAndroid Build Coastguard Worker class ProvenanceAnalysis;
39*9880d681SAndroid Build Coastguard Worker 
40*9880d681SAndroid Build Coastguard Worker /// \enum DependenceKind
41*9880d681SAndroid Build Coastguard Worker /// \brief Defines different dependence kinds among various ARC constructs.
42*9880d681SAndroid Build Coastguard Worker ///
43*9880d681SAndroid Build Coastguard Worker /// There are several kinds of dependence-like concepts in use here.
44*9880d681SAndroid Build Coastguard Worker ///
45*9880d681SAndroid Build Coastguard Worker enum DependenceKind {
46*9880d681SAndroid Build Coastguard Worker   NeedsPositiveRetainCount,
47*9880d681SAndroid Build Coastguard Worker   AutoreleasePoolBoundary,
48*9880d681SAndroid Build Coastguard Worker   CanChangeRetainCount,
49*9880d681SAndroid Build Coastguard Worker   RetainAutoreleaseDep,       ///< Blocks objc_retainAutorelease.
50*9880d681SAndroid Build Coastguard Worker   RetainAutoreleaseRVDep,     ///< Blocks objc_retainAutoreleaseReturnValue.
51*9880d681SAndroid Build Coastguard Worker   RetainRVDep                 ///< Blocks objc_retainAutoreleasedReturnValue.
52*9880d681SAndroid Build Coastguard Worker };
53*9880d681SAndroid Build Coastguard Worker 
54*9880d681SAndroid Build Coastguard Worker void FindDependencies(DependenceKind Flavor,
55*9880d681SAndroid Build Coastguard Worker                       const Value *Arg,
56*9880d681SAndroid Build Coastguard Worker                       BasicBlock *StartBB, Instruction *StartInst,
57*9880d681SAndroid Build Coastguard Worker                       SmallPtrSetImpl<Instruction *> &DependingInstructions,
58*9880d681SAndroid Build Coastguard Worker                       SmallPtrSetImpl<const BasicBlock *> &Visited,
59*9880d681SAndroid Build Coastguard Worker                       ProvenanceAnalysis &PA);
60*9880d681SAndroid Build Coastguard Worker 
61*9880d681SAndroid Build Coastguard Worker bool
62*9880d681SAndroid Build Coastguard Worker Depends(DependenceKind Flavor, Instruction *Inst, const Value *Arg,
63*9880d681SAndroid Build Coastguard Worker         ProvenanceAnalysis &PA);
64*9880d681SAndroid Build Coastguard Worker 
65*9880d681SAndroid Build Coastguard Worker /// Test whether the given instruction can "use" the given pointer's object in a
66*9880d681SAndroid Build Coastguard Worker /// way that requires the reference count to be positive.
67*9880d681SAndroid Build Coastguard Worker bool CanUse(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA,
68*9880d681SAndroid Build Coastguard Worker             ARCInstKind Class);
69*9880d681SAndroid Build Coastguard Worker 
70*9880d681SAndroid Build Coastguard Worker /// Test whether the given instruction can result in a reference count
71*9880d681SAndroid Build Coastguard Worker /// modification (positive or negative) for the pointer's object.
72*9880d681SAndroid Build Coastguard Worker bool CanAlterRefCount(const Instruction *Inst, const Value *Ptr,
73*9880d681SAndroid Build Coastguard Worker                       ProvenanceAnalysis &PA, ARCInstKind Class);
74*9880d681SAndroid Build Coastguard Worker 
75*9880d681SAndroid Build Coastguard Worker /// Returns true if we can not conservatively prove that Inst can not decrement
76*9880d681SAndroid Build Coastguard Worker /// the reference count of Ptr. Returns false if we can.
77*9880d681SAndroid Build Coastguard Worker bool CanDecrementRefCount(const Instruction *Inst, const Value *Ptr,
78*9880d681SAndroid Build Coastguard Worker                           ProvenanceAnalysis &PA, ARCInstKind Class);
79*9880d681SAndroid Build Coastguard Worker 
CanDecrementRefCount(const Instruction * Inst,const Value * Ptr,ProvenanceAnalysis & PA)80*9880d681SAndroid Build Coastguard Worker static inline bool CanDecrementRefCount(const Instruction *Inst,
81*9880d681SAndroid Build Coastguard Worker                                         const Value *Ptr,
82*9880d681SAndroid Build Coastguard Worker                                         ProvenanceAnalysis &PA) {
83*9880d681SAndroid Build Coastguard Worker   return CanDecrementRefCount(Inst, Ptr, PA, GetARCInstKind(Inst));
84*9880d681SAndroid Build Coastguard Worker }
85*9880d681SAndroid Build Coastguard Worker 
86*9880d681SAndroid Build Coastguard Worker } // namespace objcarc
87*9880d681SAndroid Build Coastguard Worker } // namespace llvm
88*9880d681SAndroid Build Coastguard Worker 
89*9880d681SAndroid Build Coastguard Worker #endif
90