[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
+ // type as a key. Hence not reusing DataLayoutEntryInterface::verify.
+ bool targetDeviceIDKeyPresentAndValid = false;
+ bool targetDeviceTypeKeyPresentAndValid = false;
+
+ DenseSet<StringAttr> ids;
+ for (DataLayoutEntryInterface entry : entries) {
+ if (auto type = llvm::dyn_cast_if_present<Type>(entry.getKey())) {
+ return emitError()
+ << "dlti.target_device_desc_spec does not allow type as a key: "
+ << type;
+ } else {
+ auto id = entry.getKey().get<StringAttr>();
+ if (!ids.insert(id).second)
+ return emitError() << "repeated layout entry key: " << id.getValue();
+ }
+
+ // check that Device ID and Device Type are present.
----------------
ftynse wrote:
```suggestion
// Check that Device ID and Device Type are present.
```
https://github.com/llvm/llvm-project/pull/92138
More information about the Mlir-commits
mailing list