[llvm-branch-commits] [mlir] df7ddee - [mlir][python] Add FlatSymbolRef attribute.
Stella Laurenzo via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Dec 29 12:34:39 PST 2020
Author: Stella Laurenzo
Date: 2020-12-29T12:24:28-08:00
New Revision: df7ddeea668af7b25ee01f282fd8e6b388155103
URL: https://github.com/llvm/llvm-project/commit/df7ddeea668af7b25ee01f282fd8e6b388155103
DIFF: https://github.com/llvm/llvm-project/commit/df7ddeea668af7b25ee01f282fd8e6b388155103.diff
LOG: [mlir][python] Add FlatSymbolRef attribute.
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D93909
Added:
Modified:
mlir/lib/Bindings/Python/IRModules.cpp
mlir/test/Bindings/Python/ir_attributes.py
Removed:
################################################################################
diff --git a/mlir/lib/Bindings/Python/IRModules.cpp b/mlir/lib/Bindings/Python/IRModules.cpp
index 8a77d60741b4..86d6f8206155 100644
--- a/mlir/lib/Bindings/Python/IRModules.cpp
+++ b/mlir/lib/Bindings/Python/IRModules.cpp
@@ -1643,6 +1643,33 @@ class PyBoolAttribute : public PyConcreteAttribute<PyBoolAttribute> {
}
};
+class PyFlatSymbolRefAttribute
+ : public PyConcreteAttribute<PyFlatSymbolRefAttribute> {
+public:
+ static constexpr IsAFunctionTy isaFunction = mlirAttributeIsAFlatSymbolRef;
+ static constexpr const char *pyClassName = "FlatSymbolRefAttr";
+ using PyConcreteAttribute::PyConcreteAttribute;
+
+ static void bindDerived(ClassTy &c) {
+ c.def_static(
+ "get",
+ [](std::string value, DefaultingPyMlirContext context) {
+ MlirAttribute attr =
+ mlirFlatSymbolRefAttrGet(context->get(), toMlirStringRef(value));
+ return PyFlatSymbolRefAttribute(context->getRef(), attr);
+ },
+ py::arg("value"), py::arg("context") = py::none(),
+ "Gets a uniqued FlatSymbolRef attribute");
+ c.def_property_readonly(
+ "value",
+ [](PyFlatSymbolRefAttribute &self) {
+ MlirStringRef stringRef = mlirFlatSymbolRefAttrGetValue(self);
+ return py::str(stringRef.data, stringRef.length);
+ },
+ "Returns the value of the FlatSymbolRef attribute as a string");
+ }
+};
+
class PyStringAttribute : public PyConcreteAttribute<PyStringAttribute> {
public:
static constexpr IsAFunctionTy isaFunction = mlirAttributeIsAString;
@@ -3229,6 +3256,7 @@ void mlir::python::populateIRSubmodule(py::module &m) {
PyArrayAttribute::PyArrayAttributeIterator::bind(m);
PyIntegerAttribute::bind(m);
PyBoolAttribute::bind(m);
+ PyFlatSymbolRefAttribute::bind(m);
PyStringAttribute::bind(m);
PyDenseElementsAttribute::bind(m);
PyDenseIntElementsAttribute::bind(m);
diff --git a/mlir/test/Bindings/Python/ir_attributes.py b/mlir/test/Bindings/Python/ir_attributes.py
index 84f313912547..ce85dc3cf87a 100644
--- a/mlir/test/Bindings/Python/ir_attributes.py
+++ b/mlir/test/Bindings/Python/ir_attributes.py
@@ -165,6 +165,20 @@ def testBoolAttr():
run(testBoolAttr)
+# CHECK-LABEL: TEST: testFlatSymbolRefAttr
+def testFlatSymbolRefAttr():
+ with Context() as ctx:
+ sattr = FlatSymbolRefAttr(Attribute.parse('@symbol'))
+ # CHECK: symattr value: symbol
+ print("symattr value:", sattr.value)
+
+ # Test factory methods.
+ # CHECK: default_get: @foobar
+ print("default_get:", FlatSymbolRefAttr.get("foobar"))
+
+run(testFlatSymbolRefAttr)
+
+
# CHECK-LABEL: TEST: testStringAttr
def testStringAttr():
with Context() as ctx:
More information about the llvm-branch-commits
mailing list