File tree Expand file tree Collapse file tree 4 files changed +25
-3
lines changed Expand file tree Collapse file tree 4 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -634,6 +634,10 @@ MLIR_CAPI_EXPORTED MlirContext mlirOperationGetContext(MlirOperation op);
634
634
/// Gets the location of the operation.
635
635
MLIR_CAPI_EXPORTED MlirLocation mlirOperationGetLocation (MlirOperation op );
636
636
637
+ /// Sets the location of the operation.
638
+ MLIR_CAPI_EXPORTED void mlirOperationSetLocation (MlirOperation op ,
639
+ MlirLocation loc );
640
+
637
641
/// Gets the type id of the operation.
638
642
/// Returns null if the operation does not have a registered operation
639
643
/// description.
Original file line number Diff line number Diff line change @@ -3485,15 +3485,21 @@ void mlir::python::populateIRCore(nb::module_ &m) {
3485
3485
},
3486
3486
" Shortcut to get an op result if it has only one (throws an error "
3487
3487
" otherwise)." )
3488
- .def_prop_ro (
3488
+ .def_prop_rw (
3489
3489
" location" ,
3490
3490
[](PyOperationBase &self) {
3491
3491
PyOperation &operation = self.getOperation ();
3492
3492
return PyLocation (operation.getContext (),
3493
3493
mlirOperationGetLocation (operation.get ()));
3494
3494
},
3495
- " Returns the source location the operation was defined or derived "
3496
- " from." )
3495
+ [](PyOperationBase &self, const PyLocation &location) {
3496
+ PyOperation &operation = self.getOperation ();
3497
+ mlirOperationSetLocation (operation.get (), location.get ());
3498
+ },
3499
+ nb::for_getter (" Returns the source location the operation was "
3500
+ " defined or derived from." ),
3501
+ nb::for_setter (" Sets the source location the operation was defined "
3502
+ " or derived from." ))
3497
3503
.def_prop_ro (" parent" ,
3498
3504
[](PyOperationBase &self)
3499
3505
-> std::optional<nb::typed<nb::object, PyOperation>> {
Original file line number Diff line number Diff line change @@ -656,6 +656,10 @@ MlirLocation mlirOperationGetLocation(MlirOperation op) {
656
656
return wrap (unwrap (op)->getLoc ());
657
657
}
658
658
659
+ void mlirOperationSetLocation (MlirOperation op, MlirLocation loc) {
660
+ unwrap (op)->setLoc (unwrap (loc));
661
+ }
662
+
659
663
MlirTypeID mlirOperationGetTypeID (MlirOperation op) {
660
664
if (auto info = unwrap (op)->getRegisteredInfo ())
661
665
return wrap (info->getTypeID ());
Original file line number Diff line number Diff line change @@ -696,6 +696,7 @@ def testOperationPrint():
696
696
# CHECK: resource1: "0x08
697
697
module .operation .print (large_elements_limit = 2 )
698
698
699
+
699
700
# CHECK-LABEL: TEST: testKnownOpView
700
701
@run
701
702
def testKnownOpView ():
@@ -969,6 +970,13 @@ def testOperationLoc():
969
970
assert op .location == loc
970
971
assert op .operation .location == loc
971
972
973
+ another_loc = Location .name ("another_loc" )
974
+ op .location = another_loc
975
+ assert op .location == another_loc
976
+ assert op .operation .location == another_loc
977
+ # CHECK: loc("another_loc")
978
+ print (op .location )
979
+
972
980
973
981
# CHECK-LABEL: TEST: testModuleMerge
974
982
@run
You can’t perform that action at this time.
0 commit comments