[mlir] Add a new fold API using Generic Adaptors
authorMarkus Böck <markus.boeck02@gmail.com>
Sun, 25 Dec 2022 18:29:31 +0000 (19:29 +0100)
committerMarkus Böck <markus.boeck02@gmail.com>
Wed, 11 Jan 2023 13:32:21 +0000 (14:32 +0100)
commitbbfa7ef16dd9900b36abfa1a5f2faddb81afeb51
tree3639e00eaaabccfb705bfa6bccdd9aaf7dc47c5d
parentcf6f21751622fcae326d1fe13bc5afd74c4e720f
[mlir] Add a new fold API using Generic Adaptors

This is part of the RFC for a better fold API: https://discourse.llvm.org/t/rfc-a-better-fold-api-using-more-generic-adaptors/67374

This patch implements the required foldHook changes and the TableGen machinery for generating `fold` method signatures using `FoldAdaptor` for ops, based on the value of `useFoldAPI` of the dialect. It may be one of 2 values, with convenient named constants to create a quasi enum. The new `fold` method will then be generated if `kEmitFoldAdaptorFolder` is used.

Since the new `FoldAdaptor` approach is strictly better than the old signature, part of this patch updates the documentation and all example to encourage use of the new `fold` signature.
Included are also tests exercising the new API, ensuring proper construction of the `FoldAdaptor` and proper generation by TableGen.

Differential Revision: https://reviews.llvm.org/D140886
17 files changed:
mlir/docs/Canonicalization.md
mlir/docs/DefiningDialects/_index.md
mlir/docs/Tutorials/Toy/Ch-7.md
mlir/examples/toy/Ch7/include/toy/Ops.td
mlir/examples/toy/Ch7/mlir/ToyCombine.cpp
mlir/include/mlir/IR/DialectBase.td
mlir/include/mlir/IR/OpDefinition.h
mlir/include/mlir/TableGen/Dialect.h
mlir/include/mlir/TableGen/Operator.h
mlir/lib/TableGen/Dialect.cpp
mlir/lib/TableGen/Operator.cpp
mlir/test/IR/test-fold-adaptor.mlir [new file with mode: 0644]
mlir/test/lib/Dialect/Test/TestDialect.cpp
mlir/test/lib/Dialect/Test/TestOps.td
mlir/test/mlir-tblgen/has-fold-invalid-values.td [new file with mode: 0644]
mlir/test/mlir-tblgen/op-decl-and-defs.td
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp