From fe0befb123e4a727c3c883845c9d3bfe75d831c7 Mon Sep 17 00:00:00 2001 From: Matthias Springer Date: Mon, 7 Jun 2021 20:13:08 +0900 Subject: [PATCH] [mlir][linalg] Add padding helper functions to PadTensorOp 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td index d74e407640b0..8b0766b2f703 100644 --- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td +++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td @@ -263,6 +263,18 @@ def Linalg_PadTensorOp : Linalg_Op<"pad_tensor", SmallVector 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 = [