LLVM 24.0.0git
MachinePassManager.h
Go to the documentation of this file.
1//===- PassManager.h --- Pass management for CodeGen ------------*- 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//
9// This header defines the pass manager interface for codegen. The codegen
10// pipeline consists of only machine function passes. There is no container
11// relationship between IR module/function and machine function in terms of pass
12// manager organization. So there is no need for adaptor classes (for example
13// ModuleToMachineFunctionAdaptor). Since invalidation could only happen among
14// machine function passes, there is no proxy classes to handle cross-IR-unit
15// invalidation. IR analysis results are provided for machine function passes by
16// their respective analysis managers such as ModuleAnalysisManager and
17// FunctionAnalysisManager.
18//
19//===----------------------------------------------------------------------===//
20
21#ifndef LLVM_CODEGEN_MACHINEPASSMANAGER_H
22#define LLVM_CODEGEN_MACHINEPASSMANAGER_H
23
27#include "llvm/IR/PassManager.h"
30#include "llvm/Support/Error.h"
31
32namespace llvm {
33class Module;
34class Function;
35
38
39template <>
40LLVM_ABI bool MachineFunctionAnalysisManagerModuleProxy::Result::invalidate(
41 Module &M, const PreservedAnalyses &PA,
42 ModuleAnalysisManager::Invalidator &Inv);
44 Module>;
47
48template <>
49LLVM_ABI bool MachineFunctionAnalysisManagerFunctionProxy::Result::invalidate(
50 Function &F, const PreservedAnalyses &PA,
51 FunctionAnalysisManager::Invalidator &Inv);
53 Function>;
54
55extern template class LLVM_TEMPLATE_ABI
57/// Provide the \c ModuleAnalysisManager to \c Function proxy.
60
63public:
64 class Result {
65 public:
66 explicit Result(FunctionAnalysisManager &FAM) : FAM(&FAM) {}
67
68 Result(Result &&Arg) : FAM(std::move(Arg.FAM)) {
69 // We have to null out the analysis manager in the moved-from state
70 // because we are taking ownership of the responsibility to clear the
71 // analysis state.
72 Arg.FAM = nullptr;
73 }
74
76 FAM = RHS.FAM;
77 // We have to null out the analysis manager in the moved-from state
78 // because we are taking ownership of the responsibility to clear the
79 // analysis state.
80 RHS.FAM = nullptr;
81 return *this;
82 }
83
84 /// Accessor for the analysis manager.
86
87 /// Handler for invalidation of the outer IR unit, \c IRUnitT.
88 ///
89 /// If the proxy analysis itself is not preserved, we assume that the set of
90 /// inner IR objects contained in IRUnit may have changed. In this case,
91 /// we have to call \c clear() on the inner analysis manager, as it may now
92 /// have stale pointers to its inner IR objects.
93 ///
94 /// Regardless of whether the proxy analysis is marked as preserved, all of
95 /// the analyses in the inner analysis manager are potentially invalidated
96 /// based on the set of preserved analyses.
97 LLVM_ABI bool invalidate(MachineFunction &IR, const PreservedAnalyses &PA,
98 MachineFunctionAnalysisManager::Invalidator &Inv);
99
100 private:
102 };
103
107
108 /// Run the analysis pass and create our proxy result object.
109 ///
110 /// This doesn't do any interesting work; it is primarily used to insert our
111 /// proxy result object into the outer analysis cache so that we can proxy
112 /// invalidation to the inner analysis manager.
116
118
119private:
121};
122
125public:
128
131
132 /// Runs the function pass across every function in the function.
134 LLVM_ABI void
135 printPipeline(raw_ostream &OS,
136 function_ref<StringRef(StringRef)> MapClassName2PassName);
137
138private:
139 PassConceptT::unique_ptr Pass;
140};
141
142template <typename MachineFunctionPassT>
143FunctionToMachineFunctionPassAdaptor
145 using PassModelT = detail::PassModel<MachineFunction, MachineFunctionPassT,
148 PassModelT::create(std::move(Pass)));
149}
150
151template <>
154extern template class PassManager<MachineFunction>;
155
156/// Convenience typedef for a pass manager over functions.
158
159/// Returns the minimum set of Analyses that all machine function passes must
160/// preserve.
162
163} // end namespace llvm
164
165#endif // LLVM_CODEGEN_MACHINEPASSMANAGER_H
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_TEMPLATE_ABI
Definition Compiler.h:212
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
This header defines various interfaces for pass management in LLVM.
Legalize the Machine IR a function s Machine IR
Definition Legalizer.cpp:86
return Result
#define F(x, y, z)
Definition MD5.cpp:54
FunctionAnalysisManager FAM
This header provides internal APIs and implementation details used by the pass management interfaces ...
This file defines the SmallVector class.
Value * RHS
A container for analyses that lazily runs them and caches their results.
FunctionAnalysisManager & getManager()
Accessor for the analysis manager.
FunctionAnalysisManagerMachineFunctionProxy(FunctionAnalysisManager &FAM)
Result run(MachineFunction &, MachineFunctionAnalysisManager &)
Run the analysis pass and create our proxy result object.
FunctionToMachineFunctionPassAdaptor(PassConceptT::unique_ptr Pass)
detail::PassConcept< MachineFunction, MachineFunctionAnalysisManager > PassConceptT
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Manages a sequence of passes over a particular unit of IR.
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
Pass interface - Implemented by all 'passes'.
Definition Pass.h:97
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Template for the abstract base class used to dispatch over pass objects.
A template wrapper used to implement PassConcept.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
FunctionToMachineFunctionPassAdaptor createFunctionToMachineFunctionPassAdaptor(MachineFunctionPassT &&Pass)
InnerAnalysisManagerProxy< MachineFunctionAnalysisManager, Function > MachineFunctionAnalysisManagerFunctionProxy
InnerAnalysisManagerProxy< MachineFunctionAnalysisManager, Module > MachineFunctionAnalysisManagerModuleProxy
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:1933
PassManager< MachineFunction > MachineFunctionPassManager
Convenience typedef for a pass manager over functions.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
A CRTP mix-in for passes that should not be skipped.