LLVM 22.0.0git
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
32#include "llvm/IR/PassManager.h"
34
35namespace llvm {
36
37class AAResults;
38class AssumptionCache;
39class BlockFrequencyInfo;
40class BranchProbabilityInfo;
41class DominatorTree;
42class Function;
43class Loop;
44class LoopInfo;
45class MemorySSA;
46class ScalarEvolution;
47class TargetLibraryInfo;
48class TargetTransformInfo;
49
50/// The adaptor from a function pass to a loop pass computes these analyses and
51/// makes them available to the loop passes "for free". Each loop pass is
52/// expected to update these analyses if necessary to ensure they're
53/// valid after it runs.
65};
66
67/// Extern template declaration for the analysis set for this IR unit.
68extern template class LLVM_TEMPLATE_ABI AllAnalysesOn<Loop>;
69
70extern template class LLVM_TEMPLATE_ABI
72/// The loop analysis manager.
73///
74/// See the documentation for the AnalysisManager template for detail
75/// documentation. This typedef serves as a convenient way to refer to this
76/// construct in the adaptors and proxies used to integrate this into the larger
77/// pass manager infrastructure.
80
81/// A proxy from a \c LoopAnalysisManager to a \c Function.
84
85/// A specialized result for the \c LoopAnalysisManagerFunctionProxy which
86/// retains a \c LoopInfo reference.
87///
88/// This allows it to collect loop objects for which analysis results may be
89/// cached in the \c LoopAnalysisManager.
91public:
92 explicit Result(LoopAnalysisManager &InnerAM, LoopInfo &LI)
93 : InnerAM(&InnerAM), LI(&LI) {}
95 : InnerAM(std::move(Arg.InnerAM)), LI(Arg.LI), MSSAUsed(Arg.MSSAUsed) {
96 // We have to null out the analysis manager in the moved-from state
97 // because we are taking ownership of the responsibilty to clear the
98 // analysis state.
99 Arg.InnerAM = nullptr;
100 }
102 InnerAM = RHS.InnerAM;
103 LI = RHS.LI;
104 MSSAUsed = RHS.MSSAUsed;
105 // We have to null out the analysis manager in the moved-from state
106 // because we are taking ownership of the responsibilty to clear the
107 // analysis state.
108 RHS.InnerAM = nullptr;
109 return *this;
110 }
112 // InnerAM is cleared in a moved from state where there is nothing to do.
113 if (!InnerAM)
114 return;
115
116 // Clear out the analysis manager if we're being destroyed -- it means we
117 // didn't even see an invalidate call when we got invalidated.
118 InnerAM->clear();
119 }
120
121 /// Mark MemorySSA as used so we can invalidate self if MSSA is invalidated.
122 void markMSSAUsed() { MSSAUsed = true; }
123
124 /// Accessor for the analysis manager.
125 LoopAnalysisManager &getManager() { return *InnerAM; }
126
127 /// Handler for invalidation of the proxy for a particular function.
128 ///
129 /// If the proxy, \c LoopInfo, and associated analyses are preserved, this
130 /// will merely forward the invalidation event to any cached loop analysis
131 /// results for loops within this function.
132 ///
133 /// If the necessary loop infrastructure is not preserved, this will forcibly
134 /// clear all of the cached analysis results that are keyed on the \c
135 /// LoopInfo for this function.
138
139private:
140 LoopAnalysisManager *InnerAM;
141 LoopInfo *LI;
142 bool MSSAUsed = false;
143};
144
145/// Provide a specialized run method for the \c LoopAnalysisManagerFunctionProxy
146/// so it can pass the \c LoopInfo to the result.
147template <>
150
151// Ensure the \c LoopAnalysisManagerFunctionProxy is provided as an extern
152// template.
154
155extern template class LLVM_TEMPLATE_ABI OuterAnalysisManagerProxy<
157/// A proxy from a \c FunctionAnalysisManager to a \c Loop.
161
162/// Returns the minimum set of Analyses that all loop passes must preserve.
164}
165
166#endif // LLVM_ANALYSIS_LOOPANALYSISMANAGER_H
#define LLVM_ABI
Definition: Compiler.h:213
#define LLVM_TEMPLATE_ABI
Definition: Compiler.h:214
early cse Early CSE w MemorySSA
Definition: EarlyCSE.cpp:1962
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition: MD5.cpp:55
Value * RHS
A private abstract base class describing the concept of an individual alias analysis implementation.
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
Definition: Analysis.h:50
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:294
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:255
A cache of @llvm.assume calls within a function.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Analysis providing branch probability information.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:165
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:585
Result run(IRUnitT &IR, AnalysisManager< IRUnitT, ExtraArgTs... > &AM, ExtraArgTs...)
Run the analysis pass and create our proxy result object.
Definition: PassManager.h:646
A specialized result for the LoopAnalysisManagerFunctionProxy which retains a LoopInfo reference.
LLVM_ABI bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handler for invalidation of the proxy for a particular function.
LoopAnalysisManager & getManager()
Accessor for the analysis manager.
void markMSSAUsed()
Mark MemorySSA as used so we can invalidate self if MSSA is invalidated.
Result(LoopAnalysisManager &InnerAM, LoopInfo &LI)
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:40
Encapsulates MemorySSA, including all data associated with memory accesses.
Definition: MemorySSA.h:702
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Definition: PassManager.h:716
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:112
The main scalar evolution driver.
Provides information about what library functions are available for the current target.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Definition: PassManager.h:564
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
OuterAnalysisManagerProxy< FunctionAnalysisManager, Loop, LoopStandardAnalysisResults & > FunctionAnalysisManagerLoopProxy
A proxy from a FunctionAnalysisManager to a Loop.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
LLVM_ABI PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:851
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...