[Mlir-commits] [mlir] [MLIR][DLTI] Introduce DLTIQueryInterface and impl for DLTI attrs (PR #104595)

Adam Siemieniuk llvmlistbot at llvm.org
Mon Aug 19 02:48:31 PDT 2024


================
@@ -93,20 +85,63 @@ def DLTI_DataLayoutSpecAttr :
 
     /// Returns the stack alignment identifier.
     StringAttr getStackAlignmentIdentifier(MLIRContext *context) const;
+
+    /// Returns the attribute associated with the key.
+    FailureOr<Attribute> query(DataLayoutEntryKey key) {
+      return llvm::cast<mlir::DataLayoutSpecInterface>(*this).queryHelper(key);
+    }
+  }];
+}
+
+def DLTI_MapAttr : DLTIAttr<"Map", [DLTIQueryInterface]> {
+  let summary = "A mapping of DLTI-information by way of key-value pairs";
+  let description = [{
+    A Data Layout and Target Information map is a list of entries effectively
+    encoding a dictionary, mapping DLTI-related keys to DLTI-related values.
+
+    This attribute's main purpose is to facilate querying IR for arbitrary
+    DLTI-related key-value associations. Note that facility functions exist to
+    perform recursive lookups on nested DLTI map attributes.
+
+    Consider the following shallow usage of a DLTI-map
+    ```
+    #dlti.map<#dlti.dl_entry<"CPU::cache::L1::size_in_bytes", 65536 : i32>>
+    ```
+    versus nested maps, which make it possible to obtain sub-dictionaries of
+    related information (with the following example making use of other
+    attributes that also implement the `DLTIQueryInterface`):
+    ```
+    #dlti.target_system_spec<"CPU":
----------------
adam-smnk wrote:

I take it that these two representations are equivalent for the `L1::size_in_bytes`.
Is there any way to have the same query grab the `size_in_bytes` entry for either?

For example, `transform.dlti.query ["CPU","cache","L1","size_in_bytes"]` is unable to handle the shallow case.

https://github.com/llvm/llvm-project/pull/104595


More information about the Mlir-commits mailing list