[Mlir-commits] [mlir] 0b9b014 - [mlir][dlti] Query by strings (#126716)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Feb 12 00:13:46 PST 2025
Author: Adam Siemieniuk
Date: 2025-02-12T09:13:43+01:00
New Revision: 0b9b014be7f5130e2ac2809cb1914441b7870a7e
URL: https://github.com/llvm/llvm-project/commit/0b9b014be7f5130e2ac2809cb1914441b7870a7e
DIFF: https://github.com/llvm/llvm-project/commit/0b9b014be7f5130e2ac2809cb1914441b7870a7e.diff
LOG: [mlir][dlti] Query by strings (#126716)
Adds DLTI utility to query using strings directly as keys.
Added:
Modified:
mlir/include/mlir/Dialect/DLTI/DLTI.h
mlir/lib/Dialect/DLTI/DLTI.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/DLTI/DLTI.h b/mlir/include/mlir/Dialect/DLTI/DLTI.h
index f268fea340a6f..84cf6eabc5fa9 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 each string in `keys` as a separate DLTI
+/// entry key, 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 2510e774f2b2a..b057554c40d8c 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(keys.size());
+ 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