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

Mehdi Amini llvmlistbot at llvm.org
Tue Jun 18 15:19:16 PDT 2024


================
@@ -744,6 +821,56 @@ LogicalResult mlir::detail::verifyDataLayoutSpec(DataLayoutSpecInterface spec,
   return success();
 }
 
+LogicalResult
+mlir::detail::verifyTargetSystemSpec(TargetSystemSpecInterface spec,
+                                     Location loc) {
+  DenseMap<StringAttr, DataLayoutEntryInterface> device_desc_keys;
+  DenseSet<TargetSystemSpecInterface::DeviceID> device_ids;
+  for (const auto &entry : spec.getEntries()) {
+    TargetDeviceSpecInterface tdd_spec = entry.second;
+    // First, verify individual target device desc specs.
+    if (failed(tdd_spec.verifyEntry(loc)))
+      return failure();
+
+    // Check that device IDs are unique across all entries.
+    TargetSystemSpecInterface::DeviceID device_id = entry.first;
+    if (!device_ids.insert(device_id).second) {
+      return failure();
+    }
+
+    // collect all the keys used by all the tdd_specs.
+    for (DataLayoutEntryInterface entry : tdd_spec.getEntries()) {
+      if (auto type = llvm::dyn_cast_if_present<Type>(entry.getKey())) {
+        // tdd_spec does not support Type as a key.
+        return failure();
+      } else {
+        device_desc_keys[entry.getKey().get<StringAttr>()] = entry;
+      }
+    }
+  }
+
+  for (const auto &kvp : device_desc_keys) {
+    StringAttr identifier = kvp.second.getKey().get<StringAttr>();
+    Dialect *dialect = identifier.getReferencedDialect();
+
+    // Ignore attributes that belong to an unknown dialect, the dialect may
+    // actually implement the relevant interface but we don't know about that.
+    if (!dialect)
+      continue;
----------------
joker-eph wrote:

Unless the context is setup with `allowUnregisteredDialect`, shouldn't this be an error?

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


More information about the Mlir-commits mailing list