[mlir] Avoid cloning ops in SCF parallel conversion to CFG
authorAlex Zinenko <zinenko@google.com>
Mon, 23 Nov 2020 12:22:51 +0000 (13:22 +0100)
committerAlex Zinenko <zinenko@google.com>
Mon, 23 Nov 2020 13:01:22 +0000 (14:01 +0100)
commit1ec60862d7024118b2db5bcbb280eafcd9193ac5
tree9be000853f0a7dddadbad99a5a7af4d4a7d38f5d
parentb31486ad971774c859e3e031fc0d8d9b77e3b083
[mlir] Avoid cloning ops in SCF parallel conversion to CFG

The existing implementation of the conversion from SCF Parallel operation to
SCF "for" loops in order to further convert those loops to branch-based CFG has
been cloning the loop and reduction body operations into the new loop because
ConversionPatternRewriter was missing support for moving blocks while replacing
their arguments. This functionality now available, use it to implement the
conversion and avoid cloning operations, which may lead to doubling of the IR
size during the conversion.

In addition, this fixes an issue with converting nested SCF "if" conditionals
present in "parallel" operations that would cause the conversion infrastructure
to stop because of the repeated application of the pattern converting "newly"
created "if"s (which were in fact just moved). Arguably, this should be fixed
at the infrastructure level and this fix is a workaround.

Reviewed By: herhut

Differential Revision: https://reviews.llvm.org/D91955
mlir/lib/Conversion/SCFToStandard/SCFToStandard.cpp
mlir/test/Conversion/SCFToStandard/convert-to-cfg.mlir