LLVM  mainline
ProvenanceAnalysis.h
Go to the documentation of this file.
00001 //===- ProvenanceAnalysis.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 a special form of Alias Analysis called ``Provenance
00012 /// Analysis''. The word ``provenance'' refers to the history of the ownership
00013 /// of an object. Thus ``Provenance Analysis'' is an analysis which attempts to
00014 /// use various techniques to determine if locally
00015 ///
00016 /// WARNING: This file knows about certain library functions. It recognizes them
00017 /// by name, and hardwires knowledge of their semantics.
00018 ///
00019 /// WARNING: This file knows about how certain Objective-C library functions are
00020 /// used. Naive LLVM IR transformations which would otherwise be
00021 /// behavior-preserving may break these assumptions.
00022 ///
00023 //===----------------------------------------------------------------------===//
00024 
00025 #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
00026 #define LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
00027 
00028 #include "llvm/ADT/DenseMap.h"
00029 
00030 namespace llvm {
00031   class Value;
00032   class AliasAnalysis;
00033   class DataLayout;
00034   class PHINode;
00035   class SelectInst;
00036 }
00037 
00038 namespace llvm {
00039 namespace objcarc {
00040 
00041 /// \brief This is similar to BasicAliasAnalysis, and it uses many of the same
00042 /// techniques, except it uses special ObjC-specific reasoning about pointer
00043 /// relationships.
00044 ///
00045 /// In this context ``Provenance'' is defined as the history of an object's
00046 /// ownership. Thus ``Provenance Analysis'' is defined by using the notion of
00047 /// an ``independent provenance source'' of a pointer to determine whether or
00048 /// not two pointers have the same provenance source and thus could
00049 /// potentially be related.
00050 class ProvenanceAnalysis {
00051   AliasAnalysis *AA;
00052 
00053   typedef std::pair<const Value *, const Value *> ValuePairTy;
00054   typedef DenseMap<ValuePairTy, bool> CachedResultsTy;
00055   CachedResultsTy CachedResults;
00056 
00057   bool relatedCheck(const Value *A, const Value *B, const DataLayout &DL);
00058   bool relatedSelect(const SelectInst *A, const Value *B);
00059   bool relatedPHI(const PHINode *A, const Value *B);
00060 
00061   void operator=(const ProvenanceAnalysis &) = delete;
00062   ProvenanceAnalysis(const ProvenanceAnalysis &) = delete;
00063 
00064 public:
00065   ProvenanceAnalysis() {}
00066 
00067   void setAA(AliasAnalysis *aa) { AA = aa; }
00068 
00069   AliasAnalysis *getAA() const { return AA; }
00070 
00071   bool related(const Value *A, const Value *B, const DataLayout &DL);
00072 
00073   void clear() {
00074     CachedResults.clear();
00075   }
00076 };
00077 
00078 } // end namespace objcarc
00079 } // end namespace llvm
00080 
00081 #endif