[Mlir-commits] [mlir] [mlir][EmitC] Expand the MemRefToEmitC pass - Lowering `CopyOp` (PR #151206)
Jaden Angella
llvmlistbot at llvm.org
Tue Aug 5 10:45:37 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 {
+ int64_t rank = arrayValue.getType().getRank();
+ llvm::SmallVector<mlir::Value> indices;
+ for (int i = 0; i < rank; ++i) {
+ indices.push_back(zeroIndex);
+ }
+
+ emitc::SubscriptOp subPtr = rewriter.create<emitc::SubscriptOp>(
+ loc, arrayValue, mlir::ValueRange(indices));
+ emitc::ApplyOp ptr = rewriter.create<emitc::ApplyOp>(
+ loc, emitc::PointerType::get(memrefType.getElementType()),
----------------
Jaddyen wrote:
ack, thanks for the feedback!
https://github.com/llvm/llvm-project/pull/151206
More information about the Mlir-commits
mailing list