[Mlir-commits] [mlir] [mlir][emitc] Add a structured for operation (PR #68206)
Marius Brehler
llvmlistbot at llvm.org
Wed Oct 25 03:44:05 PDT 2023
================
@@ -189,6 +190,114 @@ LogicalResult emitc::ConstantOp::verify() {
OpFoldResult emitc::ConstantOp::fold(FoldAdaptor adaptor) { return getValue(); }
+//===----------------------------------------------------------------------===//
+// ForOp
+//===----------------------------------------------------------------------===//
+
+void ForOp::build(OpBuilder &builder, OperationState &result, Value lb,
+ Value ub, Value step, BodyBuilderFn bodyBuilder) {
+ result.addOperands({lb, ub, step});
+ Type t = lb.getType();
+ Region *bodyRegion = result.addRegion();
+ bodyRegion->push_back(new Block);
+ Block &bodyBlock = bodyRegion->front();
+ bodyBlock.addArgument(t, result.location);
+
+ // Create the default terminator if the builder is not provided.
+ if (!bodyBuilder) {
+ ForOp::ensureTerminator(*bodyRegion, builder, result.location);
+ } else {
+ OpBuilder::InsertionGuard guard(builder);
+ builder.setInsertionPointToStart(&bodyBlock);
+ bodyBuilder(builder, result.location, bodyBlock.getArgument(0));
+ }
+}
+
+void ForOp::getCanonicalizationPatterns(RewritePatternSet &, MLIRContext *) {}
+
+ParseResult ForOp::parse(OpAsmParser &parser, OperationState &result) {
+ auto &builder = parser.getBuilder();
----------------
marbre wrote:
```suggestion
Builder &builder = parser.getBuilder();
```
I am aware that this is a take over from the SCF dialect, but I would suggest to keep it consistent with EmitC's `IfOp::parse`.
https://github.com/llvm/llvm-project/pull/68206
More information about the Mlir-commits
mailing list