LLVM  14.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 
33 #include "llvm/IR/PassManager.h"
34 
35 namespace llvm {
36 
37 class AAResults;
38 class AssumptionCache;
39 class DominatorTree;
40 class Function;
41 class Loop;
42 class LoopInfo;
43 class MemorySSA;
44 class ScalarEvolution;
45 class TargetLibraryInfo;
46 class TargetTransformInfo;
47 
48 /// The adaptor from a function pass to a loop pass computes these analyses and
49 /// makes them available to the loop passes "for free". Each loop pass is
50 /// expected to update these analyses if necessary to ensure they're
51 /// valid after it runs.
63 };
64 
65 /// Extern template declaration for the analysis set for this IR unit.
66 extern template class AllAnalysesOn<Loop>;
67 
69 /// The loop analysis manager.
70 ///
71 /// See the documentation for the AnalysisManager template for detail
72 /// documentation. This typedef serves as a convenient way to refer to this
73 /// construct in the adaptors and proxies used to integrate this into the larger
74 /// pass manager infrastructure.
77 
78 /// A proxy from a \c LoopAnalysisManager to a \c Function.
81 
82 /// A specialized result for the \c LoopAnalysisManagerFunctionProxy which
83 /// retains a \c LoopInfo reference.
84 ///
85 /// This allows it to collect loop objects for which analysis results may be
86 /// cached in the \c LoopAnalysisManager.
88 public:
89  explicit Result(LoopAnalysisManager &InnerAM, LoopInfo &LI)
90  : InnerAM(&InnerAM), LI(&LI), MSSAUsed(false) {}
92  : InnerAM(std::move(Arg.InnerAM)), LI(Arg.LI), MSSAUsed(Arg.MSSAUsed) {
93  // We have to null out the analysis manager in the moved-from state
94  // because we are taking ownership of the responsibilty to clear the
95  // analysis state.
96  Arg.InnerAM = nullptr;
97  }
99  InnerAM = RHS.InnerAM;
100  LI = RHS.LI;
101  MSSAUsed = RHS.MSSAUsed;
102  // We have to null out the analysis manager in the moved-from state
103  // because we are taking ownership of the responsibilty to clear the
104  // analysis state.
105  RHS.InnerAM = nullptr;
106  return *this;
107  }
109  // InnerAM is cleared in a moved from state where there is nothing to do.
110  if (!InnerAM)
111  return;
112 
113  // Clear out the analysis manager if we're being destroyed -- it means we
114  // didn't even see an invalidate call when we got invalidated.
115  InnerAM->clear();
116  }
117 
118  /// Mark MemorySSA as used so we can invalidate self if MSSA is invalidated.
119  void markMSSAUsed() { MSSAUsed = true; }
120 
121  /// Accessor for the analysis manager.
122  LoopAnalysisManager &getManager() { return *InnerAM; }
123 
124  /// Handler for invalidation of the proxy for a particular function.
125  ///
126  /// If the proxy, \c LoopInfo, and associated analyses are preserved, this
127  /// will merely forward the invalidation event to any cached loop analysis
128  /// results for loops within this function.
129  ///
130  /// If the necessary loop infrastructure is not preserved, this will forcibly
131  /// clear all of the cached analysis results that are keyed on the \c
132  /// LoopInfo for this function.
133  bool invalidate(Function &F, const PreservedAnalyses &PA,
135 
136 private:
137  LoopAnalysisManager *InnerAM;
138  LoopInfo *LI;
139  bool MSSAUsed;
140 };
141 
142 /// Provide a specialized run method for the \c LoopAnalysisManagerFunctionProxy
143 /// so it can pass the \c LoopInfo to the result.
144 template <>
147 
148 // Ensure the \c LoopAnalysisManagerFunctionProxy is provided as an extern
149 // template.
151 
154 /// A proxy from a \c FunctionAnalysisManager to a \c Loop.
158 
159 /// Returns the minimum set of Analyses that all loop passes must preserve.
161 }
162 
163 #endif // LLVM_ANALYSIS_LOOPANALYSISMANAGER_H
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm::OuterAnalysisManagerProxy
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Definition: PassManager.h:1065
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::LoopStandardAnalysisResults::AC
AssumptionCache & AC
Definition: LoopAnalysisManager.h:54
llvm::Function
Definition: Function.h:62
llvm::Loop
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:530
llvm::LoopAnalysisManagerFunctionProxy::Result::Result
Result(LoopAnalysisManager &InnerAM, LoopInfo &LI)
Definition: LoopAnalysisManager.h:89
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:168
llvm::InnerAnalysisManagerProxy::Result
Definition: PassManager.h:944
llvm::AllAnalysesOn
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
Definition: PassManager.h:93
llvm::ScalarEvolution
The main scalar evolution driver.
Definition: ScalarEvolution.h:460
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:151
llvm::LoopAnalysisManagerFunctionProxy::Result::~Result
~Result()
Definition: LoopAnalysisManager.h:108
llvm::LoopStandardAnalysisResults
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
Definition: LoopAnalysisManager.h:52
llvm::LoopStandardAnalysisResults::DT
DominatorTree & DT
Definition: LoopAnalysisManager.h:55
F
#define F(x, y, z)
Definition: MD5.cpp:56
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
llvm::BlockFrequencyInfo
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Definition: BlockFrequencyInfo.h:37
llvm::AAResults
Definition: AliasAnalysis.h:508
llvm::BranchProbabilityInfo
Analysis providing branch probability information.
Definition: BranchProbabilityInfo.h:115
false
Definition: StackSlotColoring.cpp:142
llvm::LoopStandardAnalysisResults::BPI
BranchProbabilityInfo * BPI
Definition: LoopAnalysisManager.h:61
llvm::LoopAnalysisManagerFunctionProxy::Result::getManager
LoopAnalysisManager & getManager()
Accessor for the analysis manager.
Definition: LoopAnalysisManager.h:122
llvm::AnalysisManager::Invalidator
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:670
llvm::getLoopPassPreservedAnalyses
PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
Definition: LoopAnalysisManager.cpp:140
llvm::MemorySSA
Encapsulates MemorySSA, including all data associated with memory accesses.
Definition: MemorySSA.h:705
llvm::move
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:1609
llvm::FunctionAnalysisManagerLoopProxy
OuterAnalysisManagerProxy< FunctionAnalysisManager, Loop, LoopStandardAnalysisResults & > FunctionAnalysisManagerLoopProxy
A proxy from a FunctionAnalysisManager to a Loop.
Definition: LoopAnalysisManager.h:157
llvm::LoopAnalysisManagerFunctionProxy::Result::operator=
Result & operator=(Result &&RHS)
Definition: LoopAnalysisManager.h:98
llvm::LoopInfo
Definition: LoopInfo.h:1083
llvm::AssumptionCache
A cache of @llvm.assume calls within a function.
Definition: AssumptionCache.h:41
llvm::LoopAnalysisManagerFunctionProxy
InnerAnalysisManagerProxy< LoopAnalysisManager, Function > LoopAnalysisManagerFunctionProxy
A proxy from a LoopAnalysisManager to a Function.
Definition: LoopAnalysisManager.h:80
llvm::LoopStandardAnalysisResults::LI
LoopInfo & LI
Definition: LoopAnalysisManager.h:56
llvm::LoopStandardAnalysisResults::BFI
BlockFrequencyInfo * BFI
Definition: LoopAnalysisManager.h:60
std
Definition: BitVector.h:838
llvm::LoopStandardAnalysisResults::TTI
TargetTransformInfo & TTI
Definition: LoopAnalysisManager.h:59
llvm::LoopAnalysisManagerFunctionProxy::Result::markMSSAUsed
void markMSSAUsed()
Mark MemorySSA as used so we can invalidate self if MSSA is invalidated.
Definition: LoopAnalysisManager.h:119
PassManager.h
llvm::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:221
llvm::LoopStandardAnalysisResults::SE
ScalarEvolution & SE
Definition: LoopAnalysisManager.h:57
llvm::LoopStandardAnalysisResults::AA
AAResults & AA
Definition: LoopAnalysisManager.h:53
llvm::LoopAnalysisManagerFunctionProxy::Result::Result
Result(Result &&Arg)
Definition: LoopAnalysisManager.h:91
PostOrderIterator.h
llvm::LoopAnalysisManagerFunctionProxy::Result
A specialized result for the LoopAnalysisManagerFunctionProxy which retains a LoopInfo reference.
Definition: LoopAnalysisManager.h:87
llvm::FunctionAnalysisManager
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Definition: PassManager.h:921
llvm::LoopAnalysisManager
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
Definition: LoopAnalysisManager.h:76
llvm::LoopStandardAnalysisResults::MSSA
MemorySSA * MSSA
Definition: LoopAnalysisManager.h:62
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:940
llvm::InnerAnalysisManagerProxy::run
Result run(IRUnitT &IR, AnalysisManager< IRUnitT, ExtraArgTs... > &AM, ExtraArgTs...)
Run the analysis pass and create our proxy result object.
Definition: PassManager.h:1003
MemorySSA
early cse Early CSE w MemorySSA
Definition: EarlyCSE.cpp:1751
llvm::LoopStandardAnalysisResults::TLI
TargetLibraryInfo & TLI
Definition: LoopAnalysisManager.h:58
llvm::codeview::PublicSymFlags::Function
@ Function