@@ -442,7 +442,7 @@ def StoreOp : CIR_Op<"store", [
442442
443443def ReturnOp : CIR_Op<"return", [ParentOneOf<["FuncOp", "ScopeOp", "IfOp",
444444 "SwitchOp", "DoWhileOp",
445- "LoopOp"]>,
445+ "WhileOp", " LoopOp"]>,
446446 Terminator]> {
447447 let summary = "Return from function";
448448 let description = [{
@@ -635,7 +635,7 @@ def ConditionOp : CIR_Op<"condition", [
635635//===----------------------------------------------------------------------===//
636636
637637def YieldOp : CIR_Op<"yield", [ReturnLike, Terminator,
638- ParentOneOf<["IfOp", "ScopeOp", "SwitchOp", "LoopOp", "AwaitOp",
638+ ParentOneOf<["IfOp", "ScopeOp", "SwitchOp", "WhileOp", " LoopOp", "AwaitOp",
639639 "TernaryOp", "GlobalOp", "DoWhileOp"]>]> {
640640 let summary = "Represents the default branching behaviour of a region";
641641 let description = [{
@@ -1164,12 +1164,11 @@ def BrCondOp : CIR_Op<"brcond",
11641164//===----------------------------------------------------------------------===//
11651165
11661166def LoopOpKind_For : I32EnumAttrCase<"For", 1, "for">;
1167- def LoopOpKind_While : I32EnumAttrCase<"While", 2, "while">;
11681167
11691168def LoopOpKind : I32EnumAttr<
11701169 "LoopOpKind",
11711170 "Loop kind",
1172- [LoopOpKind_For, LoopOpKind_While ]> {
1171+ [LoopOpKind_For]> {
11731172 let cppNamespace = "::mlir::cir";
11741173}
11751174
@@ -1251,8 +1250,8 @@ def LoopOp : CIR_Op<"loop",
12511250 switch(getKind()) {
12521251 case LoopOpKind::For:
12531252 return llvm::SmallVector<Region *, 3>{&getCond(), &getBody(), &getStep()};
1254- case LoopOpKind::While:
1255- return llvm::SmallVector<Region *, 2>{&getCond(), &getBody()};
1253+ // case LoopOpKind::While:
1254+ // return llvm::SmallVector<Region *, 2>{&getCond(), &getBody()};
12561255 // case LoopOpKind::DoWhile:
12571256 // return llvm::SmallVector<Region *, 2>{&getBody(), &getCond()};
12581257 }
@@ -1261,7 +1260,7 @@ def LoopOp : CIR_Op<"loop",
12611260}
12621261
12631262//===----------------------------------------------------------------------===//
1264- // DoWhileOp
1263+ // While & DoWhileOp
12651264//===----------------------------------------------------------------------===//
12661265
12671266class WhileOpBase<string mnemonic> : CIR_Op<mnemonic, [
@@ -1287,6 +1286,31 @@ class WhileOpBase<string mnemonic> : CIR_Op<mnemonic, [
12871286 ];
12881287}
12891288
1289+ def WhileOp : WhileOpBase<"while"> {
1290+ let regions = (region SizedRegion<1>:$cond, MinSizedRegion<1>:$body);
1291+ let assemblyFormat = "$cond `do` $body attr-dict";
1292+
1293+ let description = [{
1294+ Represents a C/C++ while loop. It consists of two regions:
1295+
1296+ - `cond`: single block region with the loop's condition. Should be
1297+ terminated with a `cir.condition` operation.
1298+ - `body`: contains the loop body and an arbitrary number of blocks.
1299+
1300+ Example:
1301+
1302+ ```mlir
1303+ cir.while {
1304+ cir.break
1305+ ^bb2:
1306+ cir.yield
1307+ } do {
1308+ cir.condition %cond : cir.bool
1309+ }
1310+ ```
1311+ }];
1312+ }
1313+
12901314def DoWhileOp : WhileOpBase<"do"> {
12911315 let regions = (region MinSizedRegion<1>:$body, SizedRegion<1>:$cond);
12921316 let assemblyFormat = " $body `while` $cond attr-dict";
@@ -2660,7 +2684,7 @@ def AllocException : CIR_Op<"alloc_exception", [
26602684
26612685def ThrowOp : CIR_Op<"throw", [
26622686 ParentOneOf<["FuncOp", "ScopeOp", "IfOp", "SwitchOp",
2663- "DoWhileOp", "LoopOp"]>,
2687+ "DoWhileOp", "WhileOp", " LoopOp"]>,
26642688 Terminator]> {
26652689 let summary = "(Re)Throws an exception";
26662690 let description = [{
0 commit comments