@@ -2768,6 +2768,24 @@ void mlir::python::populateIRCore(py::module &m) {
2768
2768
return PyOpAttributeMap (
2769
2769
self.getOperation ().getRef ());
2770
2770
})
2771
+ .def_property_readonly (
2772
+ " context" ,
2773
+ [](PyOperationBase &self) {
2774
+ PyOperation &concreteOperation = self.getOperation ();
2775
+ concreteOperation.checkValid ();
2776
+ return concreteOperation.getContext ().getObject ();
2777
+ },
2778
+ " Context that owns the Operation" )
2779
+ .def_property_readonly (" name" ,
2780
+ [](PyOperationBase &self) {
2781
+ auto &concreteOperation = self.getOperation ();
2782
+ concreteOperation.checkValid ();
2783
+ MlirOperation operation =
2784
+ concreteOperation.get ();
2785
+ MlirStringRef name = mlirIdentifierStr (
2786
+ mlirOperationGetName (operation));
2787
+ return py::str (name.data , name.length );
2788
+ })
2771
2789
.def_property_readonly (" operands" ,
2772
2790
[](PyOperationBase &self) {
2773
2791
return PyOpOperandList (
@@ -2813,6 +2831,14 @@ void mlir::python::populateIRCore(py::module &m) {
2813
2831
},
2814
2832
" Returns the source location the operation was defined or derived "
2815
2833
" from." )
2834
+ .def_property_readonly (" parent" ,
2835
+ [](PyOperationBase &self) -> py::object {
2836
+ auto parent =
2837
+ self.getOperation ().getParentOperation ();
2838
+ if (parent)
2839
+ return parent->getObject ();
2840
+ return py::none ();
2841
+ })
2816
2842
.def (
2817
2843
" __str__" ,
2818
2844
[](PyOperationBase &self) {
@@ -2855,6 +2881,12 @@ void mlir::python::populateIRCore(py::module &m) {
2855
2881
.def (" move_before" , &PyOperationBase::moveBefore, py::arg (" other" ),
2856
2882
" Puts self immediately before the other operation in its parent "
2857
2883
" block." )
2884
+ .def (
2885
+ " clone" ,
2886
+ [](PyOperationBase &self, py::object ip) {
2887
+ return self.getOperation ().clone (ip);
2888
+ },
2889
+ py::arg (" ip" ) = py::none ())
2858
2890
.def (
2859
2891
" detach_from_parent" ,
2860
2892
[](PyOperationBase &self) {
@@ -2866,7 +2898,8 @@ void mlir::python::populateIRCore(py::module &m) {
2866
2898
operation.detachFromParent ();
2867
2899
return operation.createOpView ();
2868
2900
},
2869
- " Detaches the operation from its parent block." );
2901
+ " Detaches the operation from its parent block." )
2902
+ .def (" erase" , [](PyOperationBase &self) { self.getOperation ().erase (); });
2870
2903
2871
2904
py::class_<PyOperation, PyOperationBase>(m, " Operation" , py::module_local ())
2872
2905
.def_static (" create" , &PyOperation::create, py::arg (" name" ),
@@ -2887,45 +2920,17 @@ void mlir::python::populateIRCore(py::module &m) {
2887
2920
py::arg (" context" ) = py::none (),
2888
2921
" Parses an operation. Supports both text assembly format and binary "
2889
2922
" bytecode format." )
2890
- .def_property_readonly (" parent" ,
2891
- [](PyOperation &self) -> py::object {
2892
- auto parent = self.getParentOperation ();
2893
- if (parent)
2894
- return parent->getObject ();
2895
- return py::none ();
2896
- })
2897
- .def (" erase" , &PyOperation::erase)
2898
- .def (" clone" , &PyOperation::clone, py::arg (" ip" ) = py::none ())
2899
2923
.def_property_readonly (MLIR_PYTHON_CAPI_PTR_ATTR,
2900
2924
&PyOperation::getCapsule)
2901
2925
.def (MLIR_PYTHON_CAPI_FACTORY_ATTR, &PyOperation::createFromCapsule)
2902
- .def_property_readonly (" name" ,
2903
- [](PyOperation &self) {
2904
- self.checkValid ();
2905
- MlirOperation operation = self.get ();
2906
- MlirStringRef name = mlirIdentifierStr (
2907
- mlirOperationGetName (operation));
2908
- return py::str (name.data , name.length );
2909
- })
2910
- .def_property_readonly (
2911
- " context" ,
2912
- [](PyOperation &self) {
2913
- self.checkValid ();
2914
- return self.getContext ().getObject ();
2915
- },
2916
- " Context that owns the Operation" )
2926
+ .def_property_readonly (" operation" , [](py::object self) { return self; })
2917
2927
.def_property_readonly (" opview" , &PyOperation::createOpView);
2918
2928
2919
2929
auto opViewClass =
2920
2930
py::class_<PyOpView, PyOperationBase>(m, " OpView" , py::module_local ())
2921
2931
.def (py::init<py::object>(), py::arg (" operation" ))
2922
2932
.def_property_readonly (" operation" , &PyOpView::getOperationObject)
2923
- .def_property_readonly (
2924
- " context" ,
2925
- [](PyOpView &self) {
2926
- return self.getOperation ().getContext ().getObject ();
2927
- },
2928
- " Context that owns the Operation" )
2933
+ .def_property_readonly (" opview" , [](py::object self) { return self; })
2929
2934
.def (" __str__" , [](PyOpView &self) {
2930
2935
return py::str (self.getOperationObject ());
2931
2936
});
0 commit comments