Skip to content

[CIR] Add back verification of LoopOpInterface #1641

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 5 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 4 additions & 5 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -872,11 +872,10 @@ def SelectOp : CIR_Op<"select", [Pure,
// ConditionOp
//===----------------------------------------------------------------------===//

def ConditionOp : CIR_Op<"condition", [
Terminator,
DeclareOpInterfaceMethods<RegionBranchTerminatorOpInterface,
["getSuccessorRegions"]>
]> {
def ConditionOp : CIR_Op<"condition", [Terminator, ConditionOpInterface,
DeclareOpInterfaceMethods<
RegionBranchTerminatorOpInterface,
["getSuccessorRegions"]>]> {
let summary = "Loop continuation condition.";
let description = [{
The `cir.condition` terminates conditional regions. It takes a single
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/CIR/Interfaces/CIRLoopOpInterface.td
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,11 @@ def LoopOpInterface : OpInterface<"LoopOpInterface", [
}];
}

def ConditionOpInterface : OpInterface<"ConditionOpInterface", []> {
let description = [{
A singleton interface for ConditionOp only. This is used to break off a
a dependency from LoopOpInterface onto ConditionOp.
}];
let cppNamespace = "::cir";
}
#endif // CLANG_CIR_INTERFACES_CIRLOOPOPINTERFACE
9 changes: 4 additions & 5 deletions clang/lib/CIR/Interfaces/CIRLoopOpInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ void LoopOpInterface::getLoopOpSuccessorRegions(

/// Verify invariants of the LoopOpInterface.
llvm::LogicalResult detail::verifyLoopOpInterface(mlir::Operation *op) {
// FIXME: fix this so the conditionop isn't requiring MLIRCIR
// auto loopOp = mlir::cast<LoopOpInterface>(op);
// if (!mlir::isa<ConditionOp>(loopOp.getCond().back().getTerminator()))
// return op->emitOpError(
// "expected condition region to terminate with 'cir.condition'");
auto loopOp = mlir::cast<LoopOpInterface>(op);
if (!mlir::isa<ConditionOpInterface>(loopOp.getCond().back().getTerminator()))
return op->emitOpError(
"expected condition region to terminate with 'cir.condition'");
return llvm::success();
}

Expand Down
41 changes: 41 additions & 0 deletions clang/test/CIR/IR/invalid.cir
Original file line number Diff line number Diff line change
Expand Up @@ -1533,3 +1533,44 @@ cir.global external dsolocal @vfp = #cir.ptr<null> : !cir.ptr<!cir.func<(!s32i)

// expected-error @below {{integer or floating point type}}
!complex = !cir.complex<!cir.ptr<!cir.void>>

// -----

#false = #cir.bool<false> : !cir.bool
#true = #cir.bool<true> : !cir.bool
cir.func @b0() {
cir.scope {
cir.while { // expected-error {{expected condition region to terminate with 'cir.condition'}}
cir.yield
} do {
cir.br ^bb1
^bb1:
cir.return
}
}
cir.return
}

// -----

cir.func @invalid_cond_region_terminator(%arg0 : !cir.bool) -> !cir.void {
cir.do { // expected-error {{op expected condition region to terminate with 'cir.condition'}}
cir.yield
} while {
cir.yield
}
cir.return
}

// -----

cir.func @invalidConditionTerminator (%arg0 : !cir.bool) -> !cir.void {
cir.for : cond { // expected-error {{op expected condition region to terminate with 'cir.condition'}}
cir.yield
} body {
cir.yield
} step {
cir.yield
}
cir.return
}
42 changes: 0 additions & 42 deletions clang/test/CIR/IR/invalid_xfail.cir

This file was deleted.

Loading