[Mlir-commits] [mlir] e7b52c4 - [MLIR] Add primitive builders for scf.if
Frederik Gossen
llvmlistbot at llvm.org
Mon Feb 27 10:54:01 PST 2023
Author: Frederik Gossen
Date: 2023-02-27T13:53:39-05:00
New Revision: e7b52c46bf31858ad3754a853977ea7da431577e
URL: https://github.com/llvm/llvm-project/commit/e7b52c46bf31858ad3754a853977ea7da431577e
DIFF: https://github.com/llvm/llvm-project/commit/e7b52c46bf31858ad3754a853977ea7da431577e.diff
LOG: [MLIR] Add primitive builders for scf.if
Differential Revision: https://reviews.llvm.org/D144886
Added:
Modified:
mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
mlir/lib/Dialect/SCF/IR/SCF.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
index 0da8558681c45..e27e8a75f37d7 100644
--- a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
+++ b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
@@ -773,6 +773,8 @@ def IfOp : SCF_Op<"if", [DeclareOpInterfaceMethods<RegionBranchOpInterface, [
let skipDefaultBuilders = 1;
let builders = [
OpBuilder<(ins "TypeRange":$resultTypes, "Value":$cond)>,
+ OpBuilder<(ins "TypeRange":$resultTypes, "Value":$cond,
+ "bool":$addThenBlock, "bool":$addElseBlock)>,
OpBuilder<(ins "Value":$cond, "bool":$withElseRegion)>,
OpBuilder<(ins "TypeRange":$resultTypes, "Value":$cond,
"bool":$withElseRegion)>,
diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp
index 84caca9806e22..79c14f9b3288a 100644
--- a/mlir/lib/Dialect/SCF/IR/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp
@@ -1593,13 +1593,26 @@ IfOp::inferReturnTypes(MLIRContext *ctx, std::optional<Location> loc,
void IfOp::build(OpBuilder &builder, OperationState &result,
TypeRange resultTypes, Value cond) {
+ return build(builder, result, resultTypes, cond, /*addThenBlock=*/false,
+ /*addElseBlock=*/false);
+}
+
+void IfOp::build(OpBuilder &builder, OperationState &result,
+ TypeRange resultTypes, Value cond, bool addThenBlock,
+ bool addElseBlock) {
+ assert((!addElseBlock || addThenBlock) &&
+ "must not create else block w/o then block");
result.addTypes(resultTypes);
result.addOperands(cond);
- // Build regions.
+ // Add regions and blocks.
OpBuilder::InsertionGuard guard(builder);
- result.addRegion();
- result.addRegion();
+ Region *thenRegion = result.addRegion();
+ if (addThenBlock)
+ builder.createBlock(thenRegion);
+ Region *elseRegion = result.addRegion();
+ if (addElseBlock)
+ builder.createBlock(elseRegion);
}
void IfOp::build(OpBuilder &builder, OperationState &result, Value cond,
More information about the Mlir-commits
mailing list