[mlir] Implement pass utils for 1:N type conversions.
authorIngo Müller <ingomueller@google.com>
Tue, 21 Feb 2023 11:21:25 +0000 (11:21 +0000)
committerIngo Müller <ingomueller@google.com>
Mon, 27 Mar 2023 09:02:28 +0000 (09:02 +0000)
commit9c4611f9c7a7055b18f0a30a4c9074b9917e4ab0
treed521533a886412e994dddf530701ff07d3ab6df5
parent1c4fedfa35aeb8b456e2d8f4f826c0e026b9d863
[mlir] Implement pass utils for 1:N type conversions.

The current dialect conversion does not support 1:N type conversions.
This commit implements a (poor-man's) dialect conversion pass that does
just that. To keep the pass independent of the "real" dialect conversion
infrastructure, it provides a specialization of the TypeConverter class
that allows for N:1 target materializations, a specialization of the
RewritePattern and PatternRewriter classes that automatically add
appropriate unrealized casts supporting 1:N type conversions and provide
converted operands for implementing subclasses, and a conversion driver
that applies the provided patterns and replaces the unrealized casts
that haven't folded away with user-provided materializations.

The current pass is powerful enough to express many existing manual
solutions for 1:N type conversions or extend transforms that previously
didn't support them, out of which this patch implements call graph type
decomposition (which is currently implemented with a ValueDecomposer
that is only used there).

The goal of this pass is to illustrate the effect that 1:N type
conversions could have, gain experience in how patterns should be
written that achieve that effect, and get feedback on how the APIs of
the dialect conversion should be extended or changed to support such
patterns. The hope is that the "real" dialect conversion eventually
supports such patterns, at which point, this pass could be removed
again.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D144469
12 files changed:
mlir/include/mlir/Dialect/Func/Transforms/OneToNFuncConversions.h [new file with mode: 0644]
mlir/include/mlir/Transforms/OneToNTypeConversion.h [new file with mode: 0644]
mlir/lib/Dialect/Func/Transforms/CMakeLists.txt
mlir/lib/Dialect/Func/Transforms/OneToNFuncConversions.cpp [new file with mode: 0644]
mlir/lib/Transforms/Utils/CMakeLists.txt
mlir/lib/Transforms/Utils/OneToNTypeConversion.cpp [new file with mode: 0644]
mlir/test/Transforms/decompose-call-graph-types.mlir
mlir/test/lib/Conversion/CMakeLists.txt
mlir/test/lib/Conversion/OneToNTypeConversion/CMakeLists.txt [new file with mode: 0644]
mlir/test/lib/Conversion/OneToNTypeConversion/TestOneToNTypeConversionPass.cpp [new file with mode: 0644]
mlir/tools/mlir-opt/CMakeLists.txt
mlir/tools/mlir-opt/mlir-opt.cpp