[Mlir-commits] [mlir] [mlir] Update prettyprinters.py to print type id correctly (#132597) (PR #132599)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Mar 23 01:13:03 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: None (CQUEE)

<details>
<summary>Changes</summary>

Fix #<!-- -->132597
In this patch, I update the python scripts utils/gdb-scripts/prettyprinters.py. Changes includes:
1. Because `mlir::detail::TypeIDExported` has been deprecated, I update it as `TypeID`
2. Function `get_type_id_printer()` can not get correct type id from template arguments, so I just parse the string, and extract the correct type id

---
Full diff: https://github.com/llvm/llvm-project/pull/132599.diff


1 Files Affected:

- (modified) mlir/utils/gdb-scripts/prettyprinters.py (+11-3) 


``````````diff
diff --git a/mlir/utils/gdb-scripts/prettyprinters.py b/mlir/utils/gdb-scripts/prettyprinters.py
index 45fd0837c9391..215d84741cf75 100644
--- a/mlir/utils/gdb-scripts/prettyprinters.py
+++ b/mlir/utils/gdb-scripts/prettyprinters.py
@@ -1,6 +1,7 @@
 """GDB pretty printers for MLIR types."""
 
 import gdb.printing
+import re
 
 
 class StoragePrinter:
@@ -68,8 +69,10 @@ def _init_map(self):
         for type_name in self.type_names:
             concrete_type = gdb.lookup_type(type_name)
             try:
+                # detail::TypeIDExported has been deprecated
+
                 storage = gdb.parse_and_eval(
-                    "&'mlir::detail::TypeIDExported::get<%s>()::instance'" % type_name
+                    "&mlir::TypeID::get<%s>()" % type_name
                 )
             except gdb.error:
                 # Skip when TypeID instance cannot be found in current context.
@@ -95,10 +98,15 @@ def __init__(self, string):
         def to_string(self):
             return self.string
 
-    concrete_type = storage_type_map[val]
+    # Extract the concrete type from the string of storage field info of TypeID.
+    concrete_type = val["storage"]
     if not concrete_type:
         return None
-    return TypeIdPrinter("mlir::TypeID::get<%s>()" % concrete_type)
+    pattern = re.compile(r'<mlir::detail::TypeIDResolver<([^,]+),')
+    match = pattern.search(str(concrete_type))
+    if match:
+        return TypeIdPrinter('mlir::TypeID::get<%s>()' % match.group(1))
+    return None
 
 
 def get_attr_or_type_printer(val, get_type_id):

``````````

</details>


https://github.com/llvm/llvm-project/pull/132599


More information about the Mlir-commits mailing list