[Mlir-commits] [mlir] [mlir][linalg] Add constant folder for linalg.elementwise ops (PR #203608)
Vinit Deodhar
llvmlistbot at llvm.org
Fri Jun 26 08:45:54 PDT 2026
================
@@ -300,10 +300,97 @@ struct FoldConstantTranspose : public FoldConstantBase<FoldConstantTranspose> {
ControlFusionFn controlFn;
};
+
+/// Folds linalg.elementwise ops with all-constant inputs by interpreting the
+/// region body. Each op in the body is folded using its own fold()
+/// implementation, enabling constant propagation through any elementwise kind
+/// (unary, binary, ternary) without explicit per-kind handling.
+struct FoldConstantElementwise
+ : public FoldConstantBase<FoldConstantElementwise> {
+
+ using FoldConstantBase::FoldConstantBase;
+
+ bool matchIndexingMaps(LinalgOp linalgOp) const {
----------------
vinitdeodhar wrote:
The function is used at FoldConstantBase at line 106. However, I agree the name is misleading here since we're just doing a type check rather than inspecting indexing maps. I can rename the CRTP hook to something more generic like matchOp. If it is okay, I will do this as a follow up bundled with other changes to FoldConstantBase
https://github.com/llvm/llvm-project/pull/203608
More information about the Mlir-commits
mailing list