Skip to content

[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

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mlir/include/mlir/Dialect/DLTI/DLTI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions mlir/lib/Dialect/DLTI/DLTI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down