[PATCH] D76603: [MLIR] Insert loop.yield to IfOp regions only if it's void.
Alexander Belyaev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 23 15:49:13 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG564ece93b836: [MLIR] Insert loop.yield to IfOp regions only if it's void. (authored by pifon2a).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D76603/new/
https://reviews.llvm.org/D76603
Files:
mlir/include/mlir/Dialect/LoopOps/LoopOps.td
mlir/lib/Dialect/LoopOps/LoopOps.cpp
Index: mlir/lib/Dialect/LoopOps/LoopOps.cpp
===================================================================
--- mlir/lib/Dialect/LoopOps/LoopOps.cpp
+++ mlir/lib/Dialect/LoopOps/LoopOps.cpp
@@ -201,18 +201,25 @@
void IfOp::build(Builder *builder, OperationState &result, Value cond,
bool withElseRegion) {
- build(builder, result, /*resultTypes=*/llvm::None, cond, withElseRegion);
+ build(builder, result, /*resultTypes=*/llvm::None, cond, withElseRegion);
}
void IfOp::build(Builder *builder, OperationState &result,
TypeRange resultTypes, Value cond, bool withElseRegion) {
result.addOperands(cond);
result.addTypes(resultTypes);
+
Region *thenRegion = result.addRegion();
+ thenRegion->push_back(new Block());
+ if (resultTypes.empty())
+ IfOp::ensureTerminator(*thenRegion, *builder, result.location);
+
Region *elseRegion = result.addRegion();
- IfOp::ensureTerminator(*thenRegion, *builder, result.location);
- if (withElseRegion)
- IfOp::ensureTerminator(*elseRegion, *builder, result.location);
+ if (withElseRegion) {
+ elseRegion->push_back(new Block());
+ if (resultTypes.empty())
+ IfOp::ensureTerminator(*elseRegion, *builder, result.location);
+ }
}
static LogicalResult verify(IfOp op) {
Index: mlir/include/mlir/Dialect/LoopOps/LoopOps.td
===================================================================
--- mlir/include/mlir/Dialect/LoopOps/LoopOps.td
+++ mlir/include/mlir/Dialect/LoopOps/LoopOps.td
@@ -223,20 +223,21 @@
OpBuilder<"Builder *builder, OperationState &result, "
"Value cond, bool withElseRegion">,
OpBuilder<"Builder *builder, OperationState &result, "
- "TypeRange resultTypes, Value cond, "
- "bool withElseRegion">
+ "TypeRange resultTypes, Value cond, bool withElseRegion">
];
let extraClassDeclaration = [{
OpBuilder getThenBodyBuilder() {
assert(!thenRegion().empty() && "Unexpected empty 'then' region.");
Block &body = thenRegion().front();
- return OpBuilder(&body, std::prev(body.end()));
+ return OpBuilder(&body,
+ results().empty() ? std::prev(body.end()) : body.end());
}
OpBuilder getElseBodyBuilder() {
assert(!elseRegion().empty() && "Unexpected empty 'else' region.");
Block &body = elseRegion().front();
- return OpBuilder(&body, std::prev(body.end()));
+ return OpBuilder(&body,
+ results().empty() ? std::prev(body.end()) : body.end());
}
}];
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76603.252165.patch
Type: text/x-patch
Size: 2581 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200323/83649c3f/attachment.bin>
More information about the llvm-commits
mailing list