[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:12:11 PDT 2025
https://github.com/CQUEE created https://github.com/llvm/llvm-project/pull/132599
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
>From e54eed476685bdca2da5ace7af2d123627d69cdd Mon Sep 17 00:00:00 2001
From: Mark <qq694104630 at gmail.com>
Date: Sun, 23 Mar 2025 15:54:23 +0800
Subject: [PATCH] [mlir] Update prettyprinters.py to print type id correctly
(#132597)
---
mlir/utils/gdb-scripts/prettyprinters.py | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
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):
More information about the Mlir-commits
mailing list