Basic conversion of MLFunctions to CFGFunctions.
authorAlex Zinenko <zinenko@google.com>
Mon, 12 Nov 2018 22:58:36 +0000 (14:58 -0800)
committerjpienaar <jpienaar@google.com>
Fri, 29 Mar 2019 20:55:22 +0000 (13:55 -0700)
commit5a0d3d02046a03e64115ee4f1bf8a5c8fa50225b
tree605d9dc1dcce4e13d01576975827bda937c2dbdc
parent25e6b541cd53f2e27aed0eccdfad76ac11cb569c
Basic conversion of MLFunctions to CFGFunctions.

Implement a pass converting a subset of MLFunctions to CFGFunctions.  Currently
supports arbitrarily complex imperfect loop nests with statically constant
(i.e., not affine map) bounds filled with operations.  Does NOT support
branches and non-constant loop bounds.

Conversion is performed per-function and the function names are preserved to
avoid breaking any external references to the current module.  In-memory IR is
updated to point to the right functions in direct calls and constant loads.
This behavior is tested via a really hidden flag that enables function
renaming.

Inside each function, the control flow conversion is based on single-entry
single-exit regions, i.e. subgraphs of the CFG that have exactly one incoming
and exactly one outgoing edge.  Since an MLFunction must have a single "return"
statement as per MLIR spec, it constitutes an SESE region.  Individual
operations are appended to this region.  Control flow statements are
recursively converted into such regions that are concatenated with the current
region.  Bodies of the compound statement also form SESE regions, which allows
to nest control flow statements easily.  Note that SESE regions are not
materialized in the code.  It is sufficent to keep track of the end of the
region as the current instruction insertion point as long as all recursive
calls update the insertion point in the end.

The converter maintains a mapping between SSA values in ML functions and their
CFG counterparts.  The mapping is used to find the operands for each operation
and is updated to contain the results of each operation as the conversion
continues.

PiperOrigin-RevId: 221162602
mlir/include/mlir/IR/Builders.h
mlir/include/mlir/IR/OperationSupport.h
mlir/lib/Transforms/ConvertToCFG.cpp
mlir/test/Transforms/convert2cfg.mlir