[Mlir-commits] [mlir] [mlir][emitc] Add a structured for operation (PR #68206)
Simon Camphausen
llvmlistbot at llvm.org
Mon Oct 23 06:59:59 PDT 2023
================
@@ -37,6 +37,106 @@ struct SCFToEmitCPass : public impl::SCFToEmitCBase<SCFToEmitCPass> {
void runOnOperation() override;
};
+// Lower scf::for to emitc::for, implementing return values using
+// emitc::variable's updated within loop body.
+struct ForLowering : public OpRewritePattern<ForOp> {
+ using OpRewritePattern<ForOp>::OpRewritePattern;
+
+ LogicalResult matchAndRewrite(ForOp forOp,
+ PatternRewriter &rewriter) const override;
+};
+
+// Create an uninitialized emitc::variable op for each result of given op.
+template <typename T>
+static SmallVector<Value> createVariablesForResults(T op,
+ PatternRewriter &rewriter) {
+ SmallVector<Value> resultVariables;
+
+ if (!op.getNumResults())
+ return resultVariables;
+
+ Location loc = op->getLoc();
+ MLIRContext *context = op.getContext();
+
+ auto insertionPoint = rewriter.saveInsertionPoint();
----------------
simon-camp wrote:
```c++
OpBuilder::InsertionGuard guard(rewriter);
...
```
You can use a guard instead of save/restore pairs.
https://github.com/llvm/llvm-project/pull/68206
More information about the Mlir-commits
mailing list