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