diff --git a/mlir/docs/PassManagement.md b/mlir/docs/PassManagement.md --- a/mlir/docs/PassManagement.md +++ b/mlir/docs/PassManagement.md @@ -829,12 +829,10 @@ } ``` -Using the `gen-pass-decls` and `gen-pass-defs` generators, we can generate most -of the boilerplate above automatically. - -The `gen-pass-decls` generator takes as an input a `-name` parameter, that +Using the `gen-pass-decls` generator, we can generate most of the boilerplate +above automatically. This generator takes as an input a `-name` parameter, that provides a tag for the group of passes that are being generated. This generator -produces code with two purposes: +produces code with multiple purposes: The first is to register the declared passes with the global registry. For each pass, the generator produces a `registerPassName` where @@ -902,14 +900,11 @@ #endif // GEN_PASS_DECL_MYPASS ``` -The `gen-pass-defs` generator produces the definitions to be used for the pass -implementation. - -It generates a base class for each of the passes, containing most of the boiler -plate related to pass definitions. These classes are named in the form of -`MyPassBase` and are declared inside the `impl` namespace, where `MyPass` is -the name of the pass definition in tablegen. We can update the original C++ -pass definition as so: +The last purpose of this generator is to emit a base class for each of the +passes, containing most of the boiler plate related to pass definitions. These +classes are named in the form of `MyPassBase` and are declared inside the +`impl` namespace, where `MyPass` is the name of the pass definition in +tablegen. We can update the original C++ pass definition as so: ```c++ // MyPass.cpp @@ -917,7 +912,7 @@ /// Include the generated base pass class definitions. namespace foo { #define GEN_PASS_DEF_MYPASS -#include "Passes.cpp.inc" +#include "Passes.h.inc" } /// Define the main class as deriving from the generated base class. @@ -929,9 +924,9 @@ }; ``` -Similarly to the previous generator, the definitions can be enabled on a -per-pass basis by defining the appropriate preprocessor `GEN_PASS_DEF_PASSNAME` -macro, with `PASSNAME` equal to the uppercase version of the name of the pass +Similarly to the previous cases, the definitions can be enabled on a per-pass +basis by defining the appropriate preprocessor `GEN_PASS_DEF_PASSNAME` macro, +with `PASSNAME` equal to the uppercase version of the name of the pass definition in tablegen. If the `constructor` field has not been specified in tablegen, then the default constructors are also defined and expect the name of the actual pass class to diff --git a/mlir/tools/mlir-tblgen/PassGen.cpp b/mlir/tools/mlir-tblgen/PassGen.cpp --- a/mlir/tools/mlir-tblgen/PassGen.cpp +++ b/mlir/tools/mlir-tblgen/PassGen.cpp @@ -118,8 +118,6 @@ std::string enableVarName = "GEN_PASS_DECL_" + passName.upper(); os << "#ifdef " << enableVarName << "\n"; - os << llvm::formatv(passHeader, passName); - emitPassOptionsStruct(pass, os); if (StringRef constructor = pass.getConstructor(); constructor.empty()) { @@ -164,24 +162,6 @@ os << "#endif // GEN_PASS_REGISTRATION\n"; } -static void emitDecls(const llvm::RecordKeeper &recordKeeper, raw_ostream &os) { - std::vector passes = getPasses(recordKeeper); - os << "/* Autogenerated by mlir-tblgen; don't manually edit */\n"; - - for (const Pass &pass : passes) - emitPassDecls(pass, os); - - emitRegistrations(passes, os); - - // TODO drop old pass declarations - // Emit the old code until all the passes have switched to the new design. - os << "#ifdef GEN_PASS_CLASSES\n"; - for (const Pass &pass : passes) - emitOldPassDecl(pass, os); - os << "#undef GEN_PASS_CLASSES\n"; - os << "#endif // GEN_PASS_CLASSES\n"; -} - //===----------------------------------------------------------------------===// // GEN: Pass base class generation //===----------------------------------------------------------------------===// @@ -313,7 +293,6 @@ bool emitDefaultConstructorWithOptions = !pass.getOptions().empty(); os << "#ifdef " << enableVarName << "\n"; - os << llvm::formatv(passHeader, passName); if (emitDefaultConstructors) { os << llvm::formatv(friendDefaultConstructorDeclTemplate, passName); @@ -377,14 +356,6 @@ os << "#endif // " << enableVarName << "\n"; } -static void emitDefs(const llvm::RecordKeeper &recordKeeper, raw_ostream &os) { - std::vector passes = getPasses(recordKeeper); - os << "/* Autogenerated by mlir-tblgen; don't manually edit */\n"; - - for (const Pass &pass : passes) - emitPassDefs(pass, os); -} - // TODO drop old pass declarations // The old pass base class is being kept until all the passes have switched to // the new decls/defs design. @@ -452,16 +423,36 @@ os << "};\n"; } +static void emitPass(const Pass &pass, raw_ostream &os) { + StringRef passName = pass.getDef()->getName(); + os << llvm::formatv(passHeader, passName); + + emitPassDecls(pass, os); + emitPassDefs(pass, os); +} + +static void emitPasses(const llvm::RecordKeeper &recordKeeper, + raw_ostream &os) { + std::vector passes = getPasses(recordKeeper); + os << "/* Autogenerated by mlir-tblgen; don't manually edit */\n"; + + for (const Pass &pass : passes) + emitPass(pass, os); + + emitRegistrations(passes, os); + + // TODO: Drop old pass declarations. + // Emit the old code until all the passes have switched to the new design. + os << "#ifdef GEN_PASS_CLASSES\n"; + for (const Pass &pass : passes) + emitOldPassDecl(pass, os); + os << "#undef GEN_PASS_CLASSES\n"; + os << "#endif // GEN_PASS_CLASSES\n"; +} + static mlir::GenRegistration genPassDecls("gen-pass-decls", "Generate pass declarations", [](const llvm::RecordKeeper &records, raw_ostream &os) { - emitDecls(records, os); + emitPasses(records, os); return false; }); - -static mlir::GenRegistration - genPassDefs("gen-pass-defs", "Generate pass definitions", - [](const llvm::RecordKeeper &records, raw_ostream &os) { - emitDefs(records, os); - return false; - }); diff --git a/mlir/unittests/TableGen/CMakeLists.txt b/mlir/unittests/TableGen/CMakeLists.txt --- a/mlir/unittests/TableGen/CMakeLists.txt +++ b/mlir/unittests/TableGen/CMakeLists.txt @@ -5,7 +5,6 @@ set(LLVM_TARGET_DEFINITIONS passes.td) mlir_tablegen(PassGenTest.h.inc -gen-pass-decls -name TableGenTest) -mlir_tablegen(PassGenTest.cpp.inc -gen-pass-defs -name TableGenTest) add_public_tablegen_target(MLIRTableGenTestPassIncGen) add_mlir_unittest(MLIRTableGenTests diff --git a/mlir/unittests/TableGen/PassGenTest.cpp b/mlir/unittests/TableGen/PassGenTest.cpp --- a/mlir/unittests/TableGen/PassGenTest.cpp +++ b/mlir/unittests/TableGen/PassGenTest.cpp @@ -22,7 +22,7 @@ #define GEN_PASS_DEF_TESTPASS #define GEN_PASS_DEF_TESTPASSWITHOPTIONS #define GEN_PASS_DEF_TESTPASSWITHCUSTOMCONSTRUCTOR -#include "PassGenTest.cpp.inc" +#include "PassGenTest.h.inc" struct TestPass : public impl::TestPassBase { using TestPassBase::TestPassBase;