LLVM 20.0.0git
TargetPassRegistry.inc
Go to the documentation of this file.
1//===- TargetPassRegistry.inc - Registry of passes --------------*- 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 file is used as the registry of passes in registerPassBuilderCallbacks
10// Just put the following lines in the body of registerPassBuilderCallbacks:
11// #define GET_PASS_REGISTRY "<Target>PassRegistry.def"
12// #include "llvm/Passes/TargetPassRegistry.inc"
13//
14//===----------------------------------------------------------------------===//
15
16// NOTE: NO INCLUDE GUARD DESIRED!
17
18#ifdef GET_PASS_REGISTRY
19
20#if !__has_include(GET_PASS_REGISTRY)
21#error "must provide <Target>PassRegistry.def"
22#endif
23
24auto *PIC = PB.getPassInstrumentationCallbacks();
25if (PIC) {
26 PIC->registerClassToPassNameCallback([this, PIC]() {
27 // MSVC requires this to be captured if it's used inside decltype.
28 // Other compilers consider it an unused lambda capture.
29 (void)this;
30#define ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS) \
31 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
32#define ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CLASS) \
33 PIC->addClassToPassName(CLASS, NAME);
34
35#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
36 ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
37#define MODULE_PASS(NAME, CREATE_PASS) \
38 ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
39#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
40 ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CLASS)
41#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
42 ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
43#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
44 ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
45#define FUNCTION_PASS(NAME, CREATE_PASS) \
46 ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
47#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
48 ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CLASS)
49#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
50 ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
51#define LOOP_PASS(NAME, CREATE_PASS) \
52 ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
53#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
54 ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
55#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
56 ADD_CLASS_PASS_TO_PASS_NAME(NAME, CREATE_PASS)
57#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
58 PARAMS) \
59 ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CLASS)
60#include GET_PASS_REGISTRY
61#undef MODULE_ANALYSIS
62#undef MODULE_PASS
63#undef MODULE_PASS_WITH_PARAMS
64#undef FUNCTION_ANALYSIS
65#undef FUNCTION_ALIAS_ANALYSIS
66#undef FUNCTION_PASS
67#undef FUNCTION_PASS_WITH_PARAMS
68#undef LOOP_ANALYSIS
69#undef LOOP_PASS
70#undef MACHINE_FUNCTION_ANALYSIS
71#undef MACHINE_FUNCTION_PASS
72#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
73#undef ADD_CLASS_PASS_TO_PASS_NAME
74#undef ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS
75 });
76}
77
78#define ADD_PASS(NAME, CREATE_PASS) \
79 if (Name == NAME) { \
80 PM.addPass(CREATE_PASS); \
81 return true; \
82 }
83
84#define ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
85 if (PassBuilder::checkParametrizedPassName(Name, NAME)) { \
86 auto Params = PassBuilder::parsePassParameters(PARSER, Name, NAME); \
87 if (!Params) { \
88 errs() << NAME ": " << toString(Params.takeError()) << '\n'; \
89 return false; \
90 } \
91 PM.addPass(CREATE_PASS(Params.get())); \
92 return true; \
93 }
94
95PB.registerPipelineParsingCallback([=](StringRef Name, ModulePassManager &PM,
96 ArrayRef<PassBuilder::PipelineElement>) {
97#define MODULE_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
98#include GET_PASS_REGISTRY
99#undef MODULE_PASS
100 return false;
101});
102
103PB.registerPipelineParsingCallback([=](StringRef Name, ModulePassManager &PM,
104 ArrayRef<PassBuilder::PipelineElement>) {
105#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
106 ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
107#include GET_PASS_REGISTRY
108#undef MODULE_PASS_WITH_PARAMS
109 return false;
110});
111
112PB.registerPipelineParsingCallback([=](StringRef Name, FunctionPassManager &PM,
113 ArrayRef<PassBuilder::PipelineElement>) {
114#define FUNCTION_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
115#include GET_PASS_REGISTRY
116#undef FUNCTION_PASS
117 return false;
118});
119
120PB.registerPipelineParsingCallback([=](StringRef Name, FunctionPassManager &PM,
121 ArrayRef<PassBuilder::PipelineElement>) {
122#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
123 ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
124#include GET_PASS_REGISTRY
125#undef FUNCTION_PASS_WITH_PARAMS
126 return false;
127});
128
129PB.registerPipelineParsingCallback([=](StringRef Name, LoopPassManager &PM,
130 ArrayRef<PassBuilder::PipelineElement>) {
131#define LOOP_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
132#include GET_PASS_REGISTRY
133 return false;
134});
135
136PB.registerPipelineParsingCallback([=](StringRef Name,
137 MachineFunctionPassManager &PM,
138 ArrayRef<PassBuilder::PipelineElement>) {
139#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) ADD_PASS(NAME, CREATE_PASS)
140#include GET_PASS_REGISTRY
141 return false;
142});
143
144PB.registerPipelineParsingCallback([=](StringRef Name, FunctionPassManager &PM,
145 ArrayRef<PassBuilder::PipelineElement>) {
146#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
147 PARAMS) \
148 ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
149#include GET_PASS_REGISTRY
150#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
151 return false;
152});
153
154#undef ADD_PASS
155#undef ADD_PASS_WITH_PARAMS
156
157PB.registerAnalysisRegistrationCallback([](ModuleAnalysisManager &AM) {
158#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
159 AM.registerPass([&] { return CREATE_PASS; });
160#include GET_PASS_REGISTRY
161#undef MODULE_ANALYSIS
162});
163
164PB.registerAnalysisRegistrationCallback([](FunctionAnalysisManager &AM) {
165#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
166 AM.registerPass([&] { return CREATE_PASS; });
167#include GET_PASS_REGISTRY
168#undef FUNCTION_ANALYSIS
169});
170
171PB.registerParseAACallback([](StringRef Name, AAManager &AM) {
172#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
173 if (Name == NAME) { \
174 AM.registerFunctionAnalysis< \
175 std::remove_reference_t<decltype(CREATE_PASS)>>(); \
176 return true; \
177 }
178#include GET_PASS_REGISTRY
179#undef FUNCTION_ALIAS_ANALYSIS
180 return false;
181});
182
183PB.registerAnalysisRegistrationCallback([](LoopAnalysisManager &AM) {
184#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
185 AM.registerPass([&] { return CREATE_PASS; });
186#include GET_PASS_REGISTRY
187#undef LOOP_ANALYSIS
188});
189
190PB.registerAnalysisRegistrationCallback([](MachineFunctionAnalysisManager &AM) {
191#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
192 AM.registerPass([&] { return CREATE_PASS; });
193#include GET_PASS_REGISTRY
194#undef MACHINE_FUNCTION_ANALYSIS
195});
196
197#undef GET_PASS_REGISTRY
198#endif // GET_PASS_REGISTRY
std::string Name
PassInstrumentationCallbacks PIC
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)