Michael Gottesman | 6eb95dc | 2013-07-10 18:49:00 +0000 | [diff] [blame] | 1 | //===- DependencyAnalysis.h - ObjC ARC Optimization ---*- C++ -*-----------===// |
Michael Gottesman | 778138e | 2013-01-29 03:03:03 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// |
| 11 | /// This file declares special dependency analysis routines used in Objective C |
| 12 | /// ARC Optimizations. |
| 13 | /// |
| 14 | /// WARNING: This file knows about certain library functions. It recognizes them |
| 15 | /// by name, and hardwires knowledge of their semantics. |
| 16 | /// |
| 17 | /// WARNING: This file knows about how certain Objective-C library functions are |
| 18 | /// used. Naive LLVM IR transformations which would otherwise be |
| 19 | /// behavior-preserving may break these assumptions. |
| 20 | /// |
| 21 | //===----------------------------------------------------------------------===// |
| 22 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 23 | #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H |
| 24 | #define LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H |
Michael Gottesman | 778138e | 2013-01-29 03:03:03 +0000 | [diff] [blame] | 25 | |
| 26 | #include "llvm/ADT/SmallPtrSet.h" |
| 27 | |
| 28 | namespace llvm { |
| 29 | class BasicBlock; |
| 30 | class Instruction; |
| 31 | class Value; |
| 32 | } |
| 33 | |
| 34 | namespace llvm { |
| 35 | namespace objcarc { |
| 36 | |
| 37 | class ProvenanceAnalysis; |
| 38 | |
| 39 | /// \enum DependenceKind |
| 40 | /// \brief Defines different dependence kinds among various ARC constructs. |
| 41 | /// |
| 42 | /// There are several kinds of dependence-like concepts in use here. |
| 43 | /// |
| 44 | enum DependenceKind { |
| 45 | NeedsPositiveRetainCount, |
| 46 | AutoreleasePoolBoundary, |
| 47 | CanChangeRetainCount, |
| 48 | RetainAutoreleaseDep, ///< Blocks objc_retainAutorelease. |
| 49 | RetainAutoreleaseRVDep, ///< Blocks objc_retainAutoreleaseReturnValue. |
| 50 | RetainRVDep ///< Blocks objc_retainAutoreleasedReturnValue. |
| 51 | }; |
| 52 | |
| 53 | void FindDependencies(DependenceKind Flavor, |
| 54 | const Value *Arg, |
| 55 | BasicBlock *StartBB, Instruction *StartInst, |
Craig Topper | 71b7b68 | 2014-08-21 05:55:13 +0000 | [diff] [blame] | 56 | SmallPtrSetImpl<Instruction *> &DependingInstructions, |
| 57 | SmallPtrSetImpl<const BasicBlock *> &Visited, |
Michael Gottesman | 778138e | 2013-01-29 03:03:03 +0000 | [diff] [blame] | 58 | ProvenanceAnalysis &PA); |
| 59 | |
| 60 | bool |
| 61 | Depends(DependenceKind Flavor, Instruction *Inst, const Value *Arg, |
| 62 | ProvenanceAnalysis &PA); |
| 63 | |
| 64 | /// Test whether the given instruction can "use" the given pointer's object in a |
| 65 | /// way that requires the reference count to be positive. |
Michael Gottesman | 6f729fa | 2015-02-19 19:51:32 +0000 | [diff] [blame^] | 66 | bool CanUse(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, |
| 67 | ARCInstKind Class); |
Michael Gottesman | 778138e | 2013-01-29 03:03:03 +0000 | [diff] [blame] | 68 | |
| 69 | /// Test whether the given instruction can result in a reference count |
| 70 | /// modification (positive or negative) for the pointer's object. |
Michael Gottesman | 6f729fa | 2015-02-19 19:51:32 +0000 | [diff] [blame^] | 71 | bool CanAlterRefCount(const Instruction *Inst, const Value *Ptr, |
| 72 | ProvenanceAnalysis &PA, ARCInstKind Class); |
Michael Gottesman | 778138e | 2013-01-29 03:03:03 +0000 | [diff] [blame] | 73 | |
| 74 | } // namespace objcarc |
| 75 | } // namespace llvm |
| 76 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 77 | #endif |