Skip to content

Commit bfde178

Browse files
authored
[mlir] Update the return type of getNum{Dynamic|Scalable}Dims (llvm#110472)
Updates the return type of `getNumDynamicDims` and `getNumScalableDims` from `int64_t` to `size_t`. This is for consistency with other helpers/methods that return "size" and to reduce the number of `static_cast`s in various places.
1 parent 0617629 commit bfde178

File tree

7 files changed

+10
-17
lines changed

7 files changed

+10
-17
lines changed

mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class SparseTensorType {
293293
/// Returns the number of dimensions which have dynamic sizes.
294294
/// The return type is `int64_t` to maintain consistency with
295295
/// `ShapedType::Trait<T>::getNumDynamicDims`.
296-
int64_t getNumDynamicDims() const { return rtp.getNumDynamicDims(); }
296+
size_t getNumDynamicDims() const { return rtp.getNumDynamicDims(); }
297297

298298
ArrayRef<LevelType> getLvlTypes() const { return enc.getLvlTypes(); }
299299
LevelType getLvlType(Level l) const {

mlir/include/mlir/IR/BuiltinTypeInterfaces.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def ShapedTypeInterface : TypeInterface<"ShapedType"> {
166166

167167
/// If this is a ranked type, return the number of dimensions with dynamic
168168
/// size. Otherwise, abort.
169-
int64_t getNumDynamicDims() const {
169+
size_t getNumDynamicDims() const {
170170
return llvm::count_if($_type.getShape(), ::mlir::ShapedType::isDynamic);
171171
}
172172

mlir/include/mlir/IR/BuiltinTypes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ def Builtin_Vector : Builtin_Type<"Vector", "vector",
12531253
}
12541254

12551255
/// Get the number of scalable dimensions.
1256-
int64_t getNumScalableDims() const {
1256+
size_t getNumScalableDims() const {
12571257
return llvm::count(getScalableDims(), true);
12581258
}
12591259

mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ AllocTensorOp::getBufferType(Value value, const BufferizationOptions &options,
249249
LogicalResult AllocTensorOp::verify() {
250250
if (getCopy() && !getDynamicSizes().empty())
251251
return emitError("dynamic sizes not needed when copying a tensor");
252-
if (!getCopy() && getType().getNumDynamicDims() !=
253-
static_cast<int64_t>(getDynamicSizes().size()))
252+
if (!getCopy() && getType().getNumDynamicDims() != getDynamicSizes().size())
254253
return emitError("expected ")
255254
<< getType().getNumDynamicDims() << " dynamic sizes";
256255
if (getCopy() && getCopy().getType() != getType())

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,8 +2045,7 @@ void WaitOp::getCanonicalizationPatterns(RewritePatternSet &results,
20452045
LogicalResult AllocOp::verify() {
20462046
auto memRefType = llvm::cast<MemRefType>(getMemref().getType());
20472047

2048-
if (static_cast<int64_t>(getDynamicSizes().size()) !=
2049-
memRefType.getNumDynamicDims())
2048+
if (getDynamicSizes().size() != memRefType.getNumDynamicDims())
20502049
return emitOpError("dimension operand count does not equal memref "
20512050
"dynamic dimension count");
20522051

mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ static LogicalResult verifyAllocLikeOp(AllocLikeOp op) {
205205
if (!memRefType)
206206
return op.emitOpError("result must be a memref");
207207

208-
if (static_cast<int64_t>(op.getDynamicSizes().size()) !=
209-
memRefType.getNumDynamicDims())
208+
if (op.getDynamicSizes().size() != memRefType.getNumDynamicDims())
210209
return op.emitOpError("dimension operand count does not equal memref "
211210
"dynamic dimension count");
212211

@@ -283,8 +282,7 @@ struct SimplifyAllocConst : public OpRewritePattern<AllocLikeOp> {
283282
// Create new memref type (which will have fewer dynamic dimensions).
284283
MemRefType newMemRefType =
285284
MemRefType::Builder(memrefType).setShape(newShapeConstants);
286-
assert(static_cast<int64_t>(dynamicSizes.size()) ==
287-
newMemRefType.getNumDynamicDims());
285+
assert(dynamicSizes.size() == newMemRefType.getNumDynamicDims());
288286

289287
// Create and insert the alloc op for the new memref.
290288
auto newAlloc = rewriter.create<AllocLikeOp>(

mlir/lib/Dialect/Tensor/IR/TensorOps.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ static RankedTensorType
179179
foldDynamicToStaticDimSizes(RankedTensorType type, ValueRange dynamicSizes,
180180
SmallVector<Value> &foldedDynamicSizes) {
181181
SmallVector<int64_t> staticShape(type.getShape());
182-
assert(type.getNumDynamicDims() ==
183-
static_cast<int64_t>(dynamicSizes.size()) &&
182+
assert(type.getNumDynamicDims() == dynamicSizes.size() &&
184183
"incorrect number of dynamic sizes");
185184

186185
// Compute new static and dynamic sizes.
@@ -894,8 +893,7 @@ void EmptyOp::build(OpBuilder &builder, OperationState &result,
894893
}
895894

896895
LogicalResult EmptyOp::verify() {
897-
if (getType().getNumDynamicDims() !=
898-
static_cast<int64_t>(getDynamicSizes().size()))
896+
if (getType().getNumDynamicDims() != getDynamicSizes().size())
899897
return emitOpError("incorrect number of dynamic sizes, has ")
900898
<< getDynamicSizes().size() << ", expected "
901899
<< getType().getNumDynamicDims();
@@ -3672,8 +3670,7 @@ void SplatOp::getAsmResultNames(
36723670
}
36733671

36743672
LogicalResult SplatOp::verify() {
3675-
if (getType().getNumDynamicDims() !=
3676-
static_cast<int64_t>(getDynamicSizes().size()))
3673+
if (getType().getNumDynamicDims() != getDynamicSizes().size())
36773674
return emitOpError("incorrect number of dynamic sizes, has ")
36783675
<< getDynamicSizes().size() << ", expected "
36793676
<< getType().getNumDynamicDims();

0 commit comments

Comments
 (0)