[Mlir-commits] [mlir] [mlir][Linalg] Add transform to convert linalg.copy into memref.copy (PR #132422)
Pablo Antonio Martinez
llvmlistbot at llvm.org
Fri Mar 28 10:40:23 PDT 2025
================
@@ -1176,6 +1176,60 @@ LogicalResult transform::InterchangeOp::verify() {
return success();
}
+//===----------------------------------------------------------------------===//
+// LinalgCopyToMemrefOp
+//===----------------------------------------------------------------------===//
+
+DiagnosedSilenceableFailure transform::LinalgCopyToMemrefOp::applyToOne(
+ transform::TransformRewriter &rewriter, Operation *targetOp,
+ transform::ApplyToEachResultList &results,
+ transform::TransformState &state) {
+
+ // Check if the target can be converted
+ if (!isa<linalg::CopyOp>(targetOp)) {
+ DiagnosedSilenceableFailure diag =
+ emitSilenceableError() << "only linalg.copy target ops are supported";
+ diag.attachNote(targetOp->getLoc()) << "target op";
+ return diag;
+ }
+
+ auto copyOp = dyn_cast<linalg::CopyOp>(targetOp);
+ if (!copyOp.hasPureBufferSemantics()) {
+ DiagnosedSilenceableFailure diag =
+ emitSilenceableError()
+ << "linalg.copy on tensors cannot be transformed into memref.copy";
+ diag.attachNote(targetOp->getLoc()) << "target op";
+ return diag;
+ }
+
+ SmallVector<Value> inputs = copyOp.getInputs();
+ SmallVector<Value> outputs = copyOp.getOutputs();
+ assert(inputs.size() == 1 && "expected linalg copy op with one input");
+ assert(outputs.size() == 1 && "expected memref copy op with one output");
+ Value input = inputs.front();
+ Value output = outputs.front();
+
+ // linalg.copy supports different element types on source/dest whereas
+ // memref.copy does not, so we must check here that the types are the same,
----------------
pabloantoniom wrote:
Done
https://github.com/llvm/llvm-project/pull/132422
More information about the Mlir-commits
mailing list