[flang-commits] [clang] [flang] [mlir] [mlir] Remove deprecated GEN_PASS_CLASSES. (PR #166904)

Jacques Pienaar via flang-commits flang-commits at lists.llvm.org
Thu Nov 6 23:26:38 PST 2025


https://github.com/jpienaar created https://github.com/llvm/llvm-project/pull/166904

This was marked as deprecated in 2022, but as comment. Switch to error to make visible and stop generating. Will remove the error message in follow up, just felt this was easier for folks to understand compilation errors. The change required to new form is rather minimal.

Also updated CIR & flang.

>From 71e68bc46c91ce16e852b54330ecb015c9f11a10 Mon Sep 17 00:00:00 2001
From: Jacques Pienaar <jacques+gh at japienaar.info>
Date: Fri, 7 Nov 2025 07:14:37 +0000
Subject: [PATCH] [mlir] Report deprecation GEN_PASS_CLASSES as error.

This was marked as deprecated in 2022, but as comment. Switch to error
to make visible and stop generating. Will remove the error message in
follow up, just felt this was easier for folks to understand compilation
errors.

Also updated CIR & flang.
---
 .../Dialect/Transforms/CIRCanonicalize.cpp    |  8 +-
 .../CIR/Dialect/Transforms/CIRSimplify.cpp    |  7 +-
 .../lib/CIR/Dialect/Transforms/FlattenCFG.cpp |  7 +-
 .../lib/CIR/Dialect/Transforms/GotoSolver.cpp |  7 +-
 .../CIR/Dialect/Transforms/HoistAllocas.cpp   |  7 +-
 .../Dialect/Transforms/LoweringPrepare.cpp    |  8 +-
 clang/lib/CIR/Dialect/Transforms/PassDetail.h |  2 +-
 flang/lib/Optimizer/CodeGen/PassDetail.h      |  2 +-
 mlir/tools/mlir-tblgen/PassGen.cpp            | 81 +------------------
 9 files changed, 42 insertions(+), 87 deletions(-)

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<SwitchOp> {
 // CIRCanonicalizePass
 //===----------------------------------------------------------------------===//
 
-struct CIRCanonicalizePass : public CIRCanonicalizeBase<CIRCanonicalizePass> {
+struct CIRCanonicalizePass
+    : public impl::CIRCanonicalizeBase<CIRCanonicalizePass> {
   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<VecSplatOp> {
 // CIRSimplifyPass
 //===----------------------------------------------------------------------===//
 
-struct CIRSimplifyPass : public CIRSimplifyBase<CIRSimplifyPass> {
+struct CIRSimplifyPass : public impl::CIRSimplifyBase<CIRSimplifyPass> {
   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<CIRFlattenCFGPass> {
+struct CIRFlattenCFGPass : public impl::CIRFlattenCFGBase<CIRFlattenCFGPass> {
 
   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<GotoSolverPass> {
+struct GotoSolverPass : public impl::GotoSolverBase<GotoSolverPass> {
   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<HoistAllocasPass> {
+struct HoistAllocasPass : public impl::HoistAllocasBase<HoistAllocasPass> {
 
   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<LoweringPreparePass> {
+struct LoweringPreparePass
+    : public impl::LoweringPrepareBase<LoweringPreparePass> {
   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 <typename ConcreteDialect>
 void registerDialect(DialectRegistry &registry);
 
-#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 <typename DerivedT>
-class {0}Base : public {1} {
-public:
-  using Base = {0}Base;
-
-  {0}Base() : {1}(::mlir::TypeID::get<DerivedT>()) {{}
-  {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<DerivedT>();
-  }
-
-  /// A clone method to create a copy of this pass.
-  std::unique_ptr<::mlir::Pass> clonePass() const override {{
-    return std::make_unique<DerivedT>(*static_cast<const DerivedT *>(this));
-  }
-
-  /// Register the dialects that must be loaded in the context before this pass.
-  void getDependentDialects(::mlir::DialectRegistry &registry) 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<DerivedT>)
-
-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<Pass> 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";
 }



More information about the flang-commits mailing list