[MLIR] Add an IfOp builder with results

Summary:
Add an additional builder to IfOp to allow the operation to
define operands.

Differential Revision: https://reviews.llvm.org/D76524
This commit is contained in:
nmostafa 2020-03-20 13:20:45 -07:00
parent 4f5af9d70d
commit 141e5890d8
2 changed files with 10 additions and 1 deletions

View File

@ -221,7 +221,10 @@ def IfOp : Loop_Op<"if",
let skipDefaultBuilders = 1;
let builders = [
OpBuilder<"Builder *builder, OperationState &result, "
"Value cond, bool withElseRegion">
"Value cond, bool withElseRegion">,
OpBuilder<"Builder *builder, OperationState &result, "
"TypeRange resultTypes, Value cond, "
"bool withElseRegion">
];
let extraClassDeclaration = [{

View File

@ -201,7 +201,13 @@ ForOp mlir::loop::getForInductionVarOwner(Value val) {
void IfOp::build(Builder *builder, OperationState &result, Value cond,
bool 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();
Region *elseRegion = result.addRegion();
IfOp::ensureTerminator(*thenRegion, *builder, result.location);