mlir/TosaToLinalg: improve debugging during conversion
authorRamkumar Ramachandra <r@artagnon.com>
Mon, 5 Dec 2022 19:15:57 +0000 (11:15 -0800)
committerRob Suderman <suderman@google.com>
Mon, 5 Dec 2022 19:40:08 +0000 (11:40 -0800)
Make systematic use of notifyMatchFailure.

Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>
Reviewed By: rsuderman

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

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp

index 839dfb4..ab21055 100644 (file)
@@ -639,7 +639,8 @@ elementwiseMatchAndRewriteHelper(Operation *operation,
       });
 
   if (didEncounterError)
-    return failure();
+    return rewriter.notifyMatchFailure(
+        operation, "unable to create linalg.generic body for elementwise op");
 
   rewriter.replaceOp(operation, linalgOp->getResults());
   return success();
@@ -816,7 +817,8 @@ static LogicalResult reduceMatchAndRewriteHelper(Operation *op, uint64_t axis,
       });
 
   if (!didEncounterError)
-    return failure();
+    return rewriter.notifyMatchFailure(
+        op, "unable to create linalg.generic body for reduce op");
 
   SmallVector<ReassociationExprs, 4> reassociationMap;
   uint64_t expandInputRank =
@@ -1086,7 +1088,7 @@ public:
                                 PatternRewriter &rewriter) const final {
     DenseIntElementsAttr perms;
     if (!matchPattern(op.getPerms(), m_Constant(&perms))) {
-      return failure();
+      return rewriter.notifyMatchFailure(op, "unmatched permutation tensor");
     }
 
     auto loc = op.getLoc();
@@ -1348,7 +1350,8 @@ public:
 
     // TODO(suderman): These string values should be declared the TOSA dialect.
     if (op.getMode() != "NEAREST_NEIGHBOR" && op.getMode() != "BILINEAR")
-      return failure();
+      return rewriter.notifyMatchFailure(
+          op, "tosa.resize mode should be NEAREST_NEIGHBOR or BILINEAR");
 
     const bool isBilinear = op.getMode() == "BILINEAR";
 
@@ -1439,11 +1442,13 @@ public:
     auto dynamicDimsOr =
         checkHasDynamicBatchDims(rewriter, op, {input, op.getOutput()});
     if (!dynamicDimsOr.has_value())
-      return failure();
+      return rewriter.notifyMatchFailure(
+          op, "unable to get dynamic dimensions of tosa.resize");
     SmallVector<Value> dynamicDims = dynamicDimsOr.value();
 
     if (op.getMode() != "NEAREST_NEIGHBOR" && op.getMode() != "BILINEAR")
-      return failure();
+      return rewriter.notifyMatchFailure(
+          op, "tosa.resize mode should be NEAREST_NEIGHBOR or BILINEAR");
 
     auto emptyTensor = rewriter.create<tensor::EmptyOp>(
         loc, resultTy.getShape(), resultElementTy, dynamicDims);
@@ -2149,7 +2154,8 @@ public:
     auto dynamicDimsOr = checkHasDynamicBatchDims(
         rewriter, op, {input, indices, op.getOutput()});
     if (!dynamicDimsOr.has_value())
-      return failure();
+      return rewriter.notifyMatchFailure(
+          op, "tosa.gather currently only supports dynamic batch dimensions");
     SmallVector<Value> dynamicDims = dynamicDimsOr.value();
 
     auto resultElementTy = resultTy.getElementType();