[Mlir-commits] [mlir] [MLIR][Python] Add `attr_name` for `FloatAttr` (PR #175306)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Jan 10 04:38:46 PST 2026


https://github.com/PragmaTwice created https://github.com/llvm/llvm-project/pull/175306

After #174756 I found that attribute name for `FloatAttr` is missing. And this PR is to add it.

This is actually part of changes in #169045, but I think that we can make it a separate PR to make #169045 easier to review.

>From ed14a70d4da486749311940f52d5b8dda1798bb0 Mon Sep 17 00:00:00 2001
From: PragmaTwice <twice at apache.org>
Date: Sat, 10 Jan 2026 20:35:25 +0800
Subject: [PATCH] [MLIR][Python] Add attr_name for FloatAttr

---
 mlir/include/mlir-c/BuiltinAttributes.h          | 2 ++
 mlir/include/mlir/Bindings/Python/IRAttributes.h | 1 +
 mlir/lib/CAPI/IR/BuiltinAttributes.cpp           | 2 ++
 mlir/test/python/ir/attributes.py                | 2 ++
 4 files changed, 7 insertions(+)

diff --git a/mlir/include/mlir-c/BuiltinAttributes.h b/mlir/include/mlir-c/BuiltinAttributes.h
index 17c73f44cfc74..eab732365f6b8 100644
--- a/mlir/include/mlir-c/BuiltinAttributes.h
+++ b/mlir/include/mlir-c/BuiltinAttributes.h
@@ -115,6 +115,8 @@ MLIR_CAPI_EXPORTED MlirTypeID mlirDictionaryAttrGetTypeID(void);
 /// Checks whether the given attribute is a floating point attribute.
 MLIR_CAPI_EXPORTED bool mlirAttributeIsAFloat(MlirAttribute attr);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirFloatAttrGetName(void);
+
 /// Creates a floating point attribute in the given context with the given
 /// double value and double-precision FP semantics.
 MLIR_CAPI_EXPORTED MlirAttribute mlirFloatAttrDoubleGet(MlirContext ctx,
diff --git a/mlir/include/mlir/Bindings/Python/IRAttributes.h b/mlir/include/mlir/Bindings/Python/IRAttributes.h
index 05d64b0d91b1b..6175710d76dd0 100644
--- a/mlir/include/mlir/Bindings/Python/IRAttributes.h
+++ b/mlir/include/mlir/Bindings/Python/IRAttributes.h
@@ -324,6 +324,7 @@ class MLIR_PYTHON_API_EXPORTED PyFloatAttribute
   using PyConcreteAttribute::PyConcreteAttribute;
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloatAttrGetTypeID;
+  static inline const MlirStringRef name = mlirFloatAttrGetName();
 
   static void bindDerived(ClassTy &c);
 };
diff --git a/mlir/lib/CAPI/IR/BuiltinAttributes.cpp b/mlir/lib/CAPI/IR/BuiltinAttributes.cpp
index eebf82215eab0..f7172c21a0cb9 100644
--- a/mlir/lib/CAPI/IR/BuiltinAttributes.cpp
+++ b/mlir/lib/CAPI/IR/BuiltinAttributes.cpp
@@ -131,6 +131,8 @@ bool mlirAttributeIsAFloat(MlirAttribute attr) {
   return llvm::isa<FloatAttr>(unwrap(attr));
 }
 
+MlirStringRef mlirFloatAttrGetName(void) { return wrap(FloatAttr::name); }
+
 MlirAttribute mlirFloatAttrDoubleGet(MlirContext ctx, MlirType type,
                                      double value) {
   return wrap(FloatAttr::get(unwrap(type), value));
diff --git a/mlir/test/python/ir/attributes.py b/mlir/test/python/ir/attributes.py
index 15a5b5ed3a81c..5590834999261 100644
--- a/mlir/test/python/ir/attributes.py
+++ b/mlir/test/python/ir/attributes.py
@@ -747,3 +747,5 @@ def testAttrNames():
         print(DenseResourceElementsAttr.attr_name)
         # CHECK: builtin.string
         print(StringAttr.attr_name)
+        # CHECK: builtin.float
+        print(FloatAttr.attr_name)



More information about the Mlir-commits mailing list