[MLIR] Introduce scf.execute_region op
authorUday Bondhugula <uday@polymagelabs.com>
Fri, 18 Jun 2021 05:31:46 +0000 (11:01 +0530)
committerUday Bondhugula <uday@polymagelabs.com>
Fri, 18 Jun 2021 09:52:33 +0000 (15:22 +0530)
commit18c8c934d8584f706dfca9e633f0f89cefe3688e
tree41386b7e5852339fc6ff8481d791348a7198ce7d
parent3f5d53a525c62c507a482fd5f4c08451835b342d
[MLIR] Introduce scf.execute_region op

Introduce the execute_region op that is able to hold a region which it
executes exactly once. The op encapsulates a CFG within itself while
isolating it from the surrounding control flow. Proposal discussed here:
https://llvm.discourse.group/t/introduce-std-inlined-call-op-proposal/282

execute_region enables one to inline a function without lowering out all
other higher level control flow constructs (affine.for/if, scf.for/if)
to the flat list of blocks / CFG form. It thus allows the benefit of
transforms on higher level control flow ops available in the presence of
the inlined calls. The inlined calls continue to benefit from
propagation of SSA values across their top boundary. Functions won’t
have to remain outlined until later than desired.  Abstractions like
affine execute_regions, lambdas with implicit captures could be lowered
to this without first lowering out structured loops/ifs or outlining.
But two potential early use cases are of: (1) an early inliner (which
can inline functions by introducing execute_region ops), (2) lowering of
an affine.execute_region, which cleanly maps to an scf.execute_region
when going from the affine dialect to the scf dialect.

Differential Revision: https://reviews.llvm.org/D75837
mlir/include/mlir/Dialect/SCF/SCFOps.td
mlir/lib/Dialect/SCF/SCF.cpp
mlir/test/Dialect/SCF/canonicalize.mlir
mlir/test/Dialect/SCF/invalid.mlir
mlir/test/Dialect/SCF/ops.mlir
mlir/utils/vim/syntax/mlir.vim