LLVM  mainline
DependencyAnalysis.h
Go to the documentation of this file.
00001 //===- DependencyAnalysis.h - ObjC ARC Optimization ---*- C++ -*-----------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 /// \file
00010 ///
00011 /// This file declares special dependency analysis routines used in Objective C
00012 /// ARC Optimizations.
00013 ///
00014 /// WARNING: This file knows about certain library functions. It recognizes them
00015 /// by name, and hardwires knowledge of their semantics.
00016 ///
00017 /// WARNING: This file knows about how certain Objective-C library functions are
00018 /// used. Naive LLVM IR transformations which would otherwise be
00019 /// behavior-preserving may break these assumptions.
00020 ///
00021 //===----------------------------------------------------------------------===//
00022 
00023 #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
00024 #define LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
00025 
00026 #include "llvm/ADT/SmallPtrSet.h"
00027 
00028 namespace llvm {
00029   class BasicBlock;
00030   class Instruction;
00031   class Value;
00032 }
00033 
00034 namespace llvm {
00035 namespace objcarc {
00036 
00037 class ProvenanceAnalysis;
00038 
00039 /// \enum DependenceKind
00040 /// \brief Defines different dependence kinds among various ARC constructs.
00041 ///
00042 /// There are several kinds of dependence-like concepts in use here.
00043 ///
00044 enum DependenceKind {
00045   NeedsPositiveRetainCount,
00046   AutoreleasePoolBoundary,
00047   CanChangeRetainCount,
00048   RetainAutoreleaseDep,       ///< Blocks objc_retainAutorelease.
00049   RetainAutoreleaseRVDep,     ///< Blocks objc_retainAutoreleaseReturnValue.
00050   RetainRVDep                 ///< Blocks objc_retainAutoreleasedReturnValue.
00051 };
00052 
00053 void FindDependencies(DependenceKind Flavor,
00054                       const Value *Arg,
00055                       BasicBlock *StartBB, Instruction *StartInst,
00056                       SmallPtrSetImpl<Instruction *> &DependingInstructions,
00057                       SmallPtrSetImpl<const BasicBlock *> &Visited,
00058                       ProvenanceAnalysis &PA);
00059 
00060 bool
00061 Depends(DependenceKind Flavor, Instruction *Inst, const Value *Arg,
00062         ProvenanceAnalysis &PA);
00063 
00064 /// Test whether the given instruction can "use" the given pointer's object in a
00065 /// way that requires the reference count to be positive.
00066 bool CanUse(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA,
00067             ARCInstKind Class);
00068 
00069 /// Test whether the given instruction can result in a reference count
00070 /// modification (positive or negative) for the pointer's object.
00071 bool CanAlterRefCount(const Instruction *Inst, const Value *Ptr,
00072                       ProvenanceAnalysis &PA, ARCInstKind Class);
00073 
00074 /// Returns true if we can not conservatively prove that Inst can not decrement
00075 /// the reference count of Ptr. Returns false if we can.
00076 bool CanDecrementRefCount(const Instruction *Inst, const Value *Ptr,
00077                           ProvenanceAnalysis &PA, ARCInstKind Class);
00078 
00079 static inline bool CanDecrementRefCount(const Instruction *Inst,
00080                                         const Value *Ptr,
00081                                         ProvenanceAnalysis &PA) {
00082   return CanDecrementRefCount(Inst, Ptr, PA, GetARCInstKind(Inst));
00083 }
00084 
00085 } // namespace objcarc
00086 } // namespace llvm
00087 
00088 #endif