Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit 670e9a3

Browse files
authored
[mlir] Add isStatic* size check for ShapedTypes. NFCI. (#147085)
The motivation is to avoid having to negate `isDynamic*` checks, avoid double negations, and allow for `ShapedType::isStaticDim` to be used in ADT functions without having to wrap it in a lambda performing the negation. Also add the new functions to C and Python bindings.
1 parent ba2825b commit 670e9a3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

IRTypes.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,15 @@ void mlir::PyShapedType::bindDerived(ClassTy &c) {
544544
nb::arg("dim"),
545545
"Returns whether the dim-th dimension of the given shaped type is "
546546
"dynamic.");
547+
c.def(
548+
"is_static_dim",
549+
[](PyShapedType &self, intptr_t dim) -> bool {
550+
self.requireHasRank();
551+
return mlirShapedTypeIsStaticDim(self, dim);
552+
},
553+
nb::arg("dim"),
554+
"Returns whether the dim-th dimension of the given shaped type is "
555+
"static.");
547556
c.def(
548557
"get_dim_size",
549558
[](PyShapedType &self, intptr_t dim) {
@@ -558,6 +567,12 @@ void mlir::PyShapedType::bindDerived(ClassTy &c) {
558567
nb::arg("dim_size"),
559568
"Returns whether the given dimension size indicates a dynamic "
560569
"dimension.");
570+
c.def_static(
571+
"is_static_size",
572+
[](int64_t size) -> bool { return mlirShapedTypeIsStaticSize(size); },
573+
nb::arg("dim_size"),
574+
"Returns whether the given dimension size indicates a static "
575+
"dimension.");
561576
c.def(
562577
"is_dynamic_stride_or_offset",
563578
[](PyShapedType &self, int64_t val) -> bool {
@@ -567,6 +582,15 @@ void mlir::PyShapedType::bindDerived(ClassTy &c) {
567582
nb::arg("dim_size"),
568583
"Returns whether the given value is used as a placeholder for dynamic "
569584
"strides and offsets in shaped types.");
585+
c.def(
586+
"is_static_stride_or_offset",
587+
[](PyShapedType &self, int64_t val) -> bool {
588+
self.requireHasRank();
589+
return mlirShapedTypeIsStaticStrideOrOffset(val);
590+
},
591+
nb::arg("dim_size"),
592+
"Returns whether the given shaped type stride or offset value is "
593+
"statically-sized.");
570594
c.def_prop_ro(
571595
"shape",
572596
[](PyShapedType &self) {

0 commit comments

Comments
 (0)