@@ -20,6 +20,7 @@ include "IRDLInterfaces.td"
20
20
include "mlir/Interfaces/SideEffectInterfaces.td"
21
21
include "mlir/Interfaces/InferTypeOpInterface.td"
22
22
include "mlir/IR/SymbolInterfaces.td"
23
+ include "mlir/IR/BuiltinAttributes.td"
23
24
24
25
class IRDL_Op<string mnemonic, list<Trait> traits = []>
25
26
: Op<IRDL_Dialect, mnemonic, traits>;
@@ -133,7 +134,7 @@ def IRDL_ParametersOp : IRDL_Op<"parameters",
133
134
"Define the constraints on parameters of a type/attribute definition";
134
135
let description = [{
135
136
`irdl.parameters` defines the constraints on parameters of a type or
136
- attribute definition.
137
+ attribute definition. Each parameter is named after an identifier.
137
138
138
139
Example:
139
140
@@ -143,17 +144,19 @@ def IRDL_ParametersOp : IRDL_Op<"parameters",
143
144
%0 = irdl.is i32
144
145
%1 = irdl.is i64
145
146
%2 = irdl.any_of(%0, %1)
146
- irdl.parameters(%2)
147
+ irdl.parameters(elem: %2)
147
148
}
148
149
}
149
150
```
150
151
151
152
The above program defines a type `complex` inside the dialect `cmath`. The
152
- type has a single parameter that should be either `i32` or `i64`.
153
+ type has a single parameter `elem` that should be either `i32` or `i64`.
153
154
}];
154
155
155
- let arguments = (ins Variadic<IRDL_AttributeType>:$args);
156
- let assemblyFormat = " `(` $args `)` attr-dict ";
156
+ let arguments = (ins Variadic<IRDL_AttributeType>:$args,
157
+ StrArrayAttr:$names);
158
+ let assemblyFormat = " `` custom<NamedValueList>($args, $names) attr-dict ";
159
+ let hasVerifier = true;
157
160
}
158
161
159
162
//===----------------------------------------------------------------------===//
@@ -198,16 +201,17 @@ def IRDL_OperationOp : IRDL_Op<"operation",
198
201
let regions = (region SizedRegion<1>:$body);
199
202
let assemblyFormat =
200
203
"$sym_name attr-dict-with-keyword custom<SingleBlockRegion>($body)";
204
+ let hasRegionVerifier = true;
201
205
}
202
206
203
207
def IRDL_OperandsOp : IRDL_Op<"operands", [HasParent<"OperationOp">]> {
204
208
let summary = "Define the operands of an operation";
205
209
let description = [{
206
210
`irdl.operands` define the operands of the `irdl.operation` parent operation
207
- definition.
211
+ definition. Each operand is named after an identifier.
208
212
209
213
In the following example, `irdl.operands` defines the operands of the
210
- `norm ` operation:
214
+ `mul ` operation:
211
215
212
216
```mlir
213
217
irdl.dialect @cmath {
@@ -217,8 +221,8 @@ def IRDL_OperandsOp : IRDL_Op<"operands", [HasParent<"OperationOp">]> {
217
221
irdl.operation @mul {
218
222
%0 = irdl.any
219
223
%1 = irdl.parametric @cmath::@complex<%0>
220
- irdl.results(%1)
221
- irdl.operands(%1, %1)
224
+ irdl.results(res: %1)
225
+ irdl.operands(lhs: %1, rhs: %1)
222
226
}
223
227
}
224
228
```
@@ -228,43 +232,45 @@ def IRDL_OperandsOp : IRDL_Op<"operands", [HasParent<"OperationOp">]> {
228
232
229
233
The operands can also be marked as variadic or optional:
230
234
```mlir
231
- irdl.operands(%0, single %1, optional %2, variadic %3)
235
+ irdl.operands(foo: %0, bar: single %1, baz: optional %2, qux: variadic %3)
232
236
```
233
237
234
- Here, %0 and %1 are required single operands, %2 is an optional operand,
235
- and %3 is a variadic operand.
238
+ Here, foo and bar are required single operands, baz is an optional operand,
239
+ and qux is a variadic operand.
236
240
237
241
When more than one operand is marked as optional or variadic, the operation
238
242
will expect a 'operandSegmentSizes' attribute that defines the number of
239
243
operands in each segment.
240
244
}];
241
245
242
246
let arguments = (ins Variadic<IRDL_AttributeType>:$args,
243
- VariadicityArrayAttr:$variadicity);
247
+ StrArrayAttr:$names,
248
+ VariadicityArrayAttr:$variadicity);
244
249
let assemblyFormat =
245
- "`` custom<ValuesWithVariadicity >($args, $variadicity) attr-dict";
250
+ " `` custom<NamedValueListWithVariadicity >($args, $names , $variadicity) attr-dict";
246
251
let hasVerifier = true;
247
252
}
248
253
249
254
def IRDL_ResultsOp : IRDL_Op<"results", [HasParent<"OperationOp">]> {
250
255
let summary = "Define the results of an operation";
251
256
let description = [{
252
257
`irdl.results` define the results of the `irdl.operation` parent operation
253
- definition.
258
+ definition. Each result is named after an identifier.
254
259
255
260
In the following example, `irdl.results` defines the results of the
256
- `norm ` operation:
261
+ `get_values ` operation:
257
262
258
263
```mlir
259
264
irdl.dialect @cmath {
260
265
261
266
irdl.type @complex { /* ... */ }
262
267
268
+ /// Returns the real and imaginary parts of a complex number.
263
269
irdl.operation @get_values {
264
270
%0 = irdl.any
265
271
%1 = irdl.parametric @cmath::@complex<%0>
266
- irdl.results(%0, %0)
267
- irdl.operands(%1)
272
+ irdl.results(re: %0, im: %0)
273
+ irdl.operands(complex: %1)
268
274
}
269
275
}
270
276
```
@@ -274,21 +280,22 @@ def IRDL_ResultsOp : IRDL_Op<"results", [HasParent<"OperationOp">]> {
274
280
275
281
The results can also be marked as variadic or optional:
276
282
```mlir
277
- irdl.results(%0, single %1, optional %2, variadic %3)
283
+ irdl.results(foo: %0, bar: single %1, baz: optional %2, qux: variadic %3)
278
284
```
279
285
280
- Here, %0 and %1 are required single results, %2 is an optional result,
281
- and %3 is a variadic result.
286
+ Here, foo and bar are required single results, baz is an optional result,
287
+ and qux is a variadic result.
282
288
283
289
When more than one result is marked as optional or variadic, the operation
284
290
will expect a 'resultSegmentSizes' attribute that defines the number of
285
291
results in each segment.
286
292
}];
287
293
288
294
let arguments = (ins Variadic<IRDL_AttributeType>:$args,
295
+ StrArrayAttr:$names,
289
296
VariadicityArrayAttr:$variadicity);
290
297
let assemblyFormat =
291
- " `` custom<ValuesWithVariadicity >($args, $variadicity) attr-dict";
298
+ " `` custom<NamedValueListWithVariadicity >($args, $names , $variadicity) attr-dict";
292
299
let hasVerifier = true;
293
300
}
294
301
@@ -335,7 +342,8 @@ def IRDL_RegionOp : IRDL_Op<"region",
335
342
let summary = "Define a region of an operation";
336
343
let description = [{
337
344
The irdl.region construct defines a set of characteristics
338
- that a region of an operation should satify.
345
+ that a region of an operation should satify. Each region is named after
346
+ an identifier.
339
347
340
348
These characteristics include constraints for the entry block arguments
341
349
of the region and the total number of blocks it contains.
@@ -360,19 +368,19 @@ def IRDL_RegionOp : IRDL_Op<"region",
360
368
%r2 = irdl.region(%v0, %v1)
361
369
%r3 = irdl.region with size 3
362
370
363
- irdl.regions(%r0, %r1, %r2, %r3)
371
+ irdl.regions(foo: %r0, bar: %r1, baz: %r2, qux: %r3)
364
372
}
365
373
}
366
374
```
367
375
368
376
The above snippet demonstrates an operation named `@op_with_regions`,
369
377
which is constrained to have four regions.
370
378
371
- * Region `%r0 ` doesn't have any constraints on the arguments
379
+ * Region `foo ` doesn't have any constraints on the arguments
372
380
or the number of blocks.
373
- * Region `%r1 ` should have an empty set of arguments.
374
- * Region `%r2 ` should have two arguments of types `i32` and `i64`.
375
- * Region `%r3 ` should contain exactly three blocks.
381
+ * Region `bar ` should have an empty set of arguments.
382
+ * Region `baz ` should have two arguments of types `i32` and `i64`.
383
+ * Region `qux ` should contain exactly three blocks.
376
384
}];
377
385
let arguments = (ins Variadic<IRDL_AttributeType>:$entryBlockArgs,
378
386
OptionalAttr<I32Attr>:$numberOfBlocks,
@@ -391,7 +399,8 @@ def IRDL_RegionsOp : IRDL_Op<"regions", [HasParent<"OperationOp">]> {
391
399
let summary = "Define the regions of an operation";
392
400
let description = [{
393
401
`irdl.regions` defines the regions of an operation by accepting
394
- values produced by `irdl.region` operation as arguments.
402
+ values produced by `irdl.region` operation as arguments. Each
403
+ region has an identifier as name.
395
404
396
405
Example:
397
406
@@ -401,18 +410,19 @@ def IRDL_RegionsOp : IRDL_Op<"regions", [HasParent<"OperationOp">]> {
401
410
%r1 = irdl.region with size 3
402
411
%0 = irdl.any
403
412
%r2 = irdl.region(%0)
404
- irdl.regions(%r1, %r2)
413
+ irdl.regions(foo: %r1, bar: %r2)
405
414
}
406
415
}
407
416
```
408
417
409
418
In the snippet above the operation is constrained to have two regions.
410
- The first region should contain three blocks.
411
- The second region should have one region with one argument.
419
+ The first region (`foo`) should contain three blocks.
420
+ The second region (`bar`) should have one region with one argument.
412
421
}];
413
422
414
- let arguments = (ins Variadic<IRDL_RegionType>:$args);
415
- let assemblyFormat = " `(` $args `)` attr-dict ";
423
+ let arguments = (ins Variadic<IRDL_RegionType>:$args, StrArrayAttr:$names);
424
+ let assemblyFormat = " `` custom<NamedValueList>($args, $names) attr-dict ";
425
+ let hasVerifier = true;
416
426
}
417
427
418
428
//===----------------------------------------------------------------------===//
0 commit comments