[mlir][MemRef][Transform] Don't apply multibuffer on "useless" allocs
authorQuentin Colombet <quentin.colombet@gmail.com>
Fri, 10 Feb 2023 16:21:38 +0000 (17:21 +0100)
committerQuentin Colombet <quentin.colombet@gmail.com>
Mon, 13 Feb 2023 13:19:10 +0000 (14:19 +0100)
commitb838b62876179a5fac8edeccbd0d9a225a3fa922
tree8088d58e43d803c3eae3033f883da4bc3fd38b64
parent5d3c58829d28b53abb2aac7e59b345f6cdf2d853
[mlir][MemRef][Transform] Don't apply multibuffer on "useless" allocs

`alloc`s that have users outside of loops are guaranteed to fail in
`multibuffer`.

Instead of exposing ourselves to that failure in the transform dialect,
filter out the `alloc`s that fall in this category.

To be able to do this filtering we have to change the `multibuffer`
transform op from `TransformEachOpTrait` to a plain `TransformOp`. This is
because `TransformEachOpTrait` expects that every successful `applyToOne`
returns a non-empty result.

Couple of notes:
- I changed the assembly syntax to make sure we only get `alloc` ops as
  input. (And added a test case to make sure we reject invalid inputs.)
- `multibuffer` can still fail pretty easily when you know its limitations.
  See the updated `op failed to multibuffer` test case for instance.
  Longer term, instead of leaking/coupling the actual implementation (in
  this case the checks normally done in `memref::multiBuffer`) with the
  transform dialect (the added check in `::apply`), we may want to refactor
  how we structure the underlying implementation. E.g., we could imagine a
  `canApply` method for all the implementations that we want to hook up in
  the transform dialect.
  This has some implications on how not to duplicate work between
  `canApply` and the actual implementation but I thought I throw that here
  to have us think about it :).

Differential Revision: https://reviews.llvm.org/D143747
mlir/include/mlir/Dialect/MemRef/TransformOps/MemRefTransformOps.td
mlir/lib/Dialect/MemRef/TransformOps/CMakeLists.txt
mlir/lib/Dialect/MemRef/TransformOps/MemRefTransformOps.cpp
mlir/test/Dialect/MemRef/transform-ops.mlir
utils/bazel/llvm-project-overlay/mlir/BUILD.bazel