[Mlir-commits] [mlir] [mlir][linalg] Extend `FuseElementwiseOps` pattern to work with named ops (PR #144922)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Nov 17 18:55:43 PST 2025
================
@@ -554,23 +554,42 @@ FailureOr<DropUnitDimsResult> dropUnitDims(RewriterBase &rewriter,
GenericOp genericOp,
const ControlDropUnitDims &options);
-/// Fuse two `linalg.generic` operations that have a producer-consumer
+/// Base implementation for fusion of two linalg operations.
+/// Fuse two linalg operations that have a producer-consumer
/// relationship captured through `fusedOperand`. The method expects
/// that `areElementwiseOpsFusable` returns true for the given `fusedOperand`.
+/// The resulting fused operation is always a `linalg.generic`.
+/// TODO: Support fusing to named ops when possible. For many cases,
+/// `linalg.generic` is the only op that is capable of representing the fused
+/// operation. An example exception is fusing two `linalg.map` ops. The fused
+/// result can also be represented by `linalg.map`.
struct ElementwiseOpFusionResult {
Operation *fusedOp;
llvm::DenseMap<Value, Value> replacements;
};
+template <typename LinagOpTy>
FailureOr<ElementwiseOpFusionResult>
-fuseElementwiseOps(RewriterBase &rewriter, OpOperand *fusedOperand);
+fuseElementwiseLinalgOpsImpl(RewriterBase &rewriter, OpOperand *fusedOperand);
+
+/// Specialization of `fuseElementwiseLinalgOpsImpl` for a producer-consumer of
+/// `fusedOperand` that are any `LinalgOp`.
+FailureOr<ElementwiseOpFusionResult>
+fuseElementwiseLinalgOps(RewriterBase &rewriter, OpOperand *fusedOperand);
+
+/// Specialization `fuseElementwiseLinalgOpsImpl` restricted to
----------------
srcarroll wrote:
> Should never expose the template function as a public entry point. I think I left that comment on the PR already?
yup. noted. i just haven't changed it yet
> Just have to public API point, one for LinalgOps and one for GenericOps.
yup. already doing that
>I am not following the question exactly
yes, you've entirely missed the point. you're not even trying. the very last question asks for one of two options. Not sure what's so hard about at least answering that. i'm not asking you to repeat yourself.
https://github.com/llvm/llvm-project/pull/144922
More information about the Mlir-commits
mailing list