[Mlir-commits] [mlir] [mlir][emitc] Add a structured for operation (PR #68206)

Simon Camphausen llvmlistbot at llvm.org
Mon Oct 23 06:57:43 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 if (bodyBuilder) {
----------------
simon-camp wrote:

```suggestion
  } else {
```

https://github.com/llvm/llvm-project/pull/68206


More information about the Mlir-commits mailing list