[Mlir-commits] [mlir] [mlir][EmitC] Expand the MemRefToEmitC pass - Lowering `CopyOp` (PR #151206)

Gil Rapaport llvmlistbot at llvm.org
Tue Aug 5 05:56:16 PDT 2025


================
@@ -159,6 +185,71 @@ struct ConvertAlloc final : public OpConversionPattern<memref::AllocOp> {
   }
 };
 
+struct ConvertCopy final : public OpConversionPattern<memref::CopyOp> {
+  using OpConversionPattern::OpConversionPattern;
+
+  LogicalResult
+  matchAndRewrite(memref::CopyOp copyOp, OpAdaptor operands,
+                  ConversionPatternRewriter &rewriter) const override {
+    Location loc = copyOp.getLoc();
+    MemRefType srcMemrefType = cast<MemRefType>(copyOp.getSource().getType());
+    MemRefType targetMemrefType =
+        cast<MemRefType>(copyOp.getTarget().getType());
+
+    if (!isMemRefTypeLegalForEmitC(srcMemrefType)) {
+      return rewriter.notifyMatchFailure(
+          loc, "incompatible source memref type for EmitC conversion");
+    }
+    if (!isMemRefTypeLegalForEmitC(targetMemrefType)) {
+      return rewriter.notifyMatchFailure(
+          loc, "incompatible target memref type for EmitC conversion");
+    }
+
+    auto createPointerFromEmitcArray =
+        [&](mlir::Location loc, mlir::OpBuilder &rewriter,
+            mlir::TypedValue<emitc::ArrayType> arrayValue,
+            mlir::MemRefType memrefType,
+            emitc::ConstantOp zeroIndex) -> emitc::ApplyOp {
----------------
aniragil wrote:

- You're already capturing rewriter and zeroIndex, no need to pass them as arguments (if you move zeroIndex creation above the lambda).
- Usually better to capture exactly lambda uses than capture everything (`&`).

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


More information about the Mlir-commits mailing list