10
10
#define MLIR_DIALECT_DLTI_DLTIATTRS_TD
11
11
12
12
include "mlir/Dialect/DLTI/DLTI.td"
13
+ include "mlir/Interfaces/DataLayoutInterfaces.td"
13
14
include "mlir/IR/AttrTypeBase.td"
14
15
15
16
class DLTIAttr<string name, list<Trait> traits = [],
@@ -20,13 +21,8 @@ class DLTIAttr<string name, list<Trait> traits = [],
20
21
// DataLayoutEntryAttr
21
22
//===----------------------------------------------------------------------===//
22
23
23
- def DataLayoutEntryTrait
24
- : NativeAttrTrait<"DataLayoutEntryInterface::Trait"> {
25
- let cppNamespace = "::mlir";
26
- }
27
-
28
24
def DLTI_DataLayoutEntryAttr :
29
- DLTIAttr<"DataLayoutEntry", [DataLayoutEntryTrait ]> {
25
+ DLTIAttr<"DataLayoutEntry", [DataLayoutEntryInterface ]> {
30
26
let summary = "An attribute to represent an entry of a data layout specification.";
31
27
let description = [{
32
28
A data layout entry attribute is a key-value pair where the key is a type or
@@ -53,13 +49,9 @@ def DLTI_DataLayoutEntryAttr :
53
49
//===----------------------------------------------------------------------===//
54
50
// DataLayoutSpecAttr
55
51
//===----------------------------------------------------------------------===//
56
- def DataLayoutSpecTrait
57
- : NativeAttrTrait<"DataLayoutSpecInterface::Trait"> {
58
- let cppNamespace = "::mlir";
59
- }
60
52
61
53
def DLTI_DataLayoutSpecAttr :
62
- DLTIAttr<"DataLayoutSpec", [DataLayoutSpecTrait ]> {
54
+ DLTIAttr<"DataLayoutSpec", [DataLayoutSpecInterface ]> {
63
55
let summary = "An attribute to represent a data layout specification.";
64
56
let description = [{
65
57
A data layout specification is a list of entries that specify (partial) data
@@ -78,7 +70,7 @@ def DLTI_DataLayoutSpecAttr :
78
70
/// same key as the newer entries if the entries are compatible. Returns null
79
71
/// if the specifications are not compatible.
80
72
DataLayoutSpecAttr combineWith(ArrayRef<DataLayoutSpecInterface> specs) const;
81
-
73
+
82
74
/// Returns the endiannes identifier.
83
75
StringAttr getEndiannessIdentifier(MLIRContext *context) const;
84
76
@@ -93,20 +85,63 @@ def DLTI_DataLayoutSpecAttr :
93
85
94
86
/// Returns the stack alignment identifier.
95
87
StringAttr getStackAlignmentIdentifier(MLIRContext *context) const;
88
+
89
+ /// Returns the attribute associated with the key.
90
+ FailureOr<Attribute> query(DataLayoutEntryKey key) {
91
+ return llvm::cast<mlir::DataLayoutSpecInterface>(*this).queryHelper(key);
92
+ }
93
+ }];
94
+ }
95
+
96
+ def DLTI_MapAttr : DLTIAttr<"Map", [DLTIQueryInterface]> {
97
+ let summary = "A mapping of DLTI-information by way of key-value pairs";
98
+ let description = [{
99
+ A data layout and target information map is a list of entries is
100
+ effectively a dictionary mapping DLTI-related keys to DLTI-related values.
101
+
102
+ Its main purpose is to facilate querying IR for arbitrary DLTI-related
103
+ key-value associations. Note that facility functions exist to perform
104
+ nested lookups on nested DLTI map attributes.
105
+
106
+ Consider the following shallow usage of a DLTI-map
107
+ ```
108
+ #dlti.map<#dlti.dl_entry<"CPU::cache::L1::size_in_bytes", 65536 : i32>>
109
+ ```
110
+ versus nested maps, which make it possible to obtain sub-dictionaries of
111
+ related information (with the following example making use of other
112
+ attributes that also implement the `DLTIQueryInterface`):
113
+ ```
114
+ #dlti.target_system_spec<"CPU":
115
+ #dlti.target_device_spec<#dlti.dl_entry<"cache",
116
+ #dlti.map<#dlti.dl_entry<"L1",
117
+ #dlti.map<#dlti.dl_entry<"size_in_bytes", 65536 : i32>>,
118
+ #dlti.dl_entry<"L1d",
119
+ #dlti.map<#dlti.dl_entry<"size_in_bytes", 32768 : i32>> >>>>
120
+ ```
121
+ }];
122
+ let parameters = (ins
123
+ ArrayRefParameter<"DataLayoutEntryInterface", "">:$entries
124
+ );
125
+ let mnemonic = "map";
126
+ let genVerifyDecl = 1;
127
+ let assemblyFormat = "`<` $entries `>`";
128
+ let extraClassDeclaration = [{
129
+ /// Returns the attribute associated with the key.
130
+ FailureOr<Attribute> query(DataLayoutEntryKey key) {
131
+ for (DataLayoutEntryInterface entry : getEntries())
132
+ if (entry.getKey() == key)
133
+ return entry.getValue();
134
+ return ::mlir::failure();
135
+ }
96
136
}];
97
137
}
98
138
99
139
//===----------------------------------------------------------------------===//
100
140
// TargetSystemSpecAttr
101
141
//===----------------------------------------------------------------------===//
102
142
103
- def TargetSystemSpecTrait
104
- : NativeAttrTrait<"TargetSystemSpecInterface::Trait"> {
105
- let cppNamespace = "::mlir";
106
- }
107
-
108
143
def DLTI_TargetSystemSpecAttr :
109
- DLTIAttr<"TargetSystemSpec", [TargetSystemSpecTrait ]> {
144
+ DLTIAttr<"TargetSystemSpec", [TargetSystemSpecInterface ]> {
110
145
let summary = "An attribute to represent target system specification.";
111
146
let description = [{
112
147
A system specification describes the overall system containing
@@ -136,6 +171,11 @@ def DLTI_TargetSystemSpecAttr :
136
171
std::optional<TargetDeviceSpecInterface>
137
172
getDeviceSpecForDeviceID(
138
173
TargetSystemSpecInterface::DeviceID deviceID);
174
+
175
+ /// Returns the attribute associated with the key.
176
+ FailureOr<Attribute> query(DataLayoutEntryKey key) const {
177
+ return llvm::cast<mlir::TargetSystemSpecInterface>(*this).queryHelper(key);
178
+ }
139
179
}];
140
180
let extraClassDefinition = [{
141
181
std::optional<TargetDeviceSpecInterface>
@@ -154,13 +194,8 @@ def DLTI_TargetSystemSpecAttr :
154
194
// TargetDeviceSpecAttr
155
195
//===----------------------------------------------------------------------===//
156
196
157
- def TargetDeviceSpecTrait
158
- : NativeAttrTrait<"TargetDeviceSpecInterface::Trait"> {
159
- let cppNamespace = "::mlir";
160
- }
161
-
162
197
def DLTI_TargetDeviceSpecAttr :
163
- DLTIAttr<"TargetDeviceSpec", [TargetDeviceSpecTrait ]> {
198
+ DLTIAttr<"TargetDeviceSpec", [TargetDeviceSpecInterface ]> {
164
199
let summary = "An attribute to represent target device specification.";
165
200
let description = [{
166
201
Each device specification describes a single device and its
@@ -179,6 +214,13 @@ def DLTI_TargetDeviceSpecAttr :
179
214
let mnemonic = "target_device_spec";
180
215
let genVerifyDecl = 1;
181
216
let assemblyFormat = "`<` $entries `>`";
217
+
218
+ let extraClassDeclaration = [{
219
+ /// Returns the attribute associated with the key.
220
+ FailureOr<Attribute> query(DataLayoutEntryKey key) const {
221
+ return llvm::cast<mlir::TargetDeviceSpecInterface>(*this).queryHelper(key);
222
+ }
223
+ }];
182
224
}
183
225
184
226
#endif // MLIR_DIALECT_DLTI_DLTIATTRS_TD
0 commit comments