18#ifdef GET_PASS_REGISTRY
20#if !__has_include(GET_PASS_REGISTRY)
21#error "must provide <Target>PassRegistry.def"
24auto *
PIC =
PB.getPassInstrumentationCallbacks();
26 PIC->registerClassToPassNameCallback([
this,
PIC]() {
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);
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, \
59 ADD_CLASS_PASS_TO_PASS_NAME_WITH_PARAMS(NAME, CLASS)
60#include GET_PASS_REGISTRY
63#undef MODULE_PASS_WITH_PARAMS
64#undef FUNCTION_ANALYSIS
65#undef FUNCTION_ALIAS_ANALYSIS
67#undef FUNCTION_PASS_WITH_PARAMS
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
78#define ADD_PASS(NAME, CREATE_PASS) \
80 PM.addPass(CREATE_PASS); \
84#define ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
85 if (PassBuilder::checkParametrizedPassName(Name, NAME)) { \
86 auto Params = PassBuilder::parsePassParameters(PARSER, Name, NAME); \
88 errs() << NAME ": " << toString(Params.takeError()) << '\n'; \
91 PM.addPass(CREATE_PASS(Params.get())); \
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
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
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
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
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
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
144PB.registerPipelineParsingCallback([=](StringRef
Name, FunctionPassManager &PM,
145 ArrayRef<PassBuilder::PipelineElement>) {
146#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
148 ADD_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER)
149#include GET_PASS_REGISTRY
150#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
155#undef ADD_PASS_WITH_PARAMS
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
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
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)>>(); \
178#include GET_PASS_REGISTRY
179#undef FUNCTION_ALIAS_ANALYSIS
183PB.registerAnalysisRegistrationCallback([](LoopAnalysisManager &AM) {
184#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
185 AM.registerPass([&] { return CREATE_PASS; });
186#include GET_PASS_REGISTRY
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
197#undef GET_PASS_REGISTRY
PassInstrumentationCallbacks PIC
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)