1*9880d681SAndroid Build Coastguard Worker //===- ProvenanceAnalysis.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 a special form of Alias Analysis called ``Provenance 12*9880d681SAndroid Build Coastguard Worker /// Analysis''. The word ``provenance'' refers to the history of the ownership 13*9880d681SAndroid Build Coastguard Worker /// of an object. Thus ``Provenance Analysis'' is an analysis which attempts to 14*9880d681SAndroid Build Coastguard Worker /// use various techniques to determine if locally 15*9880d681SAndroid Build Coastguard Worker /// 16*9880d681SAndroid Build Coastguard Worker /// WARNING: This file knows about certain library functions. It recognizes them 17*9880d681SAndroid Build Coastguard Worker /// by name, and hardwires knowledge of their semantics. 18*9880d681SAndroid Build Coastguard Worker /// 19*9880d681SAndroid Build Coastguard Worker /// WARNING: This file knows about how certain Objective-C library functions are 20*9880d681SAndroid Build Coastguard Worker /// used. Naive LLVM IR transformations which would otherwise be 21*9880d681SAndroid Build Coastguard Worker /// behavior-preserving may break these assumptions. 22*9880d681SAndroid Build Coastguard Worker /// 23*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H 26*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/DenseMap.h" 29*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/AliasAnalysis.h" 30*9880d681SAndroid Build Coastguard Worker 31*9880d681SAndroid Build Coastguard Worker namespace llvm { 32*9880d681SAndroid Build Coastguard Worker class Value; 33*9880d681SAndroid Build Coastguard Worker class DataLayout; 34*9880d681SAndroid Build Coastguard Worker class PHINode; 35*9880d681SAndroid Build Coastguard Worker class SelectInst; 36*9880d681SAndroid Build Coastguard Worker } 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard Worker namespace llvm { 39*9880d681SAndroid Build Coastguard Worker namespace objcarc { 40*9880d681SAndroid Build Coastguard Worker 41*9880d681SAndroid Build Coastguard Worker /// \brief This is similar to BasicAliasAnalysis, and it uses many of the same 42*9880d681SAndroid Build Coastguard Worker /// techniques, except it uses special ObjC-specific reasoning about pointer 43*9880d681SAndroid Build Coastguard Worker /// relationships. 44*9880d681SAndroid Build Coastguard Worker /// 45*9880d681SAndroid Build Coastguard Worker /// In this context ``Provenance'' is defined as the history of an object's 46*9880d681SAndroid Build Coastguard Worker /// ownership. Thus ``Provenance Analysis'' is defined by using the notion of 47*9880d681SAndroid Build Coastguard Worker /// an ``independent provenance source'' of a pointer to determine whether or 48*9880d681SAndroid Build Coastguard Worker /// not two pointers have the same provenance source and thus could 49*9880d681SAndroid Build Coastguard Worker /// potentially be related. 50*9880d681SAndroid Build Coastguard Worker class ProvenanceAnalysis { 51*9880d681SAndroid Build Coastguard Worker AliasAnalysis *AA; 52*9880d681SAndroid Build Coastguard Worker 53*9880d681SAndroid Build Coastguard Worker typedef std::pair<const Value *, const Value *> ValuePairTy; 54*9880d681SAndroid Build Coastguard Worker typedef DenseMap<ValuePairTy, bool> CachedResultsTy; 55*9880d681SAndroid Build Coastguard Worker CachedResultsTy CachedResults; 56*9880d681SAndroid Build Coastguard Worker 57*9880d681SAndroid Build Coastguard Worker bool relatedCheck(const Value *A, const Value *B, const DataLayout &DL); 58*9880d681SAndroid Build Coastguard Worker bool relatedSelect(const SelectInst *A, const Value *B); 59*9880d681SAndroid Build Coastguard Worker bool relatedPHI(const PHINode *A, const Value *B); 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Worker void operator=(const ProvenanceAnalysis &) = delete; 62*9880d681SAndroid Build Coastguard Worker ProvenanceAnalysis(const ProvenanceAnalysis &) = delete; 63*9880d681SAndroid Build Coastguard Worker 64*9880d681SAndroid Build Coastguard Worker public: ProvenanceAnalysis()65*9880d681SAndroid Build Coastguard Worker ProvenanceAnalysis() {} 66*9880d681SAndroid Build Coastguard Worker setAA(AliasAnalysis * aa)67*9880d681SAndroid Build Coastguard Worker void setAA(AliasAnalysis *aa) { AA = aa; } 68*9880d681SAndroid Build Coastguard Worker getAA()69*9880d681SAndroid Build Coastguard Worker AliasAnalysis *getAA() const { return AA; } 70*9880d681SAndroid Build Coastguard Worker 71*9880d681SAndroid Build Coastguard Worker bool related(const Value *A, const Value *B, const DataLayout &DL); 72*9880d681SAndroid Build Coastguard Worker clear()73*9880d681SAndroid Build Coastguard Worker void clear() { 74*9880d681SAndroid Build Coastguard Worker CachedResults.clear(); 75*9880d681SAndroid Build Coastguard Worker } 76*9880d681SAndroid Build Coastguard Worker }; 77*9880d681SAndroid Build Coastguard Worker 78*9880d681SAndroid Build Coastguard Worker } // end namespace objcarc 79*9880d681SAndroid Build Coastguard Worker } // end namespace llvm 80*9880d681SAndroid Build Coastguard Worker 81*9880d681SAndroid Build Coastguard Worker #endif 82