File tree Expand file tree Collapse file tree 4 files changed +28
-0
lines changed Expand file tree Collapse file tree 4 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -357,6 +357,9 @@ MLIR_CAPI_EXPORTED bool mlirOperationEqual(MlirOperation op,
357
357
/// Gets the context this operation is associated with
358
358
MLIR_CAPI_EXPORTED MlirContext mlirOperationGetContext (MlirOperation op );
359
359
360
+ /// Gets the location of the operation.
361
+ MLIR_CAPI_EXPORTED MlirLocation mlirOperationGetLocation (MlirOperation op );
362
+
360
363
/// Gets the type id of the operation.
361
364
/// Returns null if the operation does not have a registered operation
362
365
/// description.
Original file line number Diff line number Diff line change @@ -2143,6 +2143,15 @@ void mlir::python::populateIRCore(py::module &m) {
2143
2143
},
2144
2144
" Shortcut to get an op result if it has only one (throws an error "
2145
2145
" otherwise)." )
2146
+ .def_property_readonly (
2147
+ " location" ,
2148
+ [](PyOperationBase &self) {
2149
+ PyOperation &operation = self.getOperation ();
2150
+ return PyLocation (operation.getContext (),
2151
+ mlirOperationGetLocation (operation.get ()));
2152
+ },
2153
+ " Returns the source location the operation was defined or derived "
2154
+ " from." )
2146
2155
.def (" __iter__" ,
2147
2156
[](PyOperationBase &self) {
2148
2157
return PyRegionIterator (self.getOperation ().getRef ());
Original file line number Diff line number Diff line change @@ -346,6 +346,10 @@ MlirContext mlirOperationGetContext(MlirOperation op) {
346
346
return wrap (unwrap (op)->getContext ());
347
347
}
348
348
349
+ MlirLocation mlirOperationGetLocation (MlirOperation op) {
350
+ return wrap (unwrap (op)->getLoc ());
351
+ }
352
+
349
353
MlirTypeID mlirOperationGetTypeID (MlirOperation op) {
350
354
if (const auto *abstractOp = unwrap (op)->getAbstractOperation ()) {
351
355
return wrap (abstractOp->typeID );
Original file line number Diff line number Diff line change @@ -728,3 +728,15 @@ def testOperationErase():
728
728
729
729
# Ensure we can create another operation
730
730
Operation .create ("custom.op2" )
731
+
732
+
733
+ # CHECK-LABEL: TEST: testOperationLoc
734
+ @run
735
+ def testOperationLoc ():
736
+ ctx = Context ()
737
+ ctx .allow_unregistered_dialects = True
738
+ with ctx :
739
+ loc = Location .name ("loc" )
740
+ op = Operation .create ("custom.op" , loc = loc )
741
+ assert op .location == loc
742
+ assert op .operation .location == loc
You can’t perform that action at this time.
0 commit comments