[Mlir-commits] [mlir] [mlir][dlti] Query by strings (PR #126716)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Feb 11 03:39:02 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-mlir-dlti
Author: Adam Siemieniuk (adam-smnk)
<details>
<summary>Changes</summary>
Adds DLTI utility to query using strings directly as keys.
---
Full diff: https://github.com/llvm/llvm-project/pull/126716.diff
2 Files Affected:
- (modified) mlir/include/mlir/Dialect/DLTI/DLTI.h (+6)
- (modified) mlir/lib/Dialect/DLTI/DLTI.cpp (+16)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/126716
More information about the Mlir-commits
mailing list