[mlir][linalg] Pad independent of application order (NFC).
authorgysit <gysit@google.com>
Mon, 6 Dec 2021 07:25:24 +0000 (07:25 +0000)
committergysit <gysit@google.com>
Mon, 6 Dec 2021 07:26:15 +0000 (07:26 +0000)
This revision makes the padding pattern independent of the application order. It addresses the concern that we cannot rely on the execution order of the greedy rewriter (https://reviews.llvm.org/D114689). Instead, the pattern is updated to apply repeatedly till all operations are padded.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D114851

mlir/lib/Dialect/Linalg/Transforms/LinalgStrategyPasses.cpp
mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp

index c006a1e778012725138df855c7a57b167d6dea6d..0da17434c42980c94ecdc8b6d5212587fa57fe4b 100644 (file)
@@ -132,19 +132,7 @@ struct LinalgStrategyPadPass
       paddingPattern.add<LinalgPaddingPattern>(funcOp.getContext(), options,
                                                filter);
     }
-    // Traverse the operations top down to pad producers before consumers. The
-    // extract slice operation introduced after every padded operation enables
-    // padding its consumers. Padding an operation whose producers have not been
-    // padded before fails due to the missing extract slice operations. In this
-    // case, the padding pattern increments the transformation marker without
-    // padding the operation. The top down traversal is thus not only a
-    // performance optimization but also needed to pad all operations along the
-    // use-def chains.
-    GreedyRewriteConfig config;
-    config.useTopDownTraversal = true;
-    if (failed(applyPatternsAndFoldGreedily(funcOp, std::move(paddingPattern),
-                                            config)))
-      signalPassFailure();
+    (void)applyPatternsAndFoldGreedily(funcOp, std::move(paddingPattern));
   }
 
   LinalgPaddingOptions options;
index 917ff770a3b5a5d60c24fe1f4ccd23ca9ce337c5..e2d16cf285d398bb3d2082b157d3f31d48e17616 100644 (file)
@@ -503,10 +503,8 @@ LogicalResult mlir::linalg::LinalgPaddingPattern::matchAndRewrite(
   FailureOr<SmallVector<Value>> newResults = rewriteAsPaddedOp(
       rewriter, linalgOp, options.paddingValueComputationFunction,
       options.paddingNoFoldComputationFunction, paddedOp);
-  if (failed(newResults)) {
-    filter.replaceLinalgTransformationFilter(rewriter, linalgOp);
+  if (failed(newResults))
     return failure();
-  }
 
   // Compute the desired hoisting depths.
   SmallVector<int64_t> depths;