[Mlir-commits] [mlir] [MLIR][Python] add value attr for PyAffineMapAttribute (PR #97254)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Jun 30 21:46:57 PDT 2024


https://github.com/xurui1995 created https://github.com/llvm/llvm-project/pull/97254

Similar to other attributes in Binding, the `PyAffineMapAttribute` should include a value attribute to enable users to directly retrieve the `AffineMap` from the `AffineMapAttr`.

>From 6b871ffbfc66256906d9b9000553c83d3d2e755a Mon Sep 17 00:00:00 2001
From: "Xu, Rui" <rui.xu at intel.com>
Date: Sun, 30 Jun 2024 21:37:18 -0700
Subject: [PATCH] [MLIR][Python] add value attr for PyAffineMapAttribute

---
 mlir/lib/Bindings/Python/IRAttributes.cpp | 2 ++
 mlir/test/python/ir/attributes.py         | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp
index b5f31aa5dec54..b4049bd7972d4 100644
--- a/mlir/lib/Bindings/Python/IRAttributes.cpp
+++ b/mlir/lib/Bindings/Python/IRAttributes.cpp
@@ -142,6 +142,8 @@ class PyAffineMapAttribute : public PyConcreteAttribute<PyAffineMapAttribute> {
           return PyAffineMapAttribute(affineMap.getContext(), attr);
         },
         py::arg("affine_map"), "Gets an attribute wrapping an AffineMap.");
+    c.def_property_readonly("value", mlirAffineMapAttrGetValue,
+                            "Returns the value of the AffineMap attribute");
   }
 };
 
diff --git a/mlir/test/python/ir/attributes.py b/mlir/test/python/ir/attributes.py
index 8a4e19463c3ee..4b475db634645 100644
--- a/mlir/test/python/ir/attributes.py
+++ b/mlir/test/python/ir/attributes.py
@@ -157,7 +157,7 @@ def testAffineMapAttr():
         # CHECK: affine_map<(d0, d1)[s0, s1, s2] -> ()>
         attr_built = AffineMapAttr.get(map0)
         print(str(attr_built))
-
+        assert attr_built.value == map0
         attr_parsed = Attribute.parse(str(attr_built))
         assert attr_built == attr_parsed
 



More information about the Mlir-commits mailing list