[mlir] Use GenericAdaptor to simplify 1:N type conversion API.
authorIngo Müller <ingomueller@google.com>
Thu, 30 Mar 2023 12:40:46 +0000 (12:40 +0000)
committerIngo Müller <ingomueller@google.com>
Fri, 31 Mar 2023 10:43:09 +0000 (10:43 +0000)
commit4e563616a5fffa1204286a9aa03604a68a7db835
tree33b74c91ff7859c44f515156f0564869667d1e44
parent16e1f8e970aad4c92b31b330daf7274e89cca98d
[mlir] Use GenericAdaptor to simplify 1:N type conversion API.

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.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D147225
mlir/include/mlir/Transforms/OneToNTypeConversion.h
mlir/lib/Dialect/Func/Transforms/OneToNFuncConversions.cpp
mlir/lib/Dialect/SCF/Transforms/OneToNTypeConversion.cpp
mlir/test/lib/Conversion/OneToNTypeConversion/TestOneToNTypeConversionPass.cpp