blob: 1a12b659e5a3e3a249d57f1649b9695558340c58 [file] [log] [blame]
Michael Gottesman6eb95dc2013-07-10 18:49:00 +00001//===- ProvenanceAnalysis.h - ObjC ARC Optimization ---*- C++ -*-----------===//
Michael Gottesman778138e2013-01-29 03:03:03 +00002//
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 Kramera7c40ef2014-08-13 16:26:38 +000025#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
26#define LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
Michael Gottesman778138e2013-01-29 03:03:03 +000027
28#include "llvm/ADT/DenseMap.h"
Chandler Carruth7b560d42015-09-09 17:55:00 +000029#include "llvm/Analysis/AliasAnalysis.h"
Michael Gottesman778138e2013-01-29 03:03:03 +000030
31namespace llvm {
32 class Value;
Mehdi Aminia28d91d2015-03-10 02:37:25 +000033 class DataLayout;
Michael Gottesman778138e2013-01-29 03:03:03 +000034 class PHINode;
35 class SelectInst;
36}
37
38namespace llvm {
39namespace objcarc {
Michael Gottesman23a1ee52013-01-29 04:58:30 +000040
Michael Gottesman778138e2013-01-29 03:03:03 +000041/// \brief This is similar to BasicAliasAnalysis, and it uses many of the same
42/// techniques, except it uses special ObjC-specific reasoning about pointer
43/// relationships.
44///
45/// In this context ``Provenance'' is defined as the history of an object's
46/// ownership. Thus ``Provenance Analysis'' is defined by using the notion of
47/// an ``independent provenance source'' of a pointer to determine whether or
48/// not two pointers have the same provenance source and thus could
49/// potentially be related.
Benjamin Kramer079b96e2013-09-11 18:05:11 +000050class ProvenanceAnalysis {
Michael Gottesman778138e2013-01-29 03:03:03 +000051 AliasAnalysis *AA;
52
53 typedef std::pair<const Value *, const Value *> ValuePairTy;
54 typedef DenseMap<ValuePairTy, bool> CachedResultsTy;
55 CachedResultsTy CachedResults;
56
Mehdi Aminia28d91d2015-03-10 02:37:25 +000057 bool relatedCheck(const Value *A, const Value *B, const DataLayout &DL);
Michael Gottesman778138e2013-01-29 03:03:03 +000058 bool relatedSelect(const SelectInst *A, const Value *B);
59 bool relatedPHI(const PHINode *A, const Value *B);
60
Aaron Ballmanf9a18972015-02-15 22:54:22 +000061 void operator=(const ProvenanceAnalysis &) = delete;
62 ProvenanceAnalysis(const ProvenanceAnalysis &) = delete;
Michael Gottesman778138e2013-01-29 03:03:03 +000063
64public:
65 ProvenanceAnalysis() {}
66
67 void setAA(AliasAnalysis *aa) { AA = aa; }
68
69 AliasAnalysis *getAA() const { return AA; }
70
Mehdi Aminia28d91d2015-03-10 02:37:25 +000071 bool related(const Value *A, const Value *B, const DataLayout &DL);
Michael Gottesman778138e2013-01-29 03:03:03 +000072
73 void clear() {
74 CachedResults.clear();
75 }
76};
77
78} // end namespace objcarc
79} // end namespace llvm
80
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000081#endif