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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Jun 30 21:47:29 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Bimo (xurui1995)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/97254.diff


2 Files Affected:

- (modified) mlir/lib/Bindings/Python/IRAttributes.cpp (+2) 
- (modified) mlir/test/python/ir/attributes.py (+1-1) 


``````````diff
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
 

``````````

</details>


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


More information about the Mlir-commits mailing list