This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Use GenericAdaptor to simplify 1:N type conversion API.
ClosedPublic

Authored by ingomueller-net on Mar 30 2023, 5:51 AM.

Details

Summary

For 1:N type conversion, there is a 1:N relationship between the
original operands and the converted operands. The same is true for the
results. The previous design passed an instance of a "mapping" class
into each pattern that helped with handling this 1:N correspondance.
However, this was still rather manual and, in particular, it required
the use of magic constants for the indices of the different operands.

This commits uses the generated GenericAdaptor class that is generated
for each op class in order to simplify this relationship further. The
GenericAdaptor allows to wrap around a list of arbitrary types for each
operand (via templating); for 1:N type conversion, this allows the
operand accessors of the adaptor class to return a ValueRange that
corresponds to the N values in the converted types. Patterns can thus
use the named accessors instead of magic constants, which eliminates a
common class of errors.

This commit further simplifies the API that patterns need to implement
by making the operand and result type mappings part of the adaptor.
Since many patterns only need one of the two (or even neither), this
reduces the number of unnecessary arguments in many cases.

Diff Detail

Event Timeline

ingomueller-net requested review of this revision.Mar 30 2023, 5:51 AM
springerm accepted this revision.Mar 31 2023, 2:53 AM

Nice cleanup!

This revision is now accepted and ready to land.Mar 31 2023, 2:53 AM