diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h --- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h +++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.h @@ -11,6 +11,7 @@ #include "mlir/Dialect/Linalg/IR/LinalgTypes.h" #include "mlir/Dialect/StandardOps/IR/Ops.h" +#include "mlir/Dialect/StandardOps/Utils/Utils.h" #include "mlir/Dialect/Utils/StructuredOpsUtils.h" #include "mlir/IR/AffineExpr.h" #include "mlir/IR/AffineMap.h" diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td --- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td +++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td @@ -256,6 +256,14 @@ SmallVector getMixedHighPad() { return getMixedPadImpl(static_high(), high()); } + SmallVector getLowPadAsValues(OpBuilder &b, Location loc) { + return getOperandsOrIntegersSizesListAsValues(b, loc, low(), + static_low()); + } + SmallVector getHighPadAsValues(OpBuilder &b, Location loc) { + return getOperandsOrIntegersSizesListAsValues(b, loc, high(), + static_high()); + } }]; let builders = [ diff --git a/mlir/include/mlir/Dialect/StandardOps/Utils/Utils.h b/mlir/include/mlir/Dialect/StandardOps/Utils/Utils.h --- a/mlir/include/mlir/Dialect/StandardOps/Utils/Utils.h +++ b/mlir/include/mlir/Dialect/StandardOps/Utils/Utils.h @@ -16,6 +16,8 @@ #ifndef MLIR_DIALECT_STANDARDOPS_UTILS_UTILS_H #define MLIR_DIALECT_STANDARDOPS_UTILS_UTILS_H +#include "mlir/IR/BuiltinAttributes.h" +#include "mlir/IR/OpImplementation.h" #include "mlir/IR/Value.h" namespace mlir { @@ -27,6 +29,21 @@ /// constructing the necessary DimOp operators. SmallVector getDynOperands(Location loc, Value val, OpBuilder &b); +/// Utility method to take a list of mixed static and dynamic values that +/// represent offsets or strides and return a vector of Values. The `values` +/// correspond to the dynamic values for the position in `integers` (which is a +/// ArrayAttr of IntegerAttrs) which contain ShapedType::kDynamicStrideOrOffset. +SmallVector getOperandsOrIntegersOffsetsOrStridesListAsValues( + OpBuilder &b, Location loc, ValueRange values, ArrayAttr integers); + +/// Utility method to take a list of mixed static and dynamic values that +/// represent sizes and return a vector of Values. The `values` correspond to +/// the dynamic values for the position in `integers` (which is a ArrayAttr of +/// IntegerAttrs) which contain ShapedType::kDynamicSize. +SmallVector +getOperandsOrIntegersSizesListAsValues(OpBuilder &b, Location loc, + ValueRange values, ArrayAttr integers); + } // end namespace mlir #endif // MLIR_DIALECT_STANDARDOPS_UTILS_UTILS_H diff --git a/mlir/lib/Dialect/StandardOps/Utils/Utils.cpp b/mlir/lib/Dialect/StandardOps/Utils/Utils.cpp --- a/mlir/lib/Dialect/StandardOps/Utils/Utils.cpp +++ b/mlir/lib/Dialect/StandardOps/Utils/Utils.cpp @@ -26,3 +26,33 @@ } return dynOperands; } + +template +static SmallVector +getOperandsOrIntegersListAsValues(OpBuilder &b, Location loc, ValueRange values, + ArrayAttr integers) { + SmallVector allValues; + unsigned dynamicOperandNum = 0; + for (auto integerValue : llvm::map_range(integers, [](Attribute attr) { + return attr.cast().getInt(); + })) { + if (integerValue != dynVal) { + allValues.push_back(b.create(loc, integerValue)); + } else { + allValues.push_back(values[dynamicOperandNum++]); + } + } + return allValues; +} + +SmallVector mlir::getOperandsOrIntegersOffsetsOrStridesListAsValues( + OpBuilder &b, Location loc, ValueRange values, ArrayAttr integers) { + return getOperandsOrIntegersListAsValues( + b, loc, values, integers); +} + +SmallVector mlir::getOperandsOrIntegersSizesListAsValues( + OpBuilder &b, Location loc, ValueRange values, ArrayAttr integers) { + return getOperandsOrIntegersListAsValues( + b, loc, values, integers); +}