@@ -2019,7 +2019,7 @@ PyOpView::PyOpView(const nb::object &operationObject)
20192019// PyInsertionPoint.
20202020// ------------------------------------------------------------------------------
20212021
2022- PyInsertionPoint::PyInsertionPoint (PyBlock &block) : block(block) {}
2022+ PyInsertionPoint::PyInsertionPoint (const PyBlock &block) : block(block) {}
20232023
20242024PyInsertionPoint::PyInsertionPoint (PyOperationBase &beforeOperationBase)
20252025 : refOperation(beforeOperationBase.getOperation().getRef()),
@@ -2073,6 +2073,17 @@ PyInsertionPoint PyInsertionPoint::atBlockTerminator(PyBlock &block) {
20732073 return PyInsertionPoint{block, std::move (terminatorOpRef)};
20742074}
20752075
2076+ PyInsertionPoint PyInsertionPoint::after (PyOperationBase &op) {
2077+ PyOperation &operation = op.getOperation ();
2078+ PyBlock block = operation.getBlock ();
2079+ MlirOperation nextOperation = mlirOperationGetNextInBlock (operation);
2080+ if (mlirOperationIsNull (nextOperation))
2081+ return PyInsertionPoint (block);
2082+ PyOperationRef nextOpRef = PyOperation::forOperation (
2083+ block.getParentOperation ()->getContext (), nextOperation);
2084+ return PyInsertionPoint{block, std::move (nextOpRef)};
2085+ }
2086+
20762087nb::object PyInsertionPoint::contextEnter (nb::object insertPoint) {
20772088 return PyThreadContextEntry::pushInsertionPoint (insertPoint);
20782089}
@@ -3861,6 +3872,8 @@ void mlir::python::populateIRCore(nb::module_ &m) {
38613872 nb::arg (" block" ), " Inserts at the beginning of the block." )
38623873 .def_static (" at_block_terminator" , &PyInsertionPoint::atBlockTerminator,
38633874 nb::arg (" block" ), " Inserts before the block terminator." )
3875+ .def_static (" after" , &PyInsertionPoint::after, nb::arg (" operation" ),
3876+ " Inserts after the operation." )
38643877 .def (" insert" , &PyInsertionPoint::insert, nb::arg (" operation" ),
38653878 " Inserts an operation." )
38663879 .def_prop_ro (
0 commit comments