-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[mlir][python] add use_name_loc_as_prefix to value.get_name() #135052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
makslevental
merged 2 commits into
llvm:main
from
makslevental:makslevental/get-name-use-name-loc-as-prefix
Apr 9, 2025
Merged
[mlir][python] add use_name_loc_as_prefix to value.get_name() #135052
makslevental
merged 2 commits into
llvm:main
from
makslevental:makslevental/get-name-use-name-loc-as-prefix
Apr 9, 2025
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-mlir Author: Maksim Levental (makslevental) ChangesAdd Full diff: https://github.com/llvm/llvm-project/pull/135052.diff 3 Files Affected:
diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index 5ffcf671741bd..b5720b7ad8b21 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -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,
@@ -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) {
diff --git a/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi b/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
index c60ff72ff9fd4..af463cfe45d0c 100644
--- a/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
+++ b/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
@@ -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:
"""
diff --git a/mlir/test/python/ir/value.py b/mlir/test/python/ir/value.py
index 9a8146bd9350b..57a5bec7e9659 100644
--- a/mlir/test/python/ir/value.py
+++ b/mlir/test/python/ir/value.py
@@ -248,6 +248,10 @@ def testValuePrintAsOperand():
print(value4)
func.ReturnOp([])
+ named_value = Operation.create(
+ "custom.op3", results=[i32], location=Location.name("apple")
+ ).results[0]
+
# CHECK: %[[VAL1]]
print(value.get_name())
# CHECK: %[[VAL2]]
@@ -292,6 +296,9 @@ def testValuePrintAsOperand():
# CHECK: %0
print(value2.get_name())
+ # CHECK: %apple
+ print(named_value.get_name(use_name_loc_as_prefix=True))
+
# CHECK-LABEL: TEST: testValueSetType
@run
@@ -404,8 +411,7 @@ def reduction(arg0, arg1):
try:
@register_value_caster(IntegerType.static_typeid)
- def dont_cast_int_shouldnt_register(v):
- ...
+ def dont_cast_int_shouldnt_register(v): ...
except RuntimeError as e:
# CHECK: Value caster is already registered: {{.*}}cast_int
|
jpienaar
approved these changes
Apr 9, 2025
✅ With the latest revision this PR passed the Python code formatter. |
aa622fb
to
7ff48fb
Compare
7ff48fb
to
fe433a5
Compare
AllinLeeYL
pushed a commit
to AllinLeeYL/llvm-project
that referenced
this pull request
Apr 10, 2025
…35052) Add `use_name_loc_as_prefix` to `value.get_name()`.
var-const
pushed a commit
to ldionne/llvm-project
that referenced
this pull request
Apr 17, 2025
…35052) Add `use_name_loc_as_prefix` to `value.get_name()`.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add
use_name_loc_as_prefix
tovalue.get_name()
.