Skip to content

Commit 9cae928

Browse files
committed
[mlir][NFC] Add static ShapedType::isDynamicShape utility
This utility is useful when we need to know if shape is dynamic and we don't have a Type itself. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D138267
1 parent fe56afc commit 9cae928

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

mlir/include/mlir/IR/BuiltinTypeInterfaces.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def ShapedTypeInterface : TypeInterface<"ShapedType"> {
9696
static constexpr bool isDynamic(int64_t dSize) {
9797
return dSize == kDynamicSize;
9898
}
99+
/// Whether the given shape has any size that indicates a dynamic dimension.
100+
static bool isDynamicShape(ArrayRef<int64_t> dSizes) {
101+
return any_of(dSizes, [](int64_t dSize) { return isDynamic(dSize); });
102+
}
99103
static constexpr bool isDynamicStrideOrOffset(int64_t dStrideOrOffset) {
100104
return dStrideOrOffset == kDynamicStrideOrOffset;
101105
}
@@ -156,7 +160,7 @@ def ShapedTypeInterface : TypeInterface<"ShapedType"> {
156160
/// all dimensions have known size (>= 0).
157161
bool hasStaticShape() const {
158162
return $_type.hasRank() &&
159-
llvm::none_of($_type.getShape(), ::mlir::ShapedType::isDynamic);
163+
!::mlir::ShapedType::isDynamicShape($_type.getShape());
160164
}
161165

162166
/// Returns if this type has a static shape and the shape is equal to

0 commit comments

Comments
 (0)