OSDN Git Service

[mlir] ensureRegionTerminator: take OpBuilder
authorAlex Zinenko <zinenko@google.com>
Wed, 20 May 2020 14:00:57 +0000 (16:00 +0200)
committerAlex Zinenko <zinenko@google.com>
Wed, 20 May 2020 14:14:46 +0000 (16:14 +0200)
commit3ccf4a5bd1099bfba544bec7ddbe610cc9531bb2
tree6d1f557a56049833b371cd790cbe3ce1d860bb61
parenta7d88a90386d6c4b456a68710ea48069b5d3a0bb
[mlir] ensureRegionTerminator: take OpBuilder

The SingleBlockImplicitTerminator op trait provides a function
`ensureRegionTerminator` that injects an appropriate terminator into the block
if necessary, which is used during operation constructing and parsing.
Currently, this function directly modifies the IR using low-level APIs on
Operation and Block. If this function is called from a conversion pattern,
these manipulations are not reflected in the ConversionPatternRewriter and thus
cannot be undone or, worse, lead to tricky memory errors and malformed IR.
Change `ensureRegionTerminator` to take an instance of `OpBuilder` instead of
`Builder`, and use it to construct the block and the terminator when required.
Maintain overloads taking an instance of `Builder` and creating a simple
`OpBuilder` to use in parsers, which don't have an `OpBuilder` and cannot
interact with the dialect conversion mechanism. This change was one of the
reasons to make `<OpTy>::build` accept an `OpBuilder`.

Differential Revision: https://reviews.llvm.org/D80138
mlir/include/mlir/IR/OpDefinition.h
mlir/lib/IR/Operation.cpp