[Mlir-commits] [mlir] Reimplementing target description concept using DLTI attribute (PR #92138)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Wed May 29 09:06:56 PDT 2024


================
@@ -277,51 +236,179 @@ DataLayoutSpecAttr::combineWith(ArrayRef<DataLayoutSpecInterface> specs) const {
   return DataLayoutSpecAttr::get(getContext(), entries);
 }
 
-DataLayoutEntryListRef DataLayoutSpecAttr::getEntries() const {
-  return getImpl()->entries;
+/// Parses an attribute with syntax
+///   attr ::= `#target.` `dl_spec` `<` attr-list? `>`
+///   attr-list ::= attr
+///               | attr `,` attr-list
+Attribute DataLayoutSpecAttr::parse(AsmParser &parser, Type type) {
+  if (failed(parser.parseLess()))
+    return {};
+
+  // Empty spec.
+  if (succeeded(parser.parseOptionalGreater()))
+    return get(parser.getContext(), {});
+
+  SmallVector<DataLayoutEntryInterface> entries;
+  if (parser.parseCommaSeparatedList(
+          [&]() { return parser.parseAttribute(entries.emplace_back()); }) ||
+      parser.parseGreater())
+    return {};
+
+  return getChecked([&] { return parser.emitError(parser.getNameLoc()); },
+                    parser.getContext(), entries);
 }
 
-StringAttr
-DataLayoutSpecAttr::getEndiannessIdentifier(MLIRContext *context) const {
-  return Builder(context).getStringAttr(DLTIDialect::kDataLayoutEndiannessKey);
+void DataLayoutSpecAttr::print(AsmPrinter &os) const {
+  os << "<";
+  llvm::interleaveComma(getEntries(), os);
+  os << ">";
 }
 
-StringAttr
-DataLayoutSpecAttr::getAllocaMemorySpaceIdentifier(MLIRContext *context) const {
-  return Builder(context).getStringAttr(
-      DLTIDialect::kDataLayoutAllocaMemorySpaceKey);
+//===----------------------------------------------------------------------===//
+// TargetDeviceDescSpecAttr
+//===----------------------------------------------------------------------===//
+
+LogicalResult
+TargetDeviceDescSpecAttr::verify(function_ref<InFlightDiagnostic()> emitError,
+                                 ArrayRef<DataLayoutEntryInterface> entries) {
+  // Entries in tdd_spec can only have StringAttr as key. It does not support
----------------
ftynse wrote:

Nit: what is `tdd_spec`?

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


More information about the Mlir-commits mailing list