File tree Expand file tree Collapse file tree 3 files changed +29
-4
lines changed
python/mlir/_mlir_libs/_mlir Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -3977,11 +3977,13 @@ void mlir::python::populateIRCore(nb::module_ &m) {
3977
3977
kValueDunderStrDocstring )
3978
3978
.def (
3979
3979
" get_name" ,
3980
- [](PyValue &self, bool useLocalScope) {
3980
+ [](PyValue &self, bool useLocalScope, bool useNameLocAsPrefix ) {
3981
3981
PyPrintAccumulator printAccum;
3982
3982
MlirOpPrintingFlags flags = mlirOpPrintingFlagsCreate ();
3983
3983
if (useLocalScope)
3984
3984
mlirOpPrintingFlagsUseLocalScope (flags);
3985
+ if (useNameLocAsPrefix)
3986
+ mlirOpPrintingFlagsPrintNameLocAsPrefix (flags);
3985
3987
MlirAsmState valueState =
3986
3988
mlirAsmStateCreateForValue (self.get (), flags);
3987
3989
mlirValuePrintAsOperand (self.get (), valueState,
@@ -3991,7 +3993,8 @@ void mlir::python::populateIRCore(nb::module_ &m) {
3991
3993
mlirAsmStateDestroy (valueState);
3992
3994
return printAccum.join ();
3993
3995
},
3994
- nb::arg (" use_local_scope" ) = false )
3996
+ nb::arg (" use_local_scope" ) = false ,
3997
+ nb::arg (" use_name_loc_as_prefix" ) = false )
3995
3998
.def (
3996
3999
" get_name" ,
3997
4000
[](PyValue &self, PyAsmState &state) {
Original file line number Diff line number Diff line change @@ -577,7 +577,7 @@ class Value:
577
577
Dumps a debug representation of the object to stderr.
578
578
"""
579
579
@overload
580
- def get_name (self , use_local_scope : bool = False ) -> str : ...
580
+ def get_name (self , use_local_scope : bool = False , use_name_loc_as_prefix : bool = True ) -> str : ...
581
581
@overload
582
582
def get_name (self , state : AsmState ) -> str :
583
583
"""
@@ -2382,7 +2382,7 @@ class Operation(_OperationBase):
2382
2382
attributes: Dict of str:Attribute.
2383
2383
successors: List of Block for the operation's successors.
2384
2384
regions: Number of regions to create.
2385
- location : A Location object (defaults to resolve from context manager).
2385
+ loc : A Location object (defaults to resolve from context manager).
2386
2386
ip: An InsertionPoint (defaults to resolve from context manager or set to
2387
2387
False to disable insertion, even with an insertion point set in the
2388
2388
context manager).
Original file line number Diff line number Diff line change @@ -293,6 +293,28 @@ def testValuePrintAsOperand():
293
293
print (value2 .get_name ())
294
294
295
295
296
+ # CHECK-LABEL: TEST: testValuePrintAsOperandNamedLocPrefix
297
+ @run
298
+ def testValuePrintAsOperandNamedLocPrefix ():
299
+ ctx = Context ()
300
+ ctx .allow_unregistered_dialects = True
301
+ with Location .unknown (ctx ):
302
+ i32 = IntegerType .get_signless (32 )
303
+
304
+ module = Module .create ()
305
+ with InsertionPoint (module .body ):
306
+ named_value = Operation .create (
307
+ "custom.op5" , results = [i32 ], loc = Location .name ("apple" )
308
+ ).results [0 ]
309
+ # CHECK: Value(%[[VAL5:.*]] = "custom.op5"() : () -> i32)
310
+ print (named_value )
311
+
312
+ # CHECK: With use_name_loc_as_prefix
313
+ # CHECK: %apple
314
+ print ("With use_name_loc_as_prefix" )
315
+ print (named_value .get_name (use_name_loc_as_prefix = True ))
316
+
317
+
296
318
# CHECK-LABEL: TEST: testValueSetType
297
319
@run
298
320
def testValueSetType ():
You can’t perform that action at this time.
0 commit comments