LLVM  9.0.0svn
LoopAnalysisManager.h
Go to the documentation of this file.
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 
34 #include "llvm/ADT/STLExtras.h"
38 #include "llvm/Analysis/LoopInfo.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.
62 };
63 
64 /// Extern template declaration for the analysis set for this IR unit.
65 extern template class AllAnalysesOn<Loop>;
66 
68 /// The loop analysis manager.
69 ///
70 /// See the documentation for the AnalysisManager template for detail
71 /// documentation. This typedef serves as a convenient way to refer to this
72 /// construct in the adaptors and proxies used to integrate this into the larger
73 /// pass manager infrastructure.
76 
77 /// A proxy from a \c LoopAnalysisManager to a \c Function.
80 
81 /// A specialized result for the \c LoopAnalysisManagerFunctionProxy which
82 /// retains a \c LoopInfo reference.
83 ///
84 /// This allows it to collect loop objects for which analysis results may be
85 /// cached in the \c LoopAnalysisManager.
87 public:
88  explicit Result(LoopAnalysisManager &InnerAM, LoopInfo &LI)
89  : InnerAM(&InnerAM), LI(&LI) {}
90  Result(Result &&Arg) : InnerAM(std::move(Arg.InnerAM)), LI(Arg.LI) {
91  // We have to null out the analysis manager in the moved-from state
92  // because we are taking ownership of the responsibilty to clear the
93  // analysis state.
94  Arg.InnerAM = nullptr;
95  }
97  InnerAM = RHS.InnerAM;
98  LI = RHS.LI;
99  // We have to null out the analysis manager in the moved-from state
100  // because we are taking ownership of the responsibilty to clear the
101  // analysis state.
102  RHS.InnerAM = nullptr;
103  return *this;
104  }
106  // InnerAM is cleared in a moved from state where there is nothing to do.
107  if (!InnerAM)
108  return;
109 
110  // Clear out the analysis manager if we're being destroyed -- it means we
111  // didn't even see an invalidate call when we got invalidated.
112  InnerAM->clear();
113  }
114 
115  /// Accessor for the analysis manager.
116  LoopAnalysisManager &getManager() { return *InnerAM; }
117 
118  /// Handler for invalidation of the proxy for a particular function.
119  ///
120  /// If the proxy, \c LoopInfo, and associated analyses are preserved, this
121  /// will merely forward the invalidation event to any cached loop analysis
122  /// results for loops within this function.
123  ///
124  /// If the necessary loop infrastructure is not preserved, this will forcibly
125  /// clear all of the cached analysis results that are keyed on the \c
126  /// LoopInfo for this function.
127  bool invalidate(Function &F, const PreservedAnalyses &PA,
129 
130 private:
131  LoopAnalysisManager *InnerAM;
132  LoopInfo *LI;
133 };
134 
135 /// Provide a specialized run method for the \c LoopAnalysisManagerFunctionProxy
136 /// so it can pass the \c LoopInfo to the result.
137 template <>
140 
141 // Ensure the \c LoopAnalysisManagerFunctionProxy is provided as an extern
142 // template.
144 
147 /// A proxy from a \c FunctionAnalysisManager to a \c Loop.
149  LoopStandardAnalysisResults &>
151 
152 /// Returns the minimum set of Analyses that all loop passes must preserve.
154 }
155 
156 #endif // LLVM_ANALYSIS_LOOPANALYSISMANAGER_H
This file provides a priority worklist.
LoopAnalysisManager & getManager()
Accessor for the analysis manager.
PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This is the interface for a simple mod/ref and alias analysis over globals.
InnerAnalysisManagerProxy< LoopAnalysisManager, Function > LoopAnalysisManagerFunctionProxy
A proxy from a LoopAnalysisManager to a Function.
The main scalar evolution driver.
A cache of @llvm.assume calls within a function.
OuterAnalysisManagerProxy< FunctionAnalysisManager, Loop, LoopStandardAnalysisResults & > FunctionAnalysisManagerLoopProxy
A proxy from a FunctionAnalysisManager to a Loop.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
F(f)
Definition: BitVector.h:937
This is the interface for a SCEV-based alias analysis.
Encapsulates MemorySSA, including all data associated with memory accesses.
Definition: MemorySSA.h:703
Result(LoopAnalysisManager &InnerAM, LoopInfo &LI)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:144
A specialized result for the LoopAnalysisManagerFunctionProxy which retains a LoopInfo reference...
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Definition: PassManager.h:1025
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Definition: PassManager.h:1160
Provides information about what library functions are available for the current target.
Result run(IRUnitT &IR, AnalysisManager< IRUnitT, ExtraArgTs... > &AM, ExtraArgTs...)
Run the analysis pass and create our proxy result object.
Definition: PassManager.h:1107
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:465
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:648
This templated class represents "all analyses that operate over <a particular IR unit>" (e...
Definition: PassManager.h:91
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
This is the interface for LLVM&#39;s primary stateless and local alias analysis.
A container for analyses that lazily runs them and caches their results.
This pass exposes codegen information to IR-level passes.
This header defines various interfaces for pass management in LLVM.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:1044