1 //===- ProvenanceAnalysis.h - ObjC ARC Optimization -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
17 /// WARNING: This file knows about certain library functions. It recognizes them
18 /// by name, and hardwires knowledge of their semantics.
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.
24 //===----------------------------------------------------------------------===//
26 #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
27 #define LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
29 #include "llvm/ADT/DenseMap.h"
30 #include "llvm/Analysis/AliasAnalysis.h"
31 #include "llvm/IR/ValueHandle.h"
43 /// This is similar to BasicAliasAnalysis, and it uses many of the same
44 /// techniques, except it uses special ObjC-specific reasoning about pointer
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 {
55 using ValuePairTy = std::pair<const Value *, const Value *>;
56 using CachedResultsTy = DenseMap<ValuePairTy, bool>;
58 CachedResultsTy CachedResults;
60 DenseMap<const Value *, WeakTrackingVH> UnderlyingObjCPtrCache;
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);
67 ProvenanceAnalysis() = default;
68 ProvenanceAnalysis(const ProvenanceAnalysis &) = delete;
69 ProvenanceAnalysis &operator=(const ProvenanceAnalysis &) = delete;
71 void setAA(AliasAnalysis *aa) { AA = aa; }
73 AliasAnalysis *getAA() const { return AA; }
75 bool related(const Value *A, const Value *B, const DataLayout &DL);
78 CachedResults.clear();
79 UnderlyingObjCPtrCache.clear();
83 } // end namespace objcarc
85 } // end namespace llvm
87 #endif // LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H