[clang] [CIR] Upstream support for while and do..while loops (PR #133157)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 26 16:58:19 PDT 2025
================
@@ -759,6 +761,84 @@ def BrCondOp : CIR_Op<"brcond",
}];
}
+//===----------------------------------------------------------------------===//
+// While & DoWhileOp
+//===----------------------------------------------------------------------===//
+
+class WhileOpBase<string mnemonic> : CIR_Op<mnemonic, [
+ LoopOpInterface,
+ NoRegionArguments,
+]> {
+ defvar isWhile = !eq(mnemonic, "while");
+ let summary = "C/C++ " # !if(isWhile, "while", "do-while") # " loop";
+ let builders = [
+ OpBuilder<(ins "llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)>":$condBuilder,
----------------
andykaylor wrote:
Yeah, we haven't been fitting the .td files in 80 columns, though I have also thought we probably should do so.
It looks like tablegen will accept it like this:
```
let builders = [
OpBuilder<(ins "llvm::function_ref<void(mlir::OpBuilder &, "
"mlir::Location)>":$condBuilder,
"llvm::function_ref<void(mlir::OpBuilder &, "
"mlir::Location)>":$bodyBuilder), [{
mlir::OpBuilder::InsertionGuard guard($_builder);
$_builder.createBlock($_state.addRegion());
}] # !if(isWhile, [{
condBuilder($_builder, $_state.location);
$_builder.createBlock($_state.addRegion());
bodyBuilder($_builder, $_state.location);
}], [{
bodyBuilder($_builder, $_state.location);
$_builder.createBlock($_state.addRegion());
condBuilder($_builder, $_state.location);
}])>
];
```
What do you think? Is that readable?
https://github.com/llvm/llvm-project/pull/133157
More information about the cfe-commits
mailing list