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