diff --git a/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h b/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h --- a/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h +++ b/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h @@ -39,6 +39,12 @@ SmallVectorImpl &staticVec, int64_t sentinel); +/// Return a vector of OpFoldResults given the special value +/// that indicates whether of the value is dynamic or not. +SmallVector getMixedValues(ArrayAttr staticValues, + ValueRange dynamicValues, + int64_t dynamicValueIndicator); + /// Extract int64_t values from the assumed ArrayAttr of IntegerAttr. SmallVector extractFromI64ArrayAttr(Attribute attr); diff --git a/mlir/lib/Dialect/Utils/StaticValueUtils.cpp b/mlir/lib/Dialect/Utils/StaticValueUtils.cpp --- a/mlir/lib/Dialect/Utils/StaticValueUtils.cpp +++ b/mlir/lib/Dialect/Utils/StaticValueUtils.cpp @@ -107,4 +107,22 @@ auto v1 = ofr1.dyn_cast(), v2 = ofr2.dyn_cast(); return v1 && v1 == v2; } + +/// Return a vector of OpFoldResults given the special value +/// that indicates whether of the value is dynamic or not. +SmallVector getMixedValues(ArrayAttr staticValues, + ValueRange dynamicValues, + int64_t dynamicValueIndicator) { + SmallVector res; + unsigned numDynamic = 0; + unsigned count = static_cast(staticValues.size()); + for (unsigned idx = 0; idx < count; ++idx) { + if (idx == dynamicValueIndicator) + res.push_back(dynamicValues[numDynamic++]); + else + res.push_back(staticValues[idx]); + } + return res; +} + } // namespace mlir diff --git a/mlir/lib/Interfaces/ViewLikeInterface.cpp b/mlir/lib/Interfaces/ViewLikeInterface.cpp --- a/mlir/lib/Interfaces/ViewLikeInterface.cpp +++ b/mlir/lib/Interfaces/ViewLikeInterface.cpp @@ -182,46 +182,23 @@ SmallVector mlir::getMixedOffsets(OffsetSizeAndStrideOpInterface op, ArrayAttr staticOffsets, ValueRange offsets) { - SmallVector res; - unsigned numDynamic = 0; - unsigned count = static_cast(staticOffsets.size()); - for (unsigned idx = 0; idx < count; ++idx) { - if (op.isDynamicOffset(idx)) - res.push_back(offsets[numDynamic++]); - else - res.push_back(staticOffsets[idx]); - } - return res; + return getMixedValues(staticOffsets, offsets, + ShapedType::kDynamicStrideOrOffset); } SmallVector mlir::getMixedSizes(OffsetSizeAndStrideOpInterface op, ArrayAttr staticSizes, ValueRange sizes) { - SmallVector res; - unsigned numDynamic = 0; - unsigned count = static_cast(staticSizes.size()); - for (unsigned idx = 0; idx < count; ++idx) { - if (op.isDynamicSize(idx)) - res.push_back(sizes[numDynamic++]); - else - res.push_back(staticSizes[idx]); - } - return res; + + return getMixedValues(staticSizes, sizes, ShapedType::kDynamicSize); } SmallVector mlir::getMixedStrides(OffsetSizeAndStrideOpInterface op, ArrayAttr staticStrides, ValueRange strides) { - SmallVector res; - unsigned numDynamic = 0; - unsigned count = static_cast(staticStrides.size()); - for (unsigned idx = 0; idx < count; ++idx) { - if (op.isDynamicStride(idx)) - res.push_back(strides[numDynamic++]); - else - res.push_back(staticStrides[idx]); - } - return res; + + return getMixedValues(staticStrides, strides, + ShapedType::kDynamicStrideOrOffset); } static std::pair>