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,20 +39,18 @@ /// Helper function to dispatch an OpFoldResult into `staticVec` if: /// a) it is an IntegerAttr /// In other cases, the OpFoldResult is dispached to the `dynamicVec`. -/// In such dynamic cases, a copy of the `sentinel` value is also pushed to +/// In such dynamic cases, ShapedType::kDynamic is also pushed to /// `staticVec`. This is useful to extract mixed static and dynamic entries that /// come from an AttrSizedOperandSegments trait. void dispatchIndexOpFoldResult(OpFoldResult ofr, SmallVectorImpl &dynamicVec, - SmallVectorImpl &staticVec, - int64_t sentinel); + SmallVectorImpl &staticVec); /// Helper function to dispatch multiple OpFoldResults according to the behavior /// of `dispatchIndexOpFoldResult(OpFoldResult ofr` for a single OpFoldResult. void dispatchIndexOpFoldResults(ArrayRef ofrs, SmallVectorImpl &dynamicVec, - SmallVectorImpl &staticVec, - int64_t sentinel); + SmallVectorImpl &staticVec); /// Extract int64_t values from the assumed ArrayAttr of IntegerAttr. SmallVector extractFromI64ArrayAttr(Attribute attr); diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp --- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp +++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp @@ -1457,8 +1457,7 @@ ArrayAttr mapping) { SmallVector staticTileSizes; SmallVector dynamicTileSizes; - dispatchIndexOpFoldResults(mixedTileSizes, dynamicTileSizes, staticTileSizes, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(mixedTileSizes, dynamicTileSizes, staticTileSizes); // Call the default builder which sets up the proper operands segment sizes // attributes for multiple variadic operands. In the absence of this, horrible // bugs ensue. @@ -1493,7 +1492,7 @@ SmallVector staticNumThreads; SmallVector dynamicNumThreads; dispatchIndexOpFoldResults(mixedNumThreads, dynamicNumThreads, - staticNumThreads, ShapedType::kDynamic); + staticNumThreads); // Call the default builder which sets up the proper operands segment sizes // attributes for multiple variadic operands. In the absence of this, horrible // bugs ensue. diff --git a/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp b/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp @@ -278,8 +278,7 @@ SmallVector dynamicDims; for (int64_t idx : llvm::seq(0, oldShape.size() + 1)) { if (idx == insertSplitDimension) { - dispatchIndexOpFoldResults(sizes[idx], dynamicDims, newOutputShape, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(sizes[idx], dynamicDims, newOutputShape); continue; } int64_t oldIdx = idx < insertSplitDimension ? idx : idx - 1; diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp --- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp @@ -1769,12 +1769,9 @@ ArrayRef attrs) { SmallVector staticOffsets, staticSizes, staticStrides; SmallVector dynamicOffsets, dynamicSizes, dynamicStrides; - dispatchIndexOpFoldResults(offset, dynamicOffsets, staticOffsets, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(offset, dynamicOffsets, staticOffsets); + dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes); + dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides); build(b, result, resultType, source, dynamicOffsets, dynamicSizes, dynamicStrides, b.getDenseI64ArrayAttr(staticOffsets), b.getDenseI64ArrayAttr(staticSizes), @@ -2577,12 +2574,9 @@ ArrayRef strides) { SmallVector staticOffsets, staticSizes, staticStrides; SmallVector dynamicOffsets, dynamicSizes, dynamicStrides; - dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets); + dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes); + dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides); return SubViewOp::inferResultType(sourceMemRefType, staticOffsets, staticSizes, staticStrides); } @@ -2627,12 +2621,9 @@ ArrayRef strides) { SmallVector staticOffsets, staticSizes, staticStrides; SmallVector dynamicOffsets, dynamicSizes, dynamicStrides; - dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets); + dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes); + dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides); return SubViewOp::inferRankReducedResultType( resultShape, sourceRankedTensorType, staticOffsets, staticSizes, staticStrides); @@ -2648,12 +2639,9 @@ ArrayRef attrs) { SmallVector staticOffsets, staticSizes, staticStrides; SmallVector dynamicOffsets, dynamicSizes, dynamicStrides; - dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets); + dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes); + dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides); auto sourceMemRefType = source.getType().cast(); // Structuring implementation this way avoids duplication between builders. if (!resultType) { diff --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp --- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp +++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp @@ -519,8 +519,7 @@ Attribute encoding) { SmallVector staticShape; SmallVector dynamicSizes; - dispatchIndexOpFoldResults(sizes, dynamicSizes, staticShape, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(sizes, dynamicSizes, staticShape); build(builder, result, staticShape, elementType, dynamicSizes, encoding); } @@ -1575,12 +1574,9 @@ ArrayRef sizes, ArrayRef strides) { SmallVector staticOffsets, staticSizes, staticStrides; SmallVector dynamicOffsets, dynamicSizes, dynamicStrides; - dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets); + dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes); + dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides); return ExtractSliceOp::inferResultType(sourceShapedTensorType, staticOffsets, staticSizes, staticStrides); } @@ -1623,12 +1619,9 @@ ArrayRef strides) { SmallVector staticOffsets, staticSizes, staticStrides; SmallVector dynamicOffsets, dynamicSizes, dynamicStrides; - dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets); + dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes); + dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides); return ExtractSliceOp::inferCanonicalRankReducedResultType( desiredResultRank, sourceRankedTensorType, staticOffsets, staticSizes, staticStrides); @@ -1644,12 +1637,9 @@ ArrayRef attrs) { SmallVector staticOffsets, staticSizes, staticStrides; SmallVector dynamicOffsets, dynamicSizes, dynamicStrides; - dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets); + dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes); + dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides); auto sourceRankedTensorType = source.getType().cast(); // Structuring implementation this way avoids duplication between builders. if (!resultType) { @@ -2081,12 +2071,9 @@ ArrayRef attrs) { SmallVector staticOffsets, staticSizes, staticStrides; SmallVector dynamicOffsets, dynamicSizes, dynamicStrides; - dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets); + dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes); + dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides); build(b, result, dest.getType(), source, dest, dynamicOffsets, dynamicSizes, dynamicStrides, b.getDenseI64ArrayAttr(staticOffsets), b.getDenseI64ArrayAttr(staticSizes), @@ -2542,9 +2529,8 @@ // This will grow staticLow and staticHigh with 1 value. If the config is // dynamic (ie not a constant), dynamicLow and dynamicHigh will grow with 1 // value as well. - dispatchIndexOpFoldResults(low, dynamicLow, staticLow, ShapedType::kDynamic); - dispatchIndexOpFoldResults(high, dynamicHigh, staticHigh, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(low, dynamicLow, staticLow); + dispatchIndexOpFoldResults(high, dynamicHigh, staticHigh); if (!resultType) { resultType = PadOp::inferResultType(sourceType, staticLow, staticHigh); } @@ -2891,12 +2877,9 @@ ArrayRef attrs) { SmallVector staticOffsets, staticSizes, staticStrides; SmallVector dynamicOffsets, dynamicSizes, dynamicStrides; - dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes, - ShapedType::kDynamic); - dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(offsets, dynamicOffsets, staticOffsets); + dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes); + dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides); build(b, result, {}, source, dest, dynamicOffsets, dynamicSizes, dynamicStrides, b.getDenseI64ArrayAttr(staticOffsets), b.getDenseI64ArrayAttr(staticSizes), @@ -3063,8 +3046,7 @@ "applies to only pack or unpack operations"); SmallVector dynamicTiles; SmallVector staticTiles; - dispatchIndexOpFoldResults(op.getMixedTiles(), dynamicTiles, staticTiles, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(op.getMixedTiles(), dynamicTiles, staticTiles); return staticTiles; } @@ -3211,8 +3193,7 @@ "original dimensions to be tiled"); SmallVector staticTileSizes; SmallVector dynamicTileSizes; - dispatchIndexOpFoldResults(innerTiles, dynamicTileSizes, staticTileSizes, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(innerTiles, dynamicTileSizes, staticTileSizes); build(builder, state, dest.getType(), source, dest, paddingValue ? paddingValue.value() : nullptr, outerDimsPerm.empty() ? nullptr @@ -3420,8 +3401,7 @@ "original dimensions to be tiled"); SmallVector staticTileSizes; SmallVector dynamicTileSizes; - dispatchIndexOpFoldResults(innerTiles, dynamicTileSizes, staticTileSizes, - ShapedType::kDynamic); + dispatchIndexOpFoldResults(innerTiles, dynamicTileSizes, staticTileSizes); build(builder, state, dest.getType(), source, dest, outerDimsPerm.empty() ? nullptr : builder.getDenseI64ArrayAttr(outerDimsPerm), diff --git a/mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp b/mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp --- a/mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp +++ b/mlir/lib/Dialect/Tensor/IR/TensorTilingInterfaceImpl.cpp @@ -358,7 +358,7 @@ // The shape of the result can be obtained from the sizes passed in. SmallVector dynDims; SmallVector shape; - dispatchIndexOpFoldResults(sizes, dynDims, shape, ShapedType::kDynamic); + dispatchIndexOpFoldResults(sizes, dynDims, shape); RankedTensorType resultType = RankedTensorType::get(shape, padOp.getResultType().getElementType()); 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 @@ -37,8 +37,7 @@ /// come from an AttrSizedOperandSegments trait. void dispatchIndexOpFoldResult(OpFoldResult ofr, SmallVectorImpl &dynamicVec, - SmallVectorImpl &staticVec, - int64_t sentinel) { + SmallVectorImpl &staticVec) { auto v = ofr.dyn_cast(); if (!v) { APInt apInt = ofr.get().cast().getValue(); @@ -46,15 +45,14 @@ return; } dynamicVec.push_back(v); - staticVec.push_back(sentinel); + staticVec.push_back(ShapedType::kDynamic); } void dispatchIndexOpFoldResults(ArrayRef ofrs, SmallVectorImpl &dynamicVec, - SmallVectorImpl &staticVec, - int64_t sentinel) { + SmallVectorImpl &staticVec) { for (OpFoldResult ofr : ofrs) - dispatchIndexOpFoldResult(ofr, dynamicVec, staticVec, sentinel); + dispatchIndexOpFoldResult(ofr, dynamicVec, staticVec); } /// Extract int64_t values from the assumed ArrayAttr of IntegerAttr.