}
};
+class PyTypeAttribute : public PyConcreteAttribute<PyTypeAttribute> {
+public:
+ static constexpr IsAFunctionTy isaFunction = mlirAttributeIsAType;
+ static constexpr const char *pyClassName = "TypeAttr";
+ using PyConcreteAttribute::PyConcreteAttribute;
+
+ static void bindDerived(ClassTy &c) {
+ c.def_static(
+ "get",
+ [](PyType value, DefaultingPyMlirContext context) {
+ MlirAttribute attr = mlirTypeAttrGet(value.get());
+ return PyTypeAttribute(context->getRef(), attr);
+ },
+ py::arg("value"), py::arg("context") = py::none(),
+ "Gets a uniqued Type attribute");
+ c.def_property_readonly("value", [](PyTypeAttribute &self) {
+ return PyType(self.getContext()->getRef(),
+ mlirTypeAttrGetValue(self.get()));
+ });
+ }
+};
+
/// Unit Attribute subclass. Unit attributes don't have values.
class PyUnitAttribute : public PyConcreteAttribute<PyUnitAttribute> {
public:
PyDenseElementsAttribute::bind(m);
PyDenseIntElementsAttribute::bind(m);
PyDenseFPElementsAttribute::bind(m);
+ PyTypeAttribute::bind(m);
PyUnitAttribute::bind(m);
//----------------------------------------------------------------------------
run(testDenseFPAttr)
+
+
+# CHECK-LABEL: TEST: testTypeAttr
+def testTypeAttr():
+ with Context():
+ raw = Attribute.parse("vector<4xf32>")
+ # CHECK: attr: vector<4xf32>
+ print("attr:", raw)
+ type_attr = TypeAttr(raw)
+ # CHECK: f32
+ print(ShapedType(type_attr.value).element_type)
+
+
+run(testTypeAttr)