-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[mlir][dlti] Query by strings #126716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][dlti] Query by strings #126716
Conversation
Adds DLTI utility to query using strings directly as keys.
|
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-dlti Author: Adam Siemieniuk (adam-smnk) ChangesAdds DLTI utility to query using strings directly as keys. Full diff: https://github.com/llvm/llvm-project/pull/126716.diff 2 Files Affected:
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;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excepting the two nits up above, LGTM.
Adds DLTI utility to query using strings directly as keys.
Adds DLTI utility to query using strings directly as keys.
Fixes upfront space allocation after llvm#126716
Fixes upfront space allocation after #126716
Adds DLTI utility to query using strings directly as keys.
Adds DLTI utility to query using strings directly as keys.