/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Analysis/LoopAnalysisManager.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- LoopAnalysisManager.h - Loop analysis management ---------*- 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 | | /// \file |
9 | | /// |
10 | | /// This header provides classes for managing per-loop analyses. These are |
11 | | /// typically used as part of a loop pass pipeline over the loop nests of |
12 | | /// a function. |
13 | | /// |
14 | | /// Loop analyses are allowed to make some simplifying assumptions: |
15 | | /// 1) Loops are, where possible, in simplified form. |
16 | | /// 2) Loops are *always* in LCSSA form. |
17 | | /// 3) A collection of analysis results are available: |
18 | | /// - LoopInfo |
19 | | /// - DominatorTree |
20 | | /// - ScalarEvolution |
21 | | /// - AAManager |
22 | | /// |
23 | | /// The primary mechanism to provide these invariants is the loop pass manager, |
24 | | /// but they can also be manually provided in order to reason about a loop from |
25 | | /// outside of a dedicated pass manager. |
26 | | /// |
27 | | //===----------------------------------------------------------------------===// |
28 | | |
29 | | #ifndef LLVM_ANALYSIS_LOOPANALYSISMANAGER_H |
30 | | #define LLVM_ANALYSIS_LOOPANALYSISMANAGER_H |
31 | | |
32 | | #include "llvm/ADT/PostOrderIterator.h" |
33 | | #include "llvm/ADT/PriorityWorklist.h" |
34 | | #include "llvm/ADT/STLExtras.h" |
35 | | #include "llvm/Analysis/AliasAnalysis.h" |
36 | | #include "llvm/Analysis/BasicAliasAnalysis.h" |
37 | | #include "llvm/Analysis/GlobalsModRef.h" |
38 | | #include "llvm/Analysis/LoopInfo.h" |
39 | | #include "llvm/Analysis/MemorySSA.h" |
40 | | #include "llvm/Analysis/ScalarEvolution.h" |
41 | | #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" |
42 | | #include "llvm/Analysis/TargetLibraryInfo.h" |
43 | | #include "llvm/Analysis/TargetTransformInfo.h" |
44 | | #include "llvm/IR/Dominators.h" |
45 | | #include "llvm/IR/PassManager.h" |
46 | | |
47 | | namespace llvm { |
48 | | |
49 | | /// The adaptor from a function pass to a loop pass computes these analyses and |
50 | | /// makes them available to the loop passes "for free". Each loop pass is |
51 | | /// expected expected to update these analyses if necessary to ensure they're |
52 | | /// valid after it runs. |
53 | | struct LoopStandardAnalysisResults { |
54 | | AAResults &AA; |
55 | | AssumptionCache ∾ |
56 | | DominatorTree &DT; |
57 | | LoopInfo &LI; |
58 | | ScalarEvolution &SE; |
59 | | TargetLibraryInfo &TLI; |
60 | | TargetTransformInfo &TTI; |
61 | | MemorySSA *MSSA; |
62 | | }; |
63 | | |
64 | | /// Enables memory ssa as a dependency for loop passes. |
65 | | extern cl::opt<bool> EnableMSSALoopDependency; |
66 | | |
67 | | /// Extern template declaration for the analysis set for this IR unit. |
68 | | extern template class AllAnalysesOn<Loop>; |
69 | | |
70 | | extern template class AnalysisManager<Loop, LoopStandardAnalysisResults &>; |
71 | | /// The loop analysis manager. |
72 | | /// |
73 | | /// See the documentation for the AnalysisManager template for detail |
74 | | /// documentation. This typedef serves as a convenient way to refer to this |
75 | | /// construct in the adaptors and proxies used to integrate this into the larger |
76 | | /// pass manager infrastructure. |
77 | | typedef AnalysisManager<Loop, LoopStandardAnalysisResults &> |
78 | | LoopAnalysisManager; |
79 | | |
80 | | /// A proxy from a \c LoopAnalysisManager to a \c Function. |
81 | | typedef InnerAnalysisManagerProxy<LoopAnalysisManager, Function> |
82 | | LoopAnalysisManagerFunctionProxy; |
83 | | |
84 | | /// A specialized result for the \c LoopAnalysisManagerFunctionProxy which |
85 | | /// retains a \c LoopInfo reference. |
86 | | /// |
87 | | /// This allows it to collect loop objects for which analysis results may be |
88 | | /// cached in the \c LoopAnalysisManager. |
89 | | template <> class LoopAnalysisManagerFunctionProxy::Result { |
90 | | public: |
91 | | explicit Result(LoopAnalysisManager &InnerAM, LoopInfo &LI) |
92 | 1.09k | : InnerAM(&InnerAM), LI(&LI) {} |
93 | 2.18k | Result(Result &&Arg) : InnerAM(std::move(Arg.InnerAM)), LI(Arg.LI) { |
94 | 2.18k | // We have to null out the analysis manager in the moved-from state |
95 | 2.18k | // because we are taking ownership of the responsibilty to clear the |
96 | 2.18k | // analysis state. |
97 | 2.18k | Arg.InnerAM = nullptr; |
98 | 2.18k | } |
99 | 0 | Result &operator=(Result &&RHS) { |
100 | 0 | InnerAM = RHS.InnerAM; |
101 | 0 | LI = RHS.LI; |
102 | 0 | // We have to null out the analysis manager in the moved-from state |
103 | 0 | // because we are taking ownership of the responsibilty to clear the |
104 | 0 | // analysis state. |
105 | 0 | RHS.InnerAM = nullptr; |
106 | 0 | return *this; |
107 | 0 | } |
108 | 3.27k | ~Result() { |
109 | 3.27k | // InnerAM is cleared in a moved from state where there is nothing to do. |
110 | 3.27k | if (!InnerAM) |
111 | 2.27k | return; |
112 | 995 | |
113 | 995 | // Clear out the analysis manager if we're being destroyed -- it means we |
114 | 995 | // didn't even see an invalidate call when we got invalidated. |
115 | 995 | InnerAM->clear(); |
116 | 995 | } |
117 | | |
118 | | /// Accessor for the analysis manager. |
119 | 1.59k | LoopAnalysisManager &getManager() { return *InnerAM; } |
120 | | |
121 | | /// Handler for invalidation of the proxy for a particular function. |
122 | | /// |
123 | | /// If the proxy, \c LoopInfo, and associated analyses are preserved, this |
124 | | /// will merely forward the invalidation event to any cached loop analysis |
125 | | /// results for loops within this function. |
126 | | /// |
127 | | /// If the necessary loop infrastructure is not preserved, this will forcibly |
128 | | /// clear all of the cached analysis results that are keyed on the \c |
129 | | /// LoopInfo for this function. |
130 | | bool invalidate(Function &F, const PreservedAnalyses &PA, |
131 | | FunctionAnalysisManager::Invalidator &Inv); |
132 | | |
133 | | private: |
134 | | LoopAnalysisManager *InnerAM; |
135 | | LoopInfo *LI; |
136 | | }; |
137 | | |
138 | | /// Provide a specialized run method for the \c LoopAnalysisManagerFunctionProxy |
139 | | /// so it can pass the \c LoopInfo to the result. |
140 | | template <> |
141 | | LoopAnalysisManagerFunctionProxy::Result |
142 | | LoopAnalysisManagerFunctionProxy::run(Function &F, FunctionAnalysisManager &AM); |
143 | | |
144 | | // Ensure the \c LoopAnalysisManagerFunctionProxy is provided as an extern |
145 | | // template. |
146 | | extern template class InnerAnalysisManagerProxy<LoopAnalysisManager, Function>; |
147 | | |
148 | | extern template class OuterAnalysisManagerProxy<FunctionAnalysisManager, Loop, |
149 | | LoopStandardAnalysisResults &>; |
150 | | /// A proxy from a \c FunctionAnalysisManager to a \c Loop. |
151 | | typedef OuterAnalysisManagerProxy<FunctionAnalysisManager, Loop, |
152 | | LoopStandardAnalysisResults &> |
153 | | FunctionAnalysisManagerLoopProxy; |
154 | | |
155 | | /// Returns the minimum set of Analyses that all loop passes must preserve. |
156 | | PreservedAnalyses getLoopPassPreservedAnalyses(); |
157 | | } |
158 | | |
159 | | #endif // LLVM_ANALYSIS_LOOPANALYSISMANAGER_H |