[Mlir-commits] [mlir] [MLIR][ODS] Make dialect attribute helper member functions const (NFC) (PR #181111)

Christian Ulmann llvmlistbot at llvm.org
Thu Feb 12 02:01:39 PST 2026


https://github.com/Dinistro created https://github.com/llvm/llvm-project/pull/181111

This commit marks member functions of dialect attribute helpers as constant. This ensures that these helpers can be used as members of rewrite patterns, whose `matchAndRewrite` functions are marked as const as well. 

>From 62cc0b2896d004a06ba6178f1e4a4e66776f1d81 Mon Sep 17 00:00:00 2001
From: Christian Ulmann <christian.ulmann at nextsilicon.com>
Date: Thu, 12 Feb 2026 10:56:44 +0100
Subject: [PATCH] [MLIR][ODS] Make dialect attribute helper member functions
 const (NFC)

This commit marks member functions of dialect attribute helpers as
constant. This ensures that these helpers can be added as members of
rewrite patterns, whose `matchAndRewrite` functions are marked as const
as well.
---
 mlir/tools/mlir-tblgen/DialectGen.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectGen.cpp
index c2c0c1f415254..8eecad39f49f3 100644
--- a/mlir/tools/mlir-tblgen/DialectGen.cpp
+++ b/mlir/tools/mlir-tblgen/DialectGen.cpp
@@ -207,23 +207,23 @@ static const char *const discardableAttrHelperDecl = R"(
       static constexpr ::llvm::StringLiteral getNameStr() {{
         return "{4}.{1}";
       }
-      constexpr ::mlir::StringAttr getName() {{
+      constexpr ::mlir::StringAttr getName() const {{
         return name;
       }
 
-      {0}AttrHelper(::mlir::MLIRContext *ctx)
+      explicit {0}AttrHelper(::mlir::MLIRContext *ctx)
         : name(::mlir::StringAttr::get(ctx, getNameStr())) {{}
 
-     {2} getAttr(::mlir::Operation *op) {{
+     {2} getAttr(::mlir::Operation *op) const {{
        return op->getAttrOfType<{2}>(name);
      }
-     void setAttr(::mlir::Operation *op, {2} val) {{
+     void setAttr(::mlir::Operation *op, {2} val) const {{
        op->setAttr(name, val);
      }
-     bool isAttrPresent(::mlir::Operation *op) {{
+     bool isAttrPresent(::mlir::Operation *op) const {{
        return op->hasAttrOfType<{2}>(name);
      }
-     void removeAttr(::mlir::Operation *op) {{
+     void removeAttr(::mlir::Operation *op) const {{
        assert(op->hasAttrOfType<{2}>(name));
        op->removeAttr(name);
      }



More information about the Mlir-commits mailing list