[Mlir-commits] [mlir] [mlir][transform] Add linalg.fold_reshape_ops_by_expansion transform op (PR #233732)

Charitha Saumya llvmlistbot at llvm.org
Tue Oct 20 09:50:48 PDT 2026


================
@@ -276,6 +276,18 @@ void transform::ApplyEraseUnusedOperandsAndResultsPatternsOp::populatePatterns(
   linalg::populateEraseUnusedOperandsAndResultsPatterns(patterns);
 }
 
+void transform::ApplyFoldReshapeOpsByExpansionPatternsOp::populatePatterns(
+    RewritePatternSet &patterns) {
+  linalg::ControlFusionFn controlFn =
+      [foldSingleUseOnly = getFoldSingleUseOnly()](OpOperand *fusedOperand) {
+        if (!foldSingleUseOnly)
+          return true;
+        Operation *producer = fusedOperand->get().getDefiningOp();
+        return producer && producer->hasOneUse();
+      };
+  linalg::populateFoldReshapeOpsByExpansionPatterns(patterns, controlFn);
----------------
charithaintc wrote:

This is the challenge in exposing entire patterns. AFIK there is not way to "expose" custom control functions to transform dialect.  Only solution will be to make the op more fine-grained by specifying which handles exactly you want to fold. 

https://github.com/llvm/llvm-project/pull/233732


More information about the Mlir-commits mailing list