LLVM API Documentation

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_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
00026 #define LLVM_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
00027 
00028 #include "llvm/ADT/DenseMap.h"
00029 
00030 namespace llvm {
00031   class Value;
00032   class AliasAnalysis;
00033   class PHINode;
00034   class SelectInst;
00035 }
00036 
00037 namespace llvm {
00038 namespace objcarc {
00039 
00040 /// \brief This is similar to BasicAliasAnalysis, and it uses many of the same
00041 /// techniques, except it uses special ObjC-specific reasoning about pointer
00042 /// relationships.
00043 ///
00044 /// In this context ``Provenance'' is defined as the history of an object's
00045 /// ownership. Thus ``Provenance Analysis'' is defined by using the notion of
00046 /// an ``independent provenance source'' of a pointer to determine whether or
00047 /// not two pointers have the same provenance source and thus could
00048 /// potentially be related.
00049 class ProvenanceAnalysis {
00050   AliasAnalysis *AA;
00051 
00052   typedef std::pair<const Value *, const Value *> ValuePairTy;
00053   typedef DenseMap<ValuePairTy, bool> CachedResultsTy;
00054   CachedResultsTy CachedResults;
00055 
00056   bool relatedCheck(const Value *A, const Value *B);
00057   bool relatedSelect(const SelectInst *A, const Value *B);
00058   bool relatedPHI(const PHINode *A, const Value *B);
00059 
00060   void operator=(const ProvenanceAnalysis &) LLVM_DELETED_FUNCTION;
00061   ProvenanceAnalysis(const ProvenanceAnalysis &) LLVM_DELETED_FUNCTION;
00062 
00063 public:
00064   ProvenanceAnalysis() {}
00065 
00066   void setAA(AliasAnalysis *aa) { AA = aa; }
00067 
00068   AliasAnalysis *getAA() const { return AA; }
00069 
00070   bool related(const Value *A, const Value *B);
00071 
00072   void clear() {
00073     CachedResults.clear();
00074   }
00075 };
00076 
00077 } // end namespace objcarc
00078 } // end namespace llvm
00079 
00080 #endif // LLVM_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H