[Mlir-commits] [mlir] [mlir][dlti] Query by strings (PR #126716)

Adam Siemieniuk llvmlistbot at llvm.org
Tue Feb 11 03:38:29 PST 2025


https://github.com/adam-smnk created https://github.com/llvm/llvm-project/pull/126716

Adds DLTI utility to query using strings directly as keys.

>From bf0aa8aab4b6cd08567874930a3b1702555c2060 Mon Sep 17 00:00:00 2001
From: Adam Siemieniuk <adam.siemieniuk at intel.com>
Date: Tue, 11 Feb 2025 12:20:45 +0100
Subject: [PATCH] [mlir][dlti] Query by strings

Adds DLTI utility to query using strings directly as keys.
---
 mlir/include/mlir/Dialect/DLTI/DLTI.h |  6 ++++++
 mlir/lib/Dialect/DLTI/DLTI.cpp        | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/mlir/include/mlir/Dialect/DLTI/DLTI.h b/mlir/include/mlir/Dialect/DLTI/DLTI.h
index f268fea340a6fb1..4004c2f64e6da03 100644
--- a/mlir/include/mlir/Dialect/DLTI/DLTI.h
+++ b/mlir/include/mlir/Dialect/DLTI/DLTI.h
@@ -28,6 +28,12 @@ namespace dlti {
 /// query interface-implementing attrs, starting from attr obtained from `op`.
 FailureOr<Attribute> query(Operation *op, ArrayRef<DataLayoutEntryKey> keys,
                            bool emitError = false);
+
+/// Perform a DLTI-query at `op` using string `keys` as DLTI entry keys,
+/// recursively querying on query interface-implementing attrs, starting from
+/// attr obtained from `op`.
+FailureOr<Attribute> query(Operation *op, ArrayRef<StringRef> keys,
+                           bool emitError = false);
 } // namespace dlti
 } // namespace mlir
 
diff --git a/mlir/lib/Dialect/DLTI/DLTI.cpp b/mlir/lib/Dialect/DLTI/DLTI.cpp
index 2510e774f2b2aa1..86bee1933268bcf 100644
--- a/mlir/lib/Dialect/DLTI/DLTI.cpp
+++ b/mlir/lib/Dialect/DLTI/DLTI.cpp
@@ -508,6 +508,9 @@ getClosestQueryable(Operation *op) {
 
 FailureOr<Attribute>
 dlti::query(Operation *op, ArrayRef<DataLayoutEntryKey> keys, bool emitError) {
+  if (!op)
+    return failure();
+
   if (keys.empty()) {
     if (emitError) {
       auto diag = op->emitError() << "target op of failed DLTI query";
@@ -562,6 +565,19 @@ dlti::query(Operation *op, ArrayRef<DataLayoutEntryKey> keys, bool emitError) {
   return currentAttr;
 }
 
+FailureOr<Attribute> dlti::query(Operation *op, ArrayRef<StringRef> keys,
+                                 bool emitError) {
+  if (!op)
+    return failure();
+
+  MLIRContext *ctx = op->getContext();
+  SmallVector<DataLayoutEntryKey> entryKeys;
+  for (StringRef key : keys)
+    entryKeys.push_back(StringAttr::get(ctx, key));
+
+  return dlti::query(op, entryKeys, emitError);
+}
+
 constexpr const StringLiteral mlir::DLTIDialect::kDataLayoutAttrName;
 constexpr const StringLiteral mlir::DLTIDialect::kDataLayoutEndiannessKey;
 constexpr const StringLiteral mlir::DLTIDialect::kDataLayoutEndiannessBig;



More information about the Mlir-commits mailing list