This is an archive of the discontinued LLVM Phabricator instance.

[mlir][irdl] Add Variadicity to IRDL operations
ClosedPublic

Authored by math-fehr on Jun 28 2023, 8:14 AM.

Details

Summary

This patch adds optional and variadic operands and results
to IRDL. These are added using the irdl.variadicity attribute,
which has to be attached to every irdl.operands and irdl.results
operations.

For instance:

mlir
irdl.operands(%0, single %1, optional %2, variadic %3)

has 4 operand definitions. The first two are single operands,
the second one is optional, and the last one is variadic.

Note that this patch only adds the variadicities to the definition,
but does not consider them when loading a dialect at runtime. This
will be done in the next patch.

Diff Detail

Event Timeline

math-fehr created this revision.Jun 28 2023, 8:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2023, 8:14 AM
math-fehr requested review of this revision.Jun 28 2023, 8:14 AM
Mogball added inline comments.Jun 29 2023, 9:57 AM
mlir/include/mlir/Dialect/IRDL/IR/IRDLAttributes.td
55

Check out ArrayOfAttr in AttrTypeBase.td for a stronger-typed array of attributes thing

mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
276

nice

mlir/lib/Dialect/IRDL/IR/IRDL.cpp
92

please drop the consts around here

Thanks for inviting to review :)
Shared my thoughts below

mlir/include/mlir/Dialect/IRDL/IR/IRDLAttributes.td
21–24

It is not used anywhere, if I'm not mistaken
Is it intentional?

29–31

I've checked the code and it seems like the third parameter for I32EnumAttrCase is optional and is defaulted to the first one. So, I think it's better to avoid the unnecessary repetition.

mlir/lib/Dialect/IRDL/IR/IRDL.cpp
139

To me, as an MLIR novice, it was not obvious that "parse" functions return true when the parsing is failed. To be exact, that the result of ParseResult conversion to bool.
I don't ask to change anything, just sharing my thoughts.

157

Optional thing

173–197

It seems like the docs are not relevant for the functions
The one for the parseAttributesOp should be actually for the printValuesWithVariadicity function

mlir/test/Dialect/IRDL/variadics.irdl.mlir
16–53

Minor thing: I wonder if the single variadicity should be tested inside operands op? Since the operands and result ops use the same parser, it's not as big of a deal

unterumarmung added inline comments.Jul 1 2023, 2:05 PM
mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
290

What do the backticks in the beginning mean?

unterumarmung added inline comments.Jul 1 2023, 2:07 PM
mlir/test/Dialect/IRDL/variadics.irdl.mlir
16–53

I'm sorry, I missed the @single_operand test when I was reviewing the first time

math-fehr updated this revision to Diff 538155.Jul 7 2023, 8:36 AM
math-fehr marked 10 inline comments as done.

Address comments

mlir/include/mlir/Dialect/IRDL/IR/IRDLOps.td
290

It means that no space should be added after the operation name.

mlir/lib/Dialect/IRDL/IR/IRDL.cpp
173–197

Oh good catch, thanks!

unterumarmung accepted this revision.Jul 7 2023, 11:11 AM

LGTM but I'm not sure that my vote is enough

This revision is now accepted and ready to land.Jul 7 2023, 11:11 AM

@Mogball, is that good to merge?

Mogball accepted this revision.Jul 25 2023, 8:24 AM
math-fehr updated this revision to Diff 544013.Jul 25 2023, 9:23 AM

Update to main

math-fehr updated this revision to Diff 544331.Jul 26 2023, 6:10 AM

Update to main

Update to main

This revision was landed with ongoing or failed builds.Jul 26 2023, 10:17 AM
This revision was automatically updated to reflect the committed changes.