File tree Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -3479,6 +3479,8 @@ void mlir::python::populateIRCore(py::module &m) {
3479
3479
3480
3480
py::class_<PyAsmState>(m, " AsmState" , py::module_local ())
3481
3481
.def (py::init<PyValue &, bool >(), py::arg (" value" ),
3482
+ py::arg (" use_local_scope" ) = false )
3483
+ .def (py::init<PyOperationBase &, bool >(), py::arg (" op" ),
3482
3484
py::arg (" use_local_scope" ) = false );
3483
3485
3484
3486
// ----------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -759,6 +759,16 @@ class PyAsmState {
759
759
mlirOpPrintingFlagsUseLocalScope (flags);
760
760
state = mlirAsmStateCreateForValue (value, flags);
761
761
}
762
+
763
+ PyAsmState (PyOperationBase &operation, bool useLocalScope) {
764
+ flags = mlirOpPrintingFlagsCreate ();
765
+ // The OpPrintingFlags are not exposed Python side, create locally and
766
+ // associate lifetime with the state.
767
+ if (useLocalScope)
768
+ mlirOpPrintingFlagsUseLocalScope (flags);
769
+ state =
770
+ mlirAsmStateCreateForOperation (operation.getOperation ().get (), flags);
771
+ }
762
772
~PyAsmState () {
763
773
mlirOpPrintingFlagsDestroy (flags);
764
774
}
Original file line number Diff line number Diff line change @@ -165,8 +165,8 @@ def testValuePrintAsOperand():
165
165
# CHECK: Value(%[[VAL2:.*]] = "custom.op2"() : () -> i32)
166
166
print (value2 )
167
167
168
- f = func .FuncOp ("test" , ([i32 , i32 ], []))
169
- entry_block1 = Block .create_at_start (f .operation .regions [0 ], [i32 , i32 ])
168
+ topFn = func .FuncOp ("test" , ([i32 , i32 ], []))
169
+ entry_block1 = Block .create_at_start (topFn .operation .regions [0 ], [i32 , i32 ])
170
170
171
171
with InsertionPoint (entry_block1 ):
172
172
value3 = Operation .create ("custom.op3" , results = [i32 ]).results [0 ]
@@ -201,7 +201,7 @@ def testValuePrintAsOperand():
201
201
202
202
print ("With AsmState" )
203
203
# CHECK-LABEL: With AsmState
204
- state = AsmState (value3 , use_local_scope = True )
204
+ state = AsmState (topFn . operation , use_local_scope = True )
205
205
# CHECK: %0
206
206
print (value3 .get_name (state = state ))
207
207
# CHECK: %1
You can’t perform that action at this time.
0 commit comments