Skip to content

[mlir][scf] Remove redundant ensureTerminator for scf.forall #133081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,6 @@ def ForallOp : SCF_Op<"forall", [
/// Checks if the lbs are zeros and steps are ones.
bool isNormalized();

// The ensureTerminator method generated by SingleBlockImplicitTerminator is
// unaware of the fact that our terminator also needs a region to be
// well-formed. We override it here to ensure that we do the right thing.
static void ensureTerminator(Region & region, OpBuilder & builder,
Location loc);

InParallelOp getTerminator();

// Declare the shared_outs as inits/outs to DestinationStyleOpInterface.
Expand Down
13 changes: 0 additions & 13 deletions mlir/lib/Dialect/SCF/IR/SCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1416,19 +1416,6 @@ bool ForallOp::isNormalized() {
return allEqual(getMixedLowerBound(), 0) && allEqual(getMixedStep(), 1);
}

// The ensureTerminator method generated by SingleBlockImplicitTerminator is
// unaware of the fact that our terminator also needs a region to be
// well-formed. We override it here to ensure that we do the right thing.
void ForallOp::ensureTerminator(Region &region, OpBuilder &builder,
Location loc) {
OpTrait::SingleBlockImplicitTerminator<InParallelOp>::Impl<
ForallOp>::ensureTerminator(region, builder, loc);
auto terminator =
llvm::dyn_cast<InParallelOp>(region.front().getTerminator());
if (terminator.getRegion().empty())
builder.createBlock(&terminator.getRegion());
}

InParallelOp ForallOp::getTerminator() {
return cast<InParallelOp>(getBody()->getTerminator());
}
Expand Down
12 changes: 12 additions & 0 deletions mlir/test/Dialect/SCF/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,18 @@ func.func @mismatched_mapping(%x: memref<2 x 32 x f32>, %y: memref<2 x 32 x f32>

// -----

func.func @forall_wrong_terminator_op() -> () {
%c100 = arith.constant 100 : index
// expected-error @+2 {{'scf.forall' op expects regions to end with 'scf.forall.in_parallel', found 'llvm.return'}}
// expected-note @below {{in custom textual format, the absence of terminator implies 'scf.forall.in_parallel'}}
scf.forall (%arg0) in (%c100) {
llvm.return
}
return
}

// -----

func.func @switch_wrong_case_count(%arg0: index) {
// expected-error @below {{'scf.index_switch' op has 0 case regions but 1 case values}}
"scf.index_switch"(%arg0) ({
Expand Down