diff --git a/mlir/docs/PassManagement.md b/mlir/docs/PassManagement.md --- a/mlir/docs/PassManagement.md +++ b/mlir/docs/PassManagement.md @@ -863,11 +863,11 @@ The second is to provide a way to configure the pass options. These classes are named in the form of `MyPassOptions`, where `MyPass` is the name of the pass -definition in tablegen. The configurable parameters reflect the options -declared in the tablegen file. Differently from the registration hooks, these -classes can be enabled on a per-pass basis by defining the -`GEN_PASS_DECL_PASSNAME` macro, where `PASSNAME` is the uppercase version of -the name specified in tablegen. +definition in tablegen. The configurable parameters reflect the options declared +in the tablegen file. These declarations can be enabled for the whole group of +passes by defining the `GEN_PASS_DECL` macro, or on a per-pass basis by defining +`GEN_PASS_DECL_PASSNAME` where `PASSNAME` is the uppercase version of the name +specified in tablegen. ```c++ // .h.inc @@ -924,10 +924,9 @@ }; ``` -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. +These 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 be equal to the name defined in tablegen. 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 @@ -110,10 +110,14 @@ os << "};\n"; } +static std::string getPassDeclVarName(const Pass &pass) { + return "GEN_PASS_DECL_" + pass.getDef()->getName().upper(); +} + /// Emit the code to be included in the public header of the pass. static void emitPassDecls(const Pass &pass, raw_ostream &os) { StringRef passName = pass.getDef()->getName(); - std::string enableVarName = "GEN_PASS_DECL_" + passName.upper(); + std::string enableVarName = getPassDeclVarName(pass); os << "#ifdef " << enableVarName << "\n"; emitPassOptionsStruct(pass, os); @@ -435,6 +439,14 @@ std::vector passes = getPasses(recordKeeper); os << "/* Autogenerated by mlir-tblgen; don't manually edit */\n"; + os << "\n"; + os << "#ifdef GEN_PASS_DECL\n"; + os << "// Generate declarations for all passes.\n"; + for (const Pass &pass : passes) + os << "#define " << getPassDeclVarName(pass) << "\n"; + os << "#undef GEN_PASS_DECL\n"; + os << "#endif // GEN_PASS_DECL\n"; + for (const Pass &pass : passes) emitPass(pass, os); 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 @@ -13,9 +13,7 @@ std::unique_ptr createTestPassWithCustomConstructor(int v = 0); -#define GEN_PASS_DECL_TESTPASS -#define GEN_PASS_DECL_TESTPASSWITHOPTIONS -#define GEN_PASS_DECL_TESTPASSWITHCUSTOMCONSTRUCTOR +#define GEN_PASS_DECL #define GEN_PASS_REGISTRATION #include "PassGenTest.h.inc"