[mlir] scf::ForOp: provide builders with callbacks for loop body
authorAlex Zinenko <zinenko@google.com>
Tue, 19 May 2020 14:22:00 +0000 (16:22 +0200)
committerAlex Zinenko <zinenko@google.com>
Tue, 19 May 2020 14:26:29 +0000 (16:26 +0200)
commitd1560f3956f6396a2b10c721b96b4c7394019cc2
tree82df201b4fe3e9b5b4d317bf2b9f49d38a2bb109
parent1aadd6ce6128a953066ab975fa6ae080df5ffc3b
[mlir] scf::ForOp: provide builders with callbacks for loop body

Thanks to a recent change that made `::build` functions take an instance of
`OpBuilder`, it is now possible to build operations within a region attached to
the operation about to be created. Exercise this on `scf::ForOp` by taking a
callback that populates the loop body while the loop is being created.

Additionally, provide helper functions to build perfect nests of `ForOp`s,
with support for iteration arguments. These functions provide the same
functionality as EDSC LoopNestBuilder with simpler implementation, without
relying on edsc::ScopedContext, and using `OpBuilder` in an unambiguous way.
Compatibility functions for EDSC are provided, but may be removed in the
future.

Differential Revision: https://reviews.llvm.org/D79688
mlir/include/mlir/Dialect/SCF/EDSC/Builders.h
mlir/include/mlir/Dialect/SCF/SCF.h
mlir/include/mlir/Dialect/SCF/SCFOps.td
mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
mlir/lib/Dialect/GPU/Transforms/MemoryPromotion.cpp
mlir/lib/Dialect/SCF/EDSC/Builders.cpp
mlir/lib/Dialect/SCF/SCF.cpp
mlir/test/EDSC/builder-api-test.cpp