1263508Sdim//===- ProvenanceAnalysis.h - ObjC ARC Optimization ---*- C++ -*-----------===//
2249259Sdim//
3249259Sdim//                     The LLVM Compiler Infrastructure
4249259Sdim//
5249259Sdim// This file is distributed under the University of Illinois Open Source
6249259Sdim// License. See LICENSE.TXT for details.
7249259Sdim//
8249259Sdim//===----------------------------------------------------------------------===//
9249259Sdim/// \file
10249259Sdim///
11249259Sdim/// This file declares a special form of Alias Analysis called ``Provenance
12249259Sdim/// Analysis''. The word ``provenance'' refers to the history of the ownership
13249259Sdim/// of an object. Thus ``Provenance Analysis'' is an analysis which attempts to
14249259Sdim/// use various techniques to determine if locally
15249259Sdim///
16249259Sdim/// WARNING: This file knows about certain library functions. It recognizes them
17249259Sdim/// by name, and hardwires knowledge of their semantics.
18249259Sdim///
19249259Sdim/// WARNING: This file knows about how certain Objective-C library functions are
20249259Sdim/// used. Naive LLVM IR transformations which would otherwise be
21249259Sdim/// behavior-preserving may break these assumptions.
22249259Sdim///
23249259Sdim//===----------------------------------------------------------------------===//
24249259Sdim
25249259Sdim#ifndef LLVM_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
26249259Sdim#define LLVM_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
27249259Sdim
28249259Sdim#include "llvm/ADT/DenseMap.h"
29249259Sdim
30249259Sdimnamespace llvm {
31249259Sdim  class Value;
32249259Sdim  class AliasAnalysis;
33249259Sdim  class PHINode;
34249259Sdim  class SelectInst;
35249259Sdim}
36249259Sdim
37249259Sdimnamespace llvm {
38249259Sdimnamespace objcarc {
39249259Sdim
40249259Sdim/// \brief This is similar to BasicAliasAnalysis, and it uses many of the same
41249259Sdim/// techniques, except it uses special ObjC-specific reasoning about pointer
42249259Sdim/// relationships.
43249259Sdim///
44249259Sdim/// In this context ``Provenance'' is defined as the history of an object's
45249259Sdim/// ownership. Thus ``Provenance Analysis'' is defined by using the notion of
46249259Sdim/// an ``independent provenance source'' of a pointer to determine whether or
47249259Sdim/// not two pointers have the same provenance source and thus could
48249259Sdim/// potentially be related.
49249259Sdimclass ProvenanceAnalysis {
50249259Sdim  AliasAnalysis *AA;
51249259Sdim
52249259Sdim  typedef std::pair<const Value *, const Value *> ValuePairTy;
53249259Sdim  typedef DenseMap<ValuePairTy, bool> CachedResultsTy;
54249259Sdim  CachedResultsTy CachedResults;
55249259Sdim
56249259Sdim  bool relatedCheck(const Value *A, const Value *B);
57249259Sdim  bool relatedSelect(const SelectInst *A, const Value *B);
58249259Sdim  bool relatedPHI(const PHINode *A, const Value *B);
59249259Sdim
60249259Sdim  void operator=(const ProvenanceAnalysis &) LLVM_DELETED_FUNCTION;
61249259Sdim  ProvenanceAnalysis(const ProvenanceAnalysis &) LLVM_DELETED_FUNCTION;
62249259Sdim
63249259Sdimpublic:
64249259Sdim  ProvenanceAnalysis() {}
65249259Sdim
66249259Sdim  void setAA(AliasAnalysis *aa) { AA = aa; }
67249259Sdim
68249259Sdim  AliasAnalysis *getAA() const { return AA; }
69249259Sdim
70249259Sdim  bool related(const Value *A, const Value *B);
71249259Sdim
72249259Sdim  void clear() {
73249259Sdim    CachedResults.clear();
74249259Sdim  }
75249259Sdim};
76249259Sdim
77249259Sdim} // end namespace objcarc
78249259Sdim} // end namespace llvm
79249259Sdim
80249259Sdim#endif // LLVM_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
81