This is an archive of the discontinued LLVM Phabricator instance.

[mlir][pdl] Restructure how results are represented.

Authored by rriddle on Jan 29 2021, 7:55 PM.



Up until now, results have been represented as additional results to a pdl.operation. This is fairly clunky, as it mismatches the representation of the rest of the IR constructs(e.g. pdl.operand) and also isn't a viable representation for operations returned by pdl.create_native. This representation also creates much more difficult problems when factoring in support for variadic result groups, optional results, etc. To resolve some of these problems, and simplify adding support for variable length results, this revision extracts the representation for results out of pdl.operation in the form of a new pdl.result operation. This operation returns the result of an operation at a given index, e.g.:

%root = pdl.operation ...
%result = pdl.result 0 of %root

Depends On D95718

Diff Detail

Event Timeline

rriddle created this revision.Jan 29 2021, 7:55 PM
rriddle requested review of this revision.Jan 29 2021, 7:55 PM
ftynse accepted this revision.Mar 10 2021, 6:12 AM
ftynse added a subscriber: ftynse.
ftynse added inline comments.

Nit: mention that the result index is zero-based

This revision is now accepted and ready to land.Mar 10 2021, 6:12 AM
jpienaar accepted this revision.Mar 10 2021, 9:45 AM
jpienaar added inline comments.

And this index is of the underlying Operation, and not the ODS index concept?


Perhaps expanding this example to show a multi result operation being matched would make this clearer (so show post the example an example match)

rriddle updated this revision to Diff 330787.Mar 15 2021, 1:24 PM
rriddle marked 3 inline comments as done.


rriddle added inline comments.Mar 15 2021, 1:27 PM

Yeah. Results are kind of weird/different in comparison to operands, given that operands are inputs into a pdl.operation we don't have to make a distinction between the ODS group and the concrete operand number. For results, we don't necessarily know how the operation was created(e.g. could come from a native rewrite) so there has to be some way for the user to make the distinction. Right now that is by having pdl.result be concrete and pdl.results be group based. My suspicion is that we may come up with something more ergonomic (or at least spelled better) as we use them more.

This revision was automatically updated to reflect the committed changes.