Mercurial > hg > Members > tobaru > cbc > CbC_llvm
comparison include/llvm/Analysis/BasicAliasAnalysis.h @ 121:803732b1fca8
LLVM 5.0
author | kono |
---|---|
date | Fri, 27 Oct 2017 17:07:41 +0900 |
parents | 1172e4bd9c6f |
children |
comparison
equal
deleted
inserted
replaced
120:1172e4bd9c6f | 121:803732b1fca8 |
---|---|
12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
13 | 13 |
14 #ifndef LLVM_ANALYSIS_BASICALIASANALYSIS_H | 14 #ifndef LLVM_ANALYSIS_BASICALIASANALYSIS_H |
15 #define LLVM_ANALYSIS_BASICALIASANALYSIS_H | 15 #define LLVM_ANALYSIS_BASICALIASANALYSIS_H |
16 | 16 |
17 #include "llvm/ADT/DenseMap.h" | |
18 #include "llvm/ADT/Optional.h" | |
17 #include "llvm/ADT/SmallPtrSet.h" | 19 #include "llvm/ADT/SmallPtrSet.h" |
20 #include "llvm/ADT/SmallVector.h" | |
18 #include "llvm/Analysis/AliasAnalysis.h" | 21 #include "llvm/Analysis/AliasAnalysis.h" |
19 #include "llvm/Analysis/AssumptionCache.h" | 22 #include "llvm/Analysis/AssumptionCache.h" |
20 #include "llvm/Analysis/TargetLibraryInfo.h" | 23 #include "llvm/Analysis/MemoryLocation.h" |
21 #include "llvm/IR/Function.h" | 24 #include "llvm/IR/CallSite.h" |
22 #include "llvm/IR/GetElementPtrTypeIterator.h" | |
23 #include "llvm/IR/Instruction.h" | |
24 #include "llvm/IR/LLVMContext.h" | |
25 #include "llvm/IR/Module.h" | |
26 #include "llvm/IR/PassManager.h" | 25 #include "llvm/IR/PassManager.h" |
27 #include "llvm/Support/ErrorHandling.h" | 26 #include "llvm/Pass.h" |
27 #include <algorithm> | |
28 #include <cstdint> | |
29 #include <memory> | |
30 #include <utility> | |
28 | 31 |
29 namespace llvm { | 32 namespace llvm { |
33 | |
34 struct AAMDNodes; | |
35 class APInt; | |
30 class AssumptionCache; | 36 class AssumptionCache; |
37 class BasicBlock; | |
38 class DataLayout; | |
31 class DominatorTree; | 39 class DominatorTree; |
40 class Function; | |
41 class GEPOperator; | |
32 class LoopInfo; | 42 class LoopInfo; |
43 class PHINode; | |
44 class SelectInst; | |
45 class TargetLibraryInfo; | |
46 class Value; | |
33 | 47 |
34 /// This is the AA result object for the basic, local, and stateless alias | 48 /// This is the AA result object for the basic, local, and stateless alias |
35 /// analysis. It implements the AA query interface in an entirely stateless | 49 /// analysis. It implements the AA query interface in an entirely stateless |
36 /// manner. As one consequence, it is never invalidated. While it does retain | 50 /// manner. As one consequence, it is never invalidated due to IR changes. |
37 /// some storage, that is used as an optimization and not to preserve | 51 /// While it does retain some storage, that is used as an optimization and not |
38 /// information from query to query. | 52 /// to preserve information from query to query. However it does retain handles |
53 /// to various other analyses and must be recomputed when those analyses are. | |
39 class BasicAAResult : public AAResultBase<BasicAAResult> { | 54 class BasicAAResult : public AAResultBase<BasicAAResult> { |
40 friend AAResultBase<BasicAAResult>; | 55 friend AAResultBase<BasicAAResult>; |
41 | 56 |
42 const DataLayout &DL; | 57 const DataLayout &DL; |
43 const TargetLibraryInfo &TLI; | 58 const TargetLibraryInfo &TLI; |
56 LI(Arg.LI) {} | 71 LI(Arg.LI) {} |
57 BasicAAResult(BasicAAResult &&Arg) | 72 BasicAAResult(BasicAAResult &&Arg) |
58 : AAResultBase(std::move(Arg)), DL(Arg.DL), TLI(Arg.TLI), AC(Arg.AC), | 73 : AAResultBase(std::move(Arg)), DL(Arg.DL), TLI(Arg.TLI), AC(Arg.AC), |
59 DT(Arg.DT), LI(Arg.LI) {} | 74 DT(Arg.DT), LI(Arg.LI) {} |
60 | 75 |
76 /// Handle invalidation events in the new pass manager. | |
77 bool invalidate(Function &F, const PreservedAnalyses &PA, | |
78 FunctionAnalysisManager::Invalidator &Inv); | |
79 | |
61 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB); | 80 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB); |
62 | 81 |
63 ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc); | 82 ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc); |
64 | 83 |
65 ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2); | 84 ModRefInfo getModRefInfo(ImmutableCallSite CS1, ImmutableCallSite CS2); |
79 | 98 |
80 private: | 99 private: |
81 // A linear transformation of a Value; this class represents ZExt(SExt(V, | 100 // A linear transformation of a Value; this class represents ZExt(SExt(V, |
82 // SExtBits), ZExtBits) * Scale + Offset. | 101 // SExtBits), ZExtBits) * Scale + Offset. |
83 struct VariableGEPIndex { | 102 struct VariableGEPIndex { |
84 | |
85 // An opaque Value - we can't decompose this further. | 103 // An opaque Value - we can't decompose this further. |
86 const Value *V; | 104 const Value *V; |
87 | 105 |
88 // We need to track what extensions we've done as we consider the same Value | 106 // We need to track what extensions we've done as we consider the same Value |
89 // with different extensions as different variables in a GEP's linear | 107 // with different extensions as different variables in a GEP's linear |
117 // Scaled variable (non-constant) indices. | 135 // Scaled variable (non-constant) indices. |
118 SmallVector<VariableGEPIndex, 4> VarIndices; | 136 SmallVector<VariableGEPIndex, 4> VarIndices; |
119 }; | 137 }; |
120 | 138 |
121 /// Track alias queries to guard against recursion. | 139 /// Track alias queries to guard against recursion. |
122 typedef std::pair<MemoryLocation, MemoryLocation> LocPair; | 140 using LocPair = std::pair<MemoryLocation, MemoryLocation>; |
123 typedef SmallDenseMap<LocPair, AliasResult, 8> AliasCacheTy; | 141 using AliasCacheTy = SmallDenseMap<LocPair, AliasResult, 8>; |
124 AliasCacheTy AliasCache; | 142 AliasCacheTy AliasCache; |
125 | 143 |
126 /// Tracks phi nodes we have visited. | 144 /// Tracks phi nodes we have visited. |
127 /// | 145 /// |
128 /// When interpret "Value" pointer equality as value equality we need to make | 146 /// When interpret "Value" pointer equality as value equality we need to make |
194 }; | 212 }; |
195 | 213 |
196 /// Analysis pass providing a never-invalidated alias analysis result. | 214 /// Analysis pass providing a never-invalidated alias analysis result. |
197 class BasicAA : public AnalysisInfoMixin<BasicAA> { | 215 class BasicAA : public AnalysisInfoMixin<BasicAA> { |
198 friend AnalysisInfoMixin<BasicAA>; | 216 friend AnalysisInfoMixin<BasicAA>; |
217 | |
199 static AnalysisKey Key; | 218 static AnalysisKey Key; |
200 | 219 |
201 public: | 220 public: |
202 typedef BasicAAResult Result; | 221 using Result = BasicAAResult; |
203 | 222 |
204 BasicAAResult run(Function &F, FunctionAnalysisManager &AM); | 223 BasicAAResult run(Function &F, FunctionAnalysisManager &AM); |
205 }; | 224 }; |
206 | 225 |
207 /// Legacy wrapper pass to provide the BasicAAResult object. | 226 /// Legacy wrapper pass to provide the BasicAAResult object. |
226 | 245 |
227 /// A helper for the legacy pass manager to create a \c BasicAAResult object | 246 /// A helper for the legacy pass manager to create a \c BasicAAResult object |
228 /// populated to the best of our ability for a particular function when inside | 247 /// populated to the best of our ability for a particular function when inside |
229 /// of a \c ModulePass or a \c CallGraphSCCPass. | 248 /// of a \c ModulePass or a \c CallGraphSCCPass. |
230 BasicAAResult createLegacyPMBasicAAResult(Pass &P, Function &F); | 249 BasicAAResult createLegacyPMBasicAAResult(Pass &P, Function &F); |
231 } | 250 |
232 | 251 /// This class is a functor to be used in legacy module or SCC passes for |
233 #endif | 252 /// computing AA results for a function. We store the results in fields so that |
253 /// they live long enough to be queried, but we re-use them each time. | |
254 class LegacyAARGetter { | |
255 Pass &P; | |
256 Optional<BasicAAResult> BAR; | |
257 Optional<AAResults> AAR; | |
258 | |
259 public: | |
260 LegacyAARGetter(Pass &P) : P(P) {} | |
261 AAResults &operator()(Function &F) { | |
262 BAR.emplace(createLegacyPMBasicAAResult(P, F)); | |
263 AAR.emplace(createLegacyPMAAResults(P, F, *BAR)); | |
264 return *AAR; | |
265 } | |
266 }; | |
267 | |
268 } // end namespace llvm | |
269 | |
270 #endif // LLVM_ANALYSIS_BASICALIASANALYSIS_H |