[Mlir-commits] [mlir] [mlir][linalg] convert arith ops to destination-passing-style. (PR #157854)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Wed Sep 10 06:58:37 PDT 2025
================
@@ -603,6 +612,56 @@ Value linalg::bufferizeToAllocation(
}
namespace {
+template <typename OpTy>
+FailureOr<Operation *>
+rewriteArithInDestinationPassingStyle(RewriterBase &rewriter, OpTy op) {
+ // reject ops such as `arith.constant` and `arith.select`.
+ auto numOperands = op->getNumOperands();
+ if (numOperands == 0 || numOperands > 2)
+ return failure();
+
+ // destination passing style rewrite is only for ops on tensor types.
+ Type resultType = op->getResult(0).getType();
+ auto tensorType = dyn_cast<RankedTensorType>(resultType);
+ if (!tensorType)
+ return failure();
+
+ auto loc = op.getLoc();
+ OpBuilder::InsertionGuard g(rewriter);
+ auto dynSizes = reifyOrComputeDynamicSizes(rewriter, op->getOperand(0));
+
+ // Create tensor.empty.
+ Value empty = tensor::EmptyOp::create(rewriter, loc, resultType, dynSizes);
----------------
banach-space wrote:
[nit] Use more descriptive variable name rather than `empty` to repeats _how_ the variable is defined and that's available on LHS (i.e. `tensor::EmptyOp::create`). Perhaps `init` or `outs`? Or `initForGeneric`?
https://github.com/llvm/llvm-project/pull/157854
More information about the Mlir-commits
mailing list