diff --git a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp index fbecab9774f5b..2ef09b74dc968 100644 --- a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp +++ b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp @@ -26,6 +26,11 @@ using namespace mlir; using namespace cir; +namespace mlir { +#define GEN_PASS_DEF_CIRCANONICALIZE +#include "clang/CIR/Dialect/Passes.h.inc" +} // namespace mlir + namespace { /// Removes branches between two blocks if it is the only branch. @@ -101,7 +106,8 @@ struct RemoveEmptySwitch : public OpRewritePattern { // CIRCanonicalizePass //===----------------------------------------------------------------------===// -struct CIRCanonicalizePass : public CIRCanonicalizeBase { +struct CIRCanonicalizePass + : public impl::CIRCanonicalizeBase { using CIRCanonicalizeBase::CIRCanonicalizeBase; // The same operation rewriting done here could have been performed diff --git a/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp b/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp index 3c6f76892d5cb..dcef9ddee1bb4 100644 --- a/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp +++ b/clang/lib/CIR/Dialect/Transforms/CIRSimplify.cpp @@ -21,6 +21,11 @@ using namespace mlir; using namespace cir; +namespace mlir { +#define GEN_PASS_DEF_CIRSIMPLIFY +#include "clang/CIR/Dialect/Passes.h.inc" +} // namespace mlir + //===----------------------------------------------------------------------===// // Rewrite patterns //===----------------------------------------------------------------------===// @@ -283,7 +288,7 @@ struct SimplifyVecSplat : public OpRewritePattern { // CIRSimplifyPass //===----------------------------------------------------------------------===// -struct CIRSimplifyPass : public CIRSimplifyBase { +struct CIRSimplifyPass : public impl::CIRSimplifyBase { using CIRSimplifyBase::CIRSimplifyBase; void runOnOperation() override; diff --git a/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp b/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp index ca7554e4e3754..69a5334ca2423 100644 --- a/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp +++ b/clang/lib/CIR/Dialect/Transforms/FlattenCFG.cpp @@ -26,6 +26,11 @@ using namespace mlir; using namespace cir; +namespace mlir { +#define GEN_PASS_DEF_CIRFLATTENCFG +#include "clang/CIR/Dialect/Passes.h.inc" +} // namespace mlir + namespace { /// Lowers operations with the terminator trait that have a single successor. @@ -50,7 +55,7 @@ void walkRegionSkipping( }); } -struct CIRFlattenCFGPass : public CIRFlattenCFGBase { +struct CIRFlattenCFGPass : public impl::CIRFlattenCFGBase { CIRFlattenCFGPass() = default; void runOnOperation() override; diff --git a/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp b/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp index c0db98440a902..00972b6976295 100644 --- a/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp +++ b/clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp @@ -14,9 +14,14 @@ using namespace mlir; using namespace cir; +namespace mlir { +#define GEN_PASS_DEF_GOTOSOLVER +#include "clang/CIR/Dialect/Passes.h.inc" +} // namespace mlir + namespace { -struct GotoSolverPass : public GotoSolverBase { +struct GotoSolverPass : public impl::GotoSolverBase { GotoSolverPass() = default; void runOnOperation() override; }; diff --git a/clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp b/clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp index 72bbf08c79b16..74b22faadc8ae 100644 --- a/clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp +++ b/clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp @@ -20,9 +20,14 @@ using namespace mlir; using namespace cir; +namespace mlir { +#define GEN_PASS_DEF_HOISTALLOCAS +#include "clang/CIR/Dialect/Passes.h.inc" +} // namespace mlir + namespace { -struct HoistAllocasPass : public HoistAllocasBase { +struct HoistAllocasPass : public impl::HoistAllocasBase { HoistAllocasPass() = default; void runOnOperation() override; diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp index cba04649ca05e..29b1211d2c351 100644 --- a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp +++ b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp @@ -23,6 +23,11 @@ using namespace mlir; using namespace cir; +namespace mlir { +#define GEN_PASS_DEF_LOWERINGPREPARE +#include "clang/CIR/Dialect/Passes.h.inc" +} // namespace mlir + static SmallString<128> getTransformedFileName(mlir::ModuleOp mlirModule) { SmallString<128> fileName; @@ -53,7 +58,8 @@ static cir::FuncOp getCalledFunction(cir::CallOp callOp) { } namespace { -struct LoweringPreparePass : public LoweringPrepareBase { +struct LoweringPreparePass + : public impl::LoweringPrepareBase { LoweringPreparePass() = default; void runOnOperation() override; diff --git a/clang/lib/CIR/Dialect/Transforms/PassDetail.h b/clang/lib/CIR/Dialect/Transforms/PassDetail.h index 600dde56d679f..ef42a85cc2751 100644 --- a/clang/lib/CIR/Dialect/Transforms/PassDetail.h +++ b/clang/lib/CIR/Dialect/Transforms/PassDetail.h @@ -21,7 +21,7 @@ namespace mlir { template void registerDialect(DialectRegistry ®istry); -#define GEN_PASS_CLASSES +#define GEN_PASS_DECL #include "clang/CIR/Dialect/Passes.h.inc" } // namespace mlir diff --git a/flang/lib/Optimizer/CodeGen/PassDetail.h b/flang/lib/Optimizer/CodeGen/PassDetail.h index f7030131beff9..252da029dc0c8 100644 --- a/flang/lib/Optimizer/CodeGen/PassDetail.h +++ b/flang/lib/Optimizer/CodeGen/PassDetail.h @@ -18,7 +18,7 @@ namespace fir { -#define GEN_PASS_CLASSES +#define GEN_PASS_DECL #include "flang/Optimizer/CodeGen/CGPasses.h.inc" } // namespace fir diff --git a/mlir/tools/mlir-tblgen/PassGen.cpp b/mlir/tools/mlir-tblgen/PassGen.cpp index f4b8eb43b49b8..e4ae78f022405 100644 --- a/mlir/tools/mlir-tblgen/PassGen.cpp +++ b/mlir/tools/mlir-tblgen/PassGen.cpp @@ -387,81 +387,6 @@ static void emitPass(const Pass &pass, raw_ostream &os) { 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. -const char *const oldPassDeclBegin = R"( -template -class {0}Base : public {1} { -public: - using Base = {0}Base; - - {0}Base() : {1}(::mlir::TypeID::get()) {{} - {0}Base(const {0}Base &other) : {1}(other) {{} - {0}Base& operator=(const {0}Base &) = delete; - {0}Base({0}Base &&) = delete; - {0}Base& operator=({0}Base &&) = delete; - ~{0}Base() = default; - - /// Returns the command-line argument attached to this pass. - static constexpr ::llvm::StringLiteral getArgumentName() { - return ::llvm::StringLiteral("{2}"); - } - ::llvm::StringRef getArgument() const override { return "{2}"; } - - ::llvm::StringRef getDescription() const override { return R"PD({3})PD"; } - - /// Returns the derived pass name. - static constexpr ::llvm::StringLiteral getPassName() { - return ::llvm::StringLiteral("{0}"); - } - ::llvm::StringRef getName() const override { return "{0}"; } - - /// Support isa/dyn_cast functionality for the derived pass class. - static bool classof(const ::mlir::Pass *pass) {{ - return pass->getTypeID() == ::mlir::TypeID::get(); - } - - /// A clone method to create a copy of this pass. - std::unique_ptr<::mlir::Pass> clonePass() const override {{ - return std::make_unique(*static_cast(this)); - } - - /// Register the dialects that must be loaded in the context before this pass. - void getDependentDialects(::mlir::DialectRegistry ®istry) const override { - {4} - } - - /// Explicitly declare the TypeID for this class. We declare an explicit private - /// instantiation because Pass classes should only be visible by the current - /// library. - MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID({0}Base) - -protected: -)"; - -// TODO: Drop old pass declarations. -/// Emit a backward-compatible declaration of the pass base class. -static void emitOldPassDecl(const Pass &pass, raw_ostream &os) { - StringRef defName = pass.getDef()->getName(); - std::string dependentDialectRegistrations; - { - llvm::raw_string_ostream dialectsOs(dependentDialectRegistrations); - llvm::interleave( - pass.getDependentDialects(), dialectsOs, - [&](StringRef dependentDialect) { - dialectsOs << formatv(dialectRegistrationTemplate, dependentDialect); - }, - "\n "); - } - os << formatv(oldPassDeclBegin, defName, pass.getBaseClass(), - pass.getArgument(), pass.getSummary().trim(), - dependentDialectRegistrations); - emitPassOptionDecls(pass, os); - emitPassStatisticDecls(pass, os); - os << "};\n"; -} - static void emitPasses(const RecordKeeper &records, raw_ostream &os) { std::vector passes = getPasses(records); os << "/* Autogenerated by mlir-tblgen; don't manually edit */\n"; @@ -479,12 +404,10 @@ static void emitPasses(const RecordKeeper &records, raw_ostream &os) { emitRegistrations(passes, os); - // TODO: Drop old pass declarations. + // TODO: Remove warning, kept in to make error understandable. // Emit the old code until all the passes have switched to the new design. - os << "// Deprecated. Please use the new per-pass macros.\n"; os << "#ifdef GEN_PASS_CLASSES\n"; - for (const Pass &pass : passes) - emitOldPassDecl(pass, os); + os << "#error \"GEN_PASS_CLASSES is deprecated; use per-pass macros\"\n"; os << "#undef GEN_PASS_CLASSES\n"; os << "#endif // GEN_PASS_CLASSES\n"; }