diff options
| author | Alex Zinenko <zinenko@google.com> | 2019-02-25 09:16:30 -0800 |
|---|---|---|
| committer | jpienaar <jpienaar@google.com> | 2019-03-29 16:40:50 -0700 |
| commit | 83e8db2193bbbd5e7aacc6e2f318f648bbd93da4 (patch) | |
| tree | 97aeade9c4564189c9ec1991405825e232b57552 /mlir/include/mlir-c | |
| parent | 8b99d1bdbfebb48ff5b052216100b52c4cdf842d (diff) | |
| download | bcm5719-llvm-83e8db2193bbbd5e7aacc6e2f318f648bbd93da4.tar.gz bcm5719-llvm-83e8db2193bbbd5e7aacc6e2f318f648bbd93da4.zip | |
EDSC: support branch instructions
The new implementation of blocks was designed to support blocks with arguments.
More specifically, StmtBlock can be constructed with a list of Bindables that
will be bound to block aguments upon construction. Leverage this functionality
to implement branch instructions with arguments.
This additionally requires the statement storage to have a list of successors,
similarly to core IR operations.
Becauase successor chains can form loops, we need a possibility to decouple
block declaration, after which it becomes usable by branch instructions, from
block body definition. This is achieved by creating an empty block and by
resetting its body with a new list of instructions. Note that assigning a
block from another block will not affect any instructions that may have
designated this block as their successor (this behavior is necessary to make
value-type semantics of EDSC types consistent). Combined, one can now write
generators like
EDSCContext context;
Type indexType = ...;
Bindable i(indexType), ii(indexType), zero(indexType), one(indexType);
StmtBlock loopBlock({i}, {});
loopBlock.set({ii = i + one,
Branch(loopBlock, {ii})});
MLIREmitter(&builder)
.bindConstant<ConstantIndexOp>(zero, 0)
.bindConstant<ConstantIndexOp>(one, 1)
.emitStmt(Branch(loopBlock, {zero}));
where the emitter will emit the statement and its successors, if present.
PiperOrigin-RevId: 235541892
Diffstat (limited to 'mlir/include/mlir-c')
| -rw-r--r-- | mlir/include/mlir-c/Core.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/mlir/include/mlir-c/Core.h b/mlir/include/mlir-c/Core.h index 09dc5c850e2..44ab5cb61be 100644 --- a/mlir/include/mlir-c/Core.h +++ b/mlir/include/mlir-c/Core.h @@ -230,8 +230,15 @@ edsc_expr_t ConstantInteger(mlir_type_t type, int64_t value); edsc_stmt_t Return(edsc_expr_list_t values); /// Returns an opaque expression for an mlir::edsc::StmtBlock containing the -/// given list of statements. Block arguments are not currently supported. -edsc_block_t Block(edsc_stmt_list_t enclosedStmts); +/// given list of statements. +edsc_block_t Block(edsc_expr_list_t arguments, edsc_stmt_list_t enclosedStmts); + +/// Set the body of the block to the given statements and return the block. +edsc_block_t BlockSetBody(edsc_block_t, edsc_stmt_list_t stmts); + +/// Returns an opaque statement branching to `destination` and passing +/// `arguments` as block arguments. +edsc_stmt_t Branch(edsc_block_t destination, edsc_expr_list_t arguments); /// Returns an opaque statement for an mlir::AffineForOp with `enclosedStmts` /// nested below it. |

