[Mlir-commits] [mlir] a6bf6f2 - [mlir][Linalg] Let FuseIntoContainingOp return success when nothing is fused.

Nicolas Vasilache llvmlistbot at llvm.org
Fri Aug 12 02:18:40 PDT 2022


Author: Nicolas Vasilache
Date: 2022-08-12T02:18:31-07:00
New Revision: a6bf6f25f070b92ecb50465f6a270671d30e459a

URL: https://github.com/llvm/llvm-project/commit/a6bf6f25f070b92ecb50465f6a270671d30e459a
DIFF: https://github.com/llvm/llvm-project/commit/a6bf6f25f070b92ecb50465f6a270671d30e459a.diff

LOG: [mlir][Linalg] Let FuseIntoContainingOp return success when nothing is fused.

This composes better when the op is applied in situations where it does not match.

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

Added: 
    

Modified: 
    mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
    mlir/test/Dialect/Linalg/transform-op-fuse-into-containing.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index 1473efb2ff198..8f2fb306030bd 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -300,6 +300,11 @@ transform::FuseIntoContainingOp::apply(transform::TransformResults &results,
                                        transform::TransformState &state) {
   SmallVector<Operation *> fusedOps;
   ArrayRef<Operation *> producerOps = state.getPayloadOps(getProducerOp());
+  // If nothing to fuse, propagate success.
+  if (producerOps.empty()) {
+    results.set(getResult().cast<OpResult>(), SmallVector<mlir::Operation *>{});
+    return DiagnosedSilenceableFailure::success();
+  }
   for (Operation *producerOp : producerOps) {
     if (producerOp->getNumResults() != 1) {
       Diagnostic diag(producerOp->getLoc(), DiagnosticSeverity::Note);
@@ -310,7 +315,8 @@ transform::FuseIntoContainingOp::apply(transform::TransformResults &results,
   ArrayRef<Operation *> containingOps = state.getPayloadOps(getContainingOp());
   if (containingOps.size() != 1)
     return DiagnosedSilenceableFailure(
-        this->emitOpError("requires exactly one containing_op handle"));
+        this->emitOpError("requires exactly one containing_op handle (got ")
+        << containingOps.size() << ")");
   Operation *containingOp = containingOps.front();
 
   // Helper function to find the next producer that should be fused. Take any

diff  --git a/mlir/test/Dialect/Linalg/transform-op-fuse-into-containing.mlir b/mlir/test/Dialect/Linalg/transform-op-fuse-into-containing.mlir
index 8b95cec4fcb8c..3d7009f1eb970 100644
--- a/mlir/test/Dialect/Linalg/transform-op-fuse-into-containing.mlir
+++ b/mlir/test/Dialect/Linalg/transform-op-fuse-into-containing.mlir
@@ -36,6 +36,11 @@ module {
     func.return %2 : tensor<?xf32>
   }
 
+  // Check no failure when nothing happens.
+  func.func @dummy1() { return }
+  func.func @dummy2() { return }
+  func.func @dummy3() { return }
+
   transform.with_pdl_patterns {
   ^bb0(%arg0: !pdl.operation):
     transform.sequence %arg0 {


        


More information about the Mlir-commits mailing list