[mlir][linalg] Add padding helper functions to PadTensorOp
authorMatthias Springer <springerm@google.com>
Mon, 7 Jun 2021 11:13:08 +0000 (20:13 +0900)
committerMatthias Springer <springerm@google.com>
Mon, 7 Jun 2021 11:18:06 +0000 (20:18 +0900)
Add helper functions to quickly check for zero low/high padding.

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

mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td

index d74e407..8b0766b 100644 (file)
@@ -263,6 +263,18 @@ def Linalg_PadTensorOp : Linalg_Op<"pad_tensor",
     SmallVector<OpFoldResult> getMixedHighPad() {
       return getMixedPadImpl(static_high(), high());
     }
+    // Return true if low padding is guaranteed to be 0.
+    bool hasZeroLowPad() {
+      return llvm::all_of(getMixedLowPad(), [](OpFoldResult ofr) {
+        return mlir::isEqualConstantInt(ofr, 0);
+      });
+    }
+    // Return true if high padding is guaranteed to be 0.
+    bool hasZeroHighPad() {
+      return llvm::all_of(getMixedHighPad(), [](OpFoldResult ofr) {
+        return mlir::isEqualConstantInt(ofr, 0);
+      });
+    }
   }];
 
   let builders = [