Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions mlir/lib/Bindings/Python/IRCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3977,11 +3977,13 @@ void mlir::python::populateIRCore(nb::module_ &m) {
kValueDunderStrDocstring)
.def(
"get_name",
[](PyValue &self, bool useLocalScope) {
[](PyValue &self, bool useLocalScope, bool useNameLocAsPrefix) {
PyPrintAccumulator printAccum;
MlirOpPrintingFlags flags = mlirOpPrintingFlagsCreate();
if (useLocalScope)
mlirOpPrintingFlagsUseLocalScope(flags);
if (useNameLocAsPrefix)
mlirOpPrintingFlagsPrintNameLocAsPrefix(flags);
MlirAsmState valueState =
mlirAsmStateCreateForValue(self.get(), flags);
mlirValuePrintAsOperand(self.get(), valueState,
Expand All @@ -3991,7 +3993,8 @@ void mlir::python::populateIRCore(nb::module_ &m) {
mlirAsmStateDestroy(valueState);
return printAccum.join();
},
nb::arg("use_local_scope") = false)
nb::arg("use_local_scope") = false,
nb::arg("use_name_loc_as_prefix") = false)
.def(
"get_name",
[](PyValue &self, PyAsmState &state) {
Expand Down
4 changes: 2 additions & 2 deletions mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ class Value:
Dumps a debug representation of the object to stderr.
"""
@overload
def get_name(self, use_local_scope: bool = False) -> str: ...
def get_name(self, use_local_scope: bool = False, use_name_loc_as_prefix: bool = True) -> str: ...
@overload
def get_name(self, state: AsmState) -> str:
"""
Expand Down Expand Up @@ -2382,7 +2382,7 @@ class Operation(_OperationBase):
attributes: Dict of str:Attribute.
successors: List of Block for the operation's successors.
regions: Number of regions to create.
location: A Location object (defaults to resolve from context manager).
loc: A Location object (defaults to resolve from context manager).
ip: An InsertionPoint (defaults to resolve from context manager or set to
False to disable insertion, even with an insertion point set in the
context manager).
Expand Down
22 changes: 22 additions & 0 deletions mlir/test/python/ir/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,28 @@ def testValuePrintAsOperand():
print(value2.get_name())


# CHECK-LABEL: TEST: testValuePrintAsOperandNamedLocPrefix
@run
def testValuePrintAsOperandNamedLocPrefix():
ctx = Context()
ctx.allow_unregistered_dialects = True
with Location.unknown(ctx):
i32 = IntegerType.get_signless(32)

module = Module.create()
with InsertionPoint(module.body):
named_value = Operation.create(
"custom.op5", results=[i32], loc=Location.name("apple")
).results[0]
# CHECK: Value(%[[VAL5:.*]] = "custom.op5"() : () -> i32)
print(named_value)

# CHECK: With use_name_loc_as_prefix
# CHECK: %apple
print("With use_name_loc_as_prefix")
print(named_value.get_name(use_name_loc_as_prefix=True))


# CHECK-LABEL: TEST: testValueSetType
@run
def testValueSetType():
Expand Down