LLVM  4.0.0
LoopAnalysisManager.h
Go to the documentation of this file.
1 //===- LoopAnalysisManager.h - Loop analysis management ---------*- 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 ///
11 /// This header provides classes for managing per-loop analyses. These are
12 /// typically used as part of a loop pass pipeline over the loop nests of
13 /// a function.
14 ///
15 /// Loop analyses are allowed to make some simplifying assumptions:
16 /// 1) Loops are, where possible, in simplified form.
17 /// 2) Loops are *always* in LCSSA form.
18 /// 3) A collection of analysis results are available:
19 /// - LoopInfo
20 /// - DominatorTree
21 /// - ScalarEvolution
22 /// - AAManager
23 ///
24 /// The primary mechanism to provide these invariants is the loop pass manager,
25 /// but they can also be manually provided in order to reason about a loop from
26 /// outside of a dedicated pass manager.
27 ///
28 //===----------------------------------------------------------------------===//
29 
30 #ifndef LLVM_ANALYSIS_LOOPANALYSISMANAGER_H
31 #define LLVM_ANALYSIS_LOOPANALYSISMANAGER_H
32 
35 #include "llvm/ADT/STLExtras.h"
39 #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.
61 };
62 
63 /// Extern template declaration for the analysis set for this IR unit.
64 extern template class AllAnalysesOn<Loop>;
65 
67 /// \brief The loop analysis manager.
68 ///
69 /// See the documentation for the AnalysisManager template for detail
70 /// documentation. This typedef serves as a convenient way to refer to this
71 /// construct in the adaptors and proxies used to integrate this into the larger
72 /// pass manager infrastructure.
75 
76 /// A proxy from a \c LoopAnalysisManager to a \c Function.
79 
80 /// A specialized result for the \c LoopAnalysisManagerFunctionProxy which
81 /// retains a \c LoopInfo reference.
82 ///
83 /// This allows it to collect loop objects for which analysis results may be
84 /// cached in the \c LoopAnalysisManager.
86 public:
87  explicit Result(LoopAnalysisManager &InnerAM, LoopInfo &LI)
88  : InnerAM(&InnerAM), LI(&LI) {}
89  Result(Result &&Arg) : InnerAM(std::move(Arg.InnerAM)), LI(Arg.LI) {
90  // We have to null out the analysis manager in the moved-from state
91  // because we are taking ownership of the responsibilty to clear the
92  // analysis state.
93  Arg.InnerAM = nullptr;
94  }
96  InnerAM = RHS.InnerAM;
97  LI = RHS.LI;
98  // We have to null out the analysis manager in the moved-from state
99  // because we are taking ownership of the responsibilty to clear the
100  // analysis state.
101  RHS.InnerAM = nullptr;
102  return *this;
103  }
105  // InnerAM is cleared in a moved from state where there is nothing to do.
106  if (!InnerAM)
107  return;
108 
109  // Clear out the analysis manager if we're being destroyed -- it means we
110  // didn't even see an invalidate call when we got invalidated.
111  InnerAM->clear();
112  }
113 
114  /// Accessor for the analysis manager.
115  LoopAnalysisManager &getManager() { return *InnerAM; }
116 
117  /// Handler for invalidation of the proxy for a particular function.
118  ///
119  /// If the proxy, \c LoopInfo, and associated analyses are preserved, this
120  /// will merely forward the invalidation event to any cached loop analysis
121  /// results for loops within this function.
122  ///
123  /// If the necessary loop infrastructure is not preserved, this will forcibly
124  /// clear all of the cached analysis results that are keyed on the \c
125  /// LoopInfo for this function.
126  bool invalidate(Function &F, const PreservedAnalyses &PA,
128 
129 private:
130  LoopAnalysisManager *InnerAM;
131  LoopInfo *LI;
132 };
133 
134 /// Provide a specialized run method for the \c LoopAnalysisManagerFunctionProxy
135 /// so it can pass the \c LoopInfo to the result.
136 template <>
139 
140 // Ensure the \c LoopAnalysisManagerFunctionProxy is provided as an extern
141 // template.
143 
146 /// A proxy from a \c FunctionAnalysisManager to a \c Loop.
150 
151 /// Returns the minimum set of Analyses that all loop passes must preserve.
153 }
154 
155 #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 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.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Definition: PassManager.h:886
A cache of .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...
This is the interface for a SCEV-based alias analysis.
Result(LoopAnalysisManager &InnerAM, LoopInfo &LI)
#define F(x, y, z)
Definition: MD5.cpp:51
Result run(IRUnitT &IR, AnalysisManager< IRUnitT, ExtraArgTs...> &AM, ExtraArgTs...)
Run the analysis pass and create our proxy result object.
Definition: PassManager.h:965
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:96
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:107
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:1017
Provides information about what library functions are available for the current target.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:368
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:525
This templated class represents "all analyses that operate over \<a particular IR unit\>" (e...
Definition: PassManager.h:361
This is the interface for LLVM'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:905