]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Analysis/CFLAndersAliasAnalysis.h
Upgrade our copies of clang, llvm, lld and libc++ to r311219 from the
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / Analysis / CFLAndersAliasAnalysis.h
1 //=- CFLAndersAliasAnalysis.h - Unification-based Alias Analysis ---*- C++-*-=//
2 //
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 /// This is the interface for LLVM's inclusion-based alias analysis
11 /// implemented with CFL graph reachability.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_ANALYSIS_CFLANDERSALIASANALYSIS_H
16 #define LLVM_ANALYSIS_CFLANDERSALIASANALYSIS_H
17
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/Analysis/AliasAnalysis.h"
21 #include "llvm/Analysis/CFLAliasAnalysisUtils.h"
22 #include "llvm/IR/Function.h"
23 #include "llvm/Pass.h"
24 #include <forward_list>
25
26 namespace llvm {
27
28 class TargetLibraryInfo;
29
30 namespace cflaa {
31 struct AliasSummary;
32 }
33
34 class CFLAndersAAResult : public AAResultBase<CFLAndersAAResult> {
35   friend AAResultBase<CFLAndersAAResult>;
36   class FunctionInfo;
37
38 public:
39   explicit CFLAndersAAResult(const TargetLibraryInfo &);
40   CFLAndersAAResult(CFLAndersAAResult &&);
41   ~CFLAndersAAResult();
42
43   /// Handle invalidation events from the new pass manager.
44   /// By definition, this result is stateless and so remains valid.
45   bool invalidate(Function &, const PreservedAnalyses &,
46                   FunctionAnalysisManager::Invalidator &) {
47     return false;
48   }
49   /// Evict the given function from cache
50   void evict(const Function *Fn);
51
52   /// \brief Get the alias summary for the given function
53   /// Return nullptr if the summary is not found or not available
54   const cflaa::AliasSummary *getAliasSummary(const Function &);
55
56   AliasResult query(const MemoryLocation &, const MemoryLocation &);
57   AliasResult alias(const MemoryLocation &, const MemoryLocation &);
58
59 private:
60   /// \brief Ensures that the given function is available in the cache.
61   /// Returns the appropriate entry from the cache.
62   const Optional<FunctionInfo> &ensureCached(const Function &);
63
64   /// \brief Inserts the given Function into the cache.
65   void scan(const Function &);
66
67   /// \brief Build summary for a given function
68   FunctionInfo buildInfoFrom(const Function &);
69
70   const TargetLibraryInfo &TLI;
71
72   /// \brief Cached mapping of Functions to their StratifiedSets.
73   /// If a function's sets are currently being built, it is marked
74   /// in the cache as an Optional without a value. This way, if we
75   /// have any kind of recursion, it is discernable from a function
76   /// that simply has empty sets.
77   DenseMap<const Function *, Optional<FunctionInfo>> Cache;
78
79   std::forward_list<cflaa::FunctionHandle<CFLAndersAAResult>> Handles;
80 };
81
82 /// Analysis pass providing a never-invalidated alias analysis result.
83 ///
84 /// FIXME: We really should refactor CFL to use the analysis more heavily, and
85 /// in particular to leverage invalidation to trigger re-computation.
86 class CFLAndersAA : public AnalysisInfoMixin<CFLAndersAA> {
87   friend AnalysisInfoMixin<CFLAndersAA>;
88   static AnalysisKey Key;
89
90 public:
91   typedef CFLAndersAAResult Result;
92
93   CFLAndersAAResult run(Function &F, FunctionAnalysisManager &AM);
94 };
95
96 /// Legacy wrapper pass to provide the CFLAndersAAResult object.
97 class CFLAndersAAWrapperPass : public ImmutablePass {
98   std::unique_ptr<CFLAndersAAResult> Result;
99
100 public:
101   static char ID;
102
103   CFLAndersAAWrapperPass();
104
105   CFLAndersAAResult &getResult() { return *Result; }
106   const CFLAndersAAResult &getResult() const { return *Result; }
107
108   void initializePass() override;
109   void getAnalysisUsage(AnalysisUsage &AU) const override;
110 };
111
112 //===--------------------------------------------------------------------===//
113 //
114 // createCFLAndersAAWrapperPass - This pass implements a set-based approach to
115 // alias analysis.
116 //
117 ImmutablePass *createCFLAndersAAWrapperPass();
118 }
119
120 #endif