This repository was archived by the owner on Oct 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -1454,6 +1454,14 @@ void PyOperationBase::moveBefore(PyOperationBase &other) {
14541454 operation.parentKeepAlive = otherOp.parentKeepAlive ;
14551455}
14561456
1457+ bool PyOperationBase::isBeforeInBlock (PyOperationBase &other) {
1458+ PyOperation &operation = getOperation ();
1459+ PyOperation &otherOp = other.getOperation ();
1460+ operation.checkValid ();
1461+ otherOp.checkValid ();
1462+ return mlirOperationIsBeforeInBlock (operation, otherOp);
1463+ }
1464+
14571465bool PyOperationBase::verify () {
14581466 PyOperation &op = getOperation ();
14591467 PyMlirContext::ErrorCapture errors (op.getContext ());
@@ -3409,6 +3417,13 @@ void mlir::python::populateIRCore(nb::module_ &m) {
34093417 .def (" move_before" , &PyOperationBase::moveBefore, nb::arg (" other" ),
34103418 " Puts self immediately before the other operation in its parent "
34113419 " block." )
3420+ .def (" is_before_in_block" , &PyOperationBase::isBeforeInBlock,
3421+ nb::arg (" other" ),
3422+ " Given an operation 'other' that is within the same parent block, "
3423+ " return"
3424+ " whether the current operation is before 'other' in the operation "
3425+ " list"
3426+ " of the parent block." )
34123427 .def (
34133428 " clone" ,
34143429 [](PyOperationBase &self, nb::object ip) {
Original file line number Diff line number Diff line change @@ -624,6 +624,13 @@ class PyOperationBase {
624624 void moveAfter (PyOperationBase &other);
625625 void moveBefore (PyOperationBase &other);
626626
627+ // / Given an operation 'other' that is within the same parent block, return
628+ // / whether the current operation is before 'other' in the operation list
629+ // / of the parent block.
630+ // / Note: This function has an average complexity of O(1), but worst case may
631+ // / take O(N) where N is the number of operations within the parent block.
632+ bool isBeforeInBlock (PyOperationBase &other);
633+
627634 // / Verify the operation. Throws `MLIRError` if verification fails, and
628635 // / returns `true` otherwise.
629636 bool verify ();
You can’t perform that action at this time.
0 commit comments