diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h --- a/mlir/include/mlir-c/IR.h +++ b/mlir/include/mlir-c/IR.h @@ -70,7 +70,7 @@ * a string. */ struct MlirNamedAttribute { - MlirStringRef name; + MlirIdentifier name; MlirAttribute attribute; }; typedef struct MlirNamedAttribute MlirNamedAttribute; @@ -600,7 +600,7 @@ MLIR_CAPI_EXPORTED void mlirAttributeDump(MlirAttribute attr); /// Associates an attribute with the name. Takes ownership of neither. -MLIR_CAPI_EXPORTED MlirNamedAttribute mlirNamedAttributeGet(MlirStringRef name, +MLIR_CAPI_EXPORTED MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name, MlirAttribute attr); //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Bindings/Python/IRModules.cpp b/mlir/lib/Bindings/Python/IRModules.cpp --- a/mlir/lib/Bindings/Python/IRModules.cpp +++ b/mlir/lib/Bindings/Python/IRModules.cpp @@ -962,8 +962,10 @@ llvm::SmallVector mlirNamedAttributes; mlirNamedAttributes.reserve(mlirAttributes.size()); for (auto &it : mlirAttributes) - mlirNamedAttributes.push_back( - mlirNamedAttributeGet(toMlirStringRef(it.first), it.second)); + mlirNamedAttributes.push_back(mlirNamedAttributeGet( + mlirIdentifierGet(mlirAttributeGetContext(it.second), + toMlirStringRef(it.first)), + it.second)); mlirOperationStateAddAttributes(&state, mlirNamedAttributes.size(), mlirNamedAttributes.data()); } @@ -1134,7 +1136,10 @@ PyNamedAttribute::PyNamedAttribute(MlirAttribute attr, std::string ownedName) : ownedName(new std::string(std::move(ownedName))) { - namedAttr = mlirNamedAttributeGet(toMlirStringRef(*this->ownedName), attr); + namedAttr = mlirNamedAttributeGet( + mlirIdentifierGet(mlirAttributeGetContext(attr), + toMlirStringRef(*this->ownedName)), + attr); } //------------------------------------------------------------------------------ @@ -1373,8 +1378,9 @@ } MlirNamedAttribute namedAttr = mlirOperationGetAttribute(operation->get(), index); - return PyNamedAttribute(namedAttr.attribute, - std::string(namedAttr.name.data)); + return PyNamedAttribute( + namedAttr.attribute, + std::string(mlirIdentifierStr(namedAttr.name).data)); } void dunderSetItem(const std::string &name, PyAttribute attr) { @@ -3137,7 +3143,8 @@ [](PyNamedAttribute &self) { PyPrintAccumulator printAccum; printAccum.parts.append("NamedAttribute("); - printAccum.parts.append(self.namedAttr.name.data); + printAccum.parts.append( + mlirIdentifierStr(self.namedAttr.name).data); printAccum.parts.append("="); mlirAttributePrint(self.namedAttr.attribute, printAccum.getCallback(), @@ -3148,8 +3155,8 @@ .def_property_readonly( "name", [](PyNamedAttribute &self) { - return py::str(self.namedAttr.name.data, - self.namedAttr.name.length); + return py::str(mlirIdentifierStr(self.namedAttr.name).data, + mlirIdentifierStr(self.namedAttr.name).length); }, "The name of the NamedAttribute binding") .def_property_readonly( diff --git a/mlir/lib/CAPI/IR/BuiltinAttributes.cpp b/mlir/lib/CAPI/IR/BuiltinAttributes.cpp --- a/mlir/lib/CAPI/IR/BuiltinAttributes.cpp +++ b/mlir/lib/CAPI/IR/BuiltinAttributes.cpp @@ -82,7 +82,7 @@ intptr_t pos) { NamedAttribute attribute = unwrap(attr).cast().getValue()[pos]; - return {wrap(attribute.first.strref()), wrap(attribute.second)}; + return {wrap(attribute.first), wrap(attribute.second)}; } MlirAttribute mlirDictionaryAttrGetElementByName(MlirAttribute attr, diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp --- a/mlir/lib/CAPI/IR/IR.cpp +++ b/mlir/lib/CAPI/IR/IR.cpp @@ -308,7 +308,7 @@ MlirNamedAttribute mlirOperationGetAttribute(MlirOperation op, intptr_t pos) { NamedAttribute attr = unwrap(op)->getAttrs()[pos]; - return MlirNamedAttribute{wrap(attr.first.strref()), wrap(attr.second)}; + return MlirNamedAttribute{wrap(attr.first), wrap(attr.second)}; } MlirAttribute mlirOperationGetAttributeByName(MlirOperation op, @@ -586,7 +586,7 @@ void mlirAttributeDump(MlirAttribute attr) { unwrap(attr).dump(); } -MlirNamedAttribute mlirNamedAttributeGet(MlirStringRef name, +MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name, MlirAttribute attr) { return MlirNamedAttribute{name, attr}; } diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c --- a/mlir/test/CAPI/ir.c +++ b/mlir/test/CAPI/ir.c @@ -89,10 +89,12 @@ MlirAttribute funcNameAttr = mlirAttributeParseGet(ctx, mlirStringRefCreateFromCString("\"add\"")); MlirNamedAttribute funcAttrs[] = { - mlirNamedAttributeGet(mlirStringRefCreateFromCString("type"), - funcTypeAttr), - mlirNamedAttributeGet(mlirStringRefCreateFromCString("sym_name"), - funcNameAttr)}; + mlirNamedAttributeGet( + mlirIdentifierGet(ctx, mlirStringRefCreateFromCString("type")), + funcTypeAttr), + mlirNamedAttributeGet( + mlirIdentifierGet(ctx, mlirStringRefCreateFromCString("sym_name")), + funcNameAttr)}; MlirOperationState funcState = mlirOperationStateGet(mlirStringRefCreateFromCString("func"), location); mlirOperationStateAddAttributes(&funcState, 2, funcAttrs); @@ -105,7 +107,8 @@ MlirAttribute indexZeroLiteral = mlirAttributeParseGet(ctx, mlirStringRefCreateFromCString("0 : index")); MlirNamedAttribute indexZeroValueAttr = mlirNamedAttributeGet( - mlirStringRefCreateFromCString("value"), indexZeroLiteral); + mlirIdentifierGet(ctx, mlirStringRefCreateFromCString("value")), + indexZeroLiteral); MlirOperationState constZeroState = mlirOperationStateGet( mlirStringRefCreateFromCString("std.constant"), location); mlirOperationStateAddResults(&constZeroState, 1, &indexType); @@ -130,7 +133,8 @@ MlirAttribute indexOneLiteral = mlirAttributeParseGet(ctx, mlirStringRefCreateFromCString("1 : index")); MlirNamedAttribute indexOneValueAttr = mlirNamedAttributeGet( - mlirStringRefCreateFromCString("value"), indexOneLiteral); + mlirIdentifierGet(ctx, mlirStringRefCreateFromCString("value")), + indexOneLiteral); MlirOperationState constOneState = mlirOperationStateGet( mlirStringRefCreateFromCString("std.constant"), location); mlirOperationStateAddResults(&constOneState, 1, &indexType); @@ -375,8 +379,8 @@ // CHECK: Get attr 0: 0 : index // Now re-get the attribute by name. - MlirAttribute attr0ByName = - mlirOperationGetAttributeByName(operation, namedAttr0.name); + MlirAttribute attr0ByName = mlirOperationGetAttributeByName( + operation, mlirIdentifierStr(namedAttr0.name)); fprintf(stderr, "Get attr 0 by name: "); mlirAttributePrint(attr0ByName, printToStderr, NULL); fprintf(stderr, "\n");