diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp --- a/flang/lib/Lower/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP.cpp @@ -151,7 +151,7 @@ sectionOp->getLoc(), firOpBuilder.createIntegerConstant( sectionOp->getLoc(), firOpBuilder.getIntegerType(1), 0x1), - /*else*/ false); + mlir::scf::buildTerminatedBody); firOpBuilder.setInsertionPointToStart(&ifOp.getThenRegion().front()); const Fortran::parser::OpenMPConstruct *parentOmpConstruct = @@ -225,7 +225,7 @@ wsLoopOp->getUpperBound()[0]); } mlir::scf::IfOp ifOp = firOpBuilder.create( - wsLoopOp->getLoc(), cmpOp, /*else*/ false); + wsLoopOp->getLoc(), cmpOp, mlir::scf::buildTerminatedBody); firOpBuilder.setInsertionPointToStart(&ifOp.getThenRegion().front()); lastPrivIP = firOpBuilder.saveInsertionPoint(); } else { diff --git a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td --- a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td +++ b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td @@ -775,7 +775,6 @@ 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)>, OpBuilder<(ins "Value":$cond, diff --git a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp --- a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp +++ b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp @@ -526,7 +526,7 @@ arith::CmpIOp pred = rewriter.create( loc, arith::CmpIPredicate::slt, newIndex, cloningMap.lookupOrDefault(originalBound)); - scf::IfOp ifOp = rewriter.create(loc, pred, false); + scf::IfOp ifOp = rewriter.create(loc, pred); rewriter.setInsertionPointToStart(&ifOp.getThenRegion().front()); // Put a sentinel into the worklist so we know when to pop out of the // if body again. We use the launchOp here, as that cannot be part of diff --git a/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp b/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp --- a/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp +++ b/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp @@ -469,8 +469,7 @@ Block::iterator insertionPoint; if (predicate) { // Step 5.a. If predicated, move at the beginning. - auto ifOp = - rewriter.create(loc, predicate, /*withElseRegion=*/false); + auto ifOp = rewriter.create(loc, predicate); targetBlock = ifOp.thenBlock(); insertionPoint = ifOp.thenBlock()->begin(); } else { diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp --- a/mlir/lib/Dialect/SCF/IR/SCF.cpp +++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp @@ -1615,11 +1615,6 @@ builder.createBlock(elseRegion); } -void IfOp::build(OpBuilder &builder, OperationState &result, Value cond, - bool withElseRegion) { - build(builder, result, TypeRange{}, cond, withElseRegion); -} - void IfOp::build(OpBuilder &builder, OperationState &result, TypeRange resultTypes, Value cond, bool withElseRegion) { result.addTypes(resultTypes); diff --git a/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp b/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp --- a/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp +++ b/mlir/lib/Dialect/SCF/Transforms/LoopSpecialization.cpp @@ -69,7 +69,8 @@ cond = cond ? b.create(op.getLoc(), cond, cmp) : cmp; map.map(std::get<0>(bound), constant); } - auto ifOp = b.create(op.getLoc(), cond, /*withElseRegion=*/true); + auto ifOp = b.create(op.getLoc(), cond, scf::buildTerminatedBody, + scf::buildTerminatedBody); ifOp.getThenBodyBuilder().clone(*op.getOperation(), map); ifOp.getElseBodyBuilder().clone(*op.getOperation()); op.erase(); @@ -98,7 +99,8 @@ Value cond = b.create(op.getLoc(), arith::CmpIPredicate::eq, bound, constant); map.map(bound, constant); - auto ifOp = b.create(op.getLoc(), cond, /*withElseRegion=*/true); + auto ifOp = b.create(op.getLoc(), cond, scf::buildTerminatedBody, + scf::buildTerminatedBody); ifOp.getThenBodyBuilder().clone(*op.getOperation(), map); ifOp.getElseBodyBuilder().clone(*op.getOperation()); op.erase(); diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp --- a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.cpp @@ -463,7 +463,7 @@ Value tensor, ValueRange ivs) { Value val = builder.create(loc, tensor, ivs); Value cond = genIsNonzero(builder, loc, val); - scf::IfOp ifOp = builder.create(loc, cond, /*else*/ false); + scf::IfOp ifOp = builder.create(loc, cond); builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); return val; } diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseBufferRewriting.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseBufferRewriting.cpp --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseBufferRewriting.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseBufferRewriting.cpp @@ -742,7 +742,8 @@ Value c2 = constantIndex(builder, loc, 2); Value condN = builder.create(loc, arith::CmpIPredicate::uge, n, c2); - scf::IfOp ifN = builder.create(loc, condN, /*else=*/false); + scf::IfOp ifN = + builder.create(loc, TypeRange{}, condN, /*else=*/false); builder.setInsertionPointToStart(&ifN.getThenRegion().front()); Value child = builder.create(loc, start, first); @@ -750,7 +751,8 @@ Value t = createSubTwoDividedByTwo(builder, loc, n); Value condNc = builder.create(loc, arith::CmpIPredicate::uge, t, child); - scf::IfOp ifNc = builder.create(loc, condNc, /*else=*/false); + scf::IfOp ifNc = + builder.create(loc, TypeRange{}, condNc, /*else=*/false); builder.setInsertionPointToStart(&ifNc.getThenRegion().front()); Value c1 = constantIndex(builder, loc, 1); @@ -925,6 +927,12 @@ Location loc = func.getLoc(); Value lo = args[loIdx]; Value hi = args[hiIdx]; + Value cond = + builder.create(loc, arith::CmpIPredicate::ult, lo, hi); + scf::IfOp ifOp = builder.create(loc, cond); + + // The if-stmt true branch. + builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); FlatSymbolRefAttr partitionFunc = getMangledSortHelperFunc( builder, func, {IndexType::get(context)}, kPartitionFuncNamePrefix, nx, ny, isCoo, args.drop_back(nTrailingP), createPartitionFunc); @@ -1080,7 +1088,8 @@ builder.create(loc, lo, constantIndex(builder, loc, 1)); Value cond = builder.create(loc, arith::CmpIPredicate::ult, loCmp, hi); - scf::IfOp ifOp = builder.create(loc, cond, /*else=*/false); + scf::IfOp ifOp = + builder.create(loc, TypeRange{}, cond, /*else=*/false); // The if-stmt true branch. builder.setInsertionPointToStart(&ifOp.getThenRegion().front()); @@ -1093,7 +1102,8 @@ Value lenLimit = constantIndex(builder, loc, 30); Value lenCond = builder.create( loc, arith::CmpIPredicate::ule, len, lenLimit); - scf::IfOp lenIf = builder.create(loc, lenCond, /*else=*/true); + scf::IfOp lenIf = + builder.create(loc, TypeRange{}, lenCond, /*else=*/true); // When len <= limit. builder.setInsertionPointToStart(&lenIf.getThenRegion().front()); @@ -1113,7 +1123,8 @@ Value depthCond = builder.create(loc, arith::CmpIPredicate::ule, depthLimit, constantI64(builder, loc, 0)); - depthIf = builder.create(loc, depthCond, /*else=*/true); + depthIf = + builder.create(loc, TypeRange{}, depthCond, /*else=*/true); // When depth exceeds limit. builder.setInsertionPointToStart(&depthIf.getThenRegion().front()); diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp @@ -594,7 +594,7 @@ if (hasDenseDim) { Value elemV = rewriter.create(loc, elemPtr); Value isZero = genIsNonzero(rewriter, loc, elemV); - scf::IfOp ifOp = rewriter.create(loc, isZero, /*else*/ false); + scf::IfOp ifOp = rewriter.create(loc, isZero); rewriter.setInsertionPointToStart(&ifOp.getThenRegion().front()); } // Callback here to build loop body. diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorDistribute.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorDistribute.cpp --- a/mlir/lib/Dialect/Vector/Transforms/VectorDistribute.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/VectorDistribute.cpp @@ -308,8 +308,7 @@ Value c0 = rewriter.create(loc, 0); Value isLane0 = rewriter.create( loc, arith::CmpIPredicate::eq, warpOp.getLaneid(), c0); - auto ifOp = rewriter.create(loc, isLane0, - /*withElseRegion=*/false); + auto ifOp = rewriter.create(loc, isLane0); rewriter.eraseOp(ifOp.thenBlock()->getTerminator()); // Step 2: insert appropriate (alloc, write)-pairs before the scf.if and