Lines Matching full:pass
1 //===- Pass.cpp - MLIR pass registration generator ------------------------===//
15 #include "mlir/TableGen/Pass.h"
27 static llvm::cl::OptionCategory passGenCat("Options for -gen-pass-decls");
33 static std::vector<Pass> getPasses(const RecordKeeper &records) {
34 std::vector<Pass> passes;
49 // GEN: Pass registration generation
52 /// The code snippet used to generate a pass registration.
54 /// {0}: The def name of the pass record.
55 /// {1}: The pass constructor call.
62 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {{
68 inline void register{0}Pass() {{
69 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {{
78 /// {0}: The name of the pass group.
87 /// Emits the definition of the struct to be used to control the pass options.
88 static void emitPassOptionsStruct(const Pass &pass, raw_ostream &os) {
89 StringRef passName = pass.getDef()->getName();
90 ArrayRef<PassOption> options = pass.getOptions();
92 // Emit the struct only if the pass has at least one option.
115 static std::string getPassDeclVarName(const Pass &pass) {
116 return "GEN_PASS_DECL_" + pass.getDef()->getName().upper();
119 /// Emit the code to be included in the public header of the pass.
120 static void emitPassDecls(const Pass &pass, raw_ostream &os) {
121 StringRef passName = pass.getDef()->getName();
122 std::string enableVarName = getPassDeclVarName(pass);
125 emitPassOptionsStruct(pass, os);
127 if (StringRef constructor = pass.getConstructor(); constructor.empty()) {
129 os << "std::unique_ptr<::mlir::Pass> create" << passName << "();\n";
132 if (ArrayRef<PassOption> options = pass.getOptions(); !options.empty())
133 os << formatv("std::unique_ptr<::mlir::Pass> create{0}("
144 static void emitRegistrations(llvm::ArrayRef<Pass> passes, raw_ostream &os) {
147 for (const Pass &pass : passes) {
149 if (StringRef constructor = pass.getConstructor(); !constructor.empty())
152 constructorCall = formatv("create{0}()", pass.getDef()->getName()).str();
154 os << formatv(passRegistrationCode, pass.getDef()->getName(),
160 for (const Pass &pass : passes)
161 os << " register" << pass.getDef()->getName() << "();\n";
169 // GEN: Pass base class generation
172 /// The code snippet used to generate the start of a pass base class.
174 /// {0}: The def name of the pass record.
175 /// {1}: The base class for the pass.
176 /// {2): The command line argument for the pass.
177 /// {3}: The summary for the pass.
192 /// Returns the command-line argument attached to this pass.
200 /// Returns the derived pass name.
206 /// Support isa/dyn_cast functionality for the derived pass class.
207 static bool classof(const ::mlir::Pass *pass) {{
208 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
211 /// A clone method to create a copy of this pass.
212 std::unique_ptr<::mlir::Pass> clonePass() const override {{
216 /// Return the dialect that must be loaded in the context before this pass.
222 /// instantiation because Pass classes should only be visible by the current
234 std::unique_ptr<::mlir::Pass> create{0}();
240 std::unique_ptr<::mlir::Pass> create{0}({0}Options options);
245 friend std::unique_ptr<::mlir::Pass> create{0}() {{
251 friend std::unique_ptr<::mlir::Pass> create{0}({0}Options options) {{
257 std::unique_ptr<::mlir::Pass> create{0}() {{
263 std::unique_ptr<::mlir::Pass> create{0}({0}Options options) {{
268 /// Emit the declarations for each of the pass options.
269 static void emitPassOptionDecls(const Pass &pass, raw_ostream &os) {
270 for (const PassOption &opt : pass.getOptions()) {
271 os.indent(2) << "::mlir::Pass::"
285 /// Emit the declarations for each of the pass statistics.
286 static void emitPassStatisticDecls(const Pass &pass, raw_ostream &os) {
287 for (const PassStatistic &stat : pass.getStatistics()) {
288 os << formatv(" ::mlir::Pass::Statistic {0}{{this, \"{1}\", \"{2}\"};\n",
294 /// Emit the code to be used in the implementation of the pass.
295 static void emitPassDefs(const Pass &pass, raw_ostream &os) {
296 StringRef passName = pass.getDef()->getName();
298 bool emitDefaultConstructors = pass.getConstructor().empty();
299 bool emitDefaultConstructorWithOptions = !pass.getOptions().empty();
314 pass.getDependentDialects(), dialectsOs,
322 os << formatv(baseClassBegin, passName, pass.getBaseClass(),
323 pass.getArgument(), pass.getSummary(),
326 if (ArrayRef<PassOption> options = pass.getOptions(); !options.empty()) {
330 for (const PassOption &opt : pass.getOptions())
339 emitPassOptionDecls(pass, os);
340 emitPassStatisticDecls(pass, os);
348 if (!pass.getOptions().empty())
366 static void emitPass(const Pass &pass, raw_ostream &os) {
367 StringRef passName = pass.getDef()->getName();
370 emitPassDecls(pass, os);
371 emitPassDefs(pass, os);
374 // TODO: Drop old pass declarations.
375 // The old pass base class is being kept until all the passes have switched to
390 /// Returns the command-line argument attached to this pass.
398 /// Returns the derived pass name.
404 /// Support isa/dyn_cast functionality for the derived pass class.
405 static bool classof(const ::mlir::Pass *pass) {{
406 return pass->getTypeID() == ::mlir::TypeID::get<DerivedT>();
409 /// A clone method to create a copy of this pass.
410 std::unique_ptr<::mlir::Pass> clonePass() const override {{
414 /// Register the dialects that must be loaded in the context before this pass.
420 /// instantiation because Pass classes should only be visible by the current
427 // TODO: Drop old pass declarations.
428 /// Emit a backward-compatible declaration of the pass base class.
429 static void emitOldPassDecl(const Pass &pass, raw_ostream &os) {
430 StringRef defName = pass.getDef()->getName();
435 pass.getDependentDialects(), dialectsOs,
441 os << formatv(oldPassDeclBegin, defName, pass.getBaseClass(),
442 pass.getArgument(), pass.getSummary(),
444 emitPassOptionDecls(pass, os);
445 emitPassStatisticDecls(pass, os);
450 std::vector<Pass> passes = getPasses(records);
456 for (const Pass &pass : passes)
457 os << "#define " << getPassDeclVarName(pass) << "\n";
461 for (const Pass &pass : passes)
462 emitPass(pass, os);
466 // TODO: Drop old pass declarations.
468 os << "// Deprecated. Please use the new per-pass macros.\n";
470 for (const Pass &pass : passes)
471 emitOldPassDecl(pass, os);
477 genPassDecls("gen-pass-decls", "Generate pass declarations",