[InstCombine] Signed saturation patterns
[llvm-complete.git] / lib / Transforms / ObjCARC / ProvenanceAnalysis.h
blob8fd842fd42d641ce28218db67f12c3b3e59dc2f3
1 //===- ProvenanceAnalysis.h - ObjC ARC Optimization -------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
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.
23 //===----------------------------------------------------------------------===//
25 #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
26 #define LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
28 #include "llvm/ADT/DenseMap.h"
29 #include "llvm/Analysis/AliasAnalysis.h"
30 #include "llvm/IR/ValueHandle.h"
31 #include <utility>
33 namespace llvm {
35 class DataLayout;
36 class PHINode;
37 class SelectInst;
38 class Value;
40 namespace objcarc {
42 /// This is similar to BasicAliasAnalysis, and it uses many of the same
43 /// techniques, except it uses special ObjC-specific reasoning about pointer
44 /// relationships.
45 ///
46 /// In this context ``Provenance'' is defined as the history of an object's
47 /// ownership. Thus ``Provenance Analysis'' is defined by using the notion of
48 /// an ``independent provenance source'' of a pointer to determine whether or
49 /// not two pointers have the same provenance source and thus could
50 /// potentially be related.
51 class ProvenanceAnalysis {
52 AliasAnalysis *AA;
54 using ValuePairTy = std::pair<const Value *, const Value *>;
55 using CachedResultsTy = DenseMap<ValuePairTy, bool>;
57 CachedResultsTy CachedResults;
59 DenseMap<const Value *, WeakTrackingVH> UnderlyingObjCPtrCache;
61 bool relatedCheck(const Value *A, const Value *B, const DataLayout &DL);
62 bool relatedSelect(const SelectInst *A, const Value *B);
63 bool relatedPHI(const PHINode *A, const Value *B);
65 public:
66 ProvenanceAnalysis() = default;
67 ProvenanceAnalysis(const ProvenanceAnalysis &) = delete;
68 ProvenanceAnalysis &operator=(const ProvenanceAnalysis &) = delete;
70 void setAA(AliasAnalysis *aa) { AA = aa; }
72 AliasAnalysis *getAA() const { return AA; }
74 bool related(const Value *A, const Value *B, const DataLayout &DL);
76 void clear() {
77 CachedResults.clear();
78 UnderlyingObjCPtrCache.clear();
82 } // end namespace objcarc
84 } // end namespace llvm
86 #endif // LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H