[Mlir-commits] [mlir] [MLIR][Python] Add a method to get full name of MLIR types (PR #174576)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jan 6 04:22:08 PST 2026


https://github.com/PragmaTwice updated https://github.com/llvm/llvm-project/pull/174576

>From b8251fd9e54d2dfa56f0f98f6e3de62defaf5b85 Mon Sep 17 00:00:00 2001
From: PragmaTwice <twice at apache.org>
Date: Tue, 6 Jan 2026 15:34:36 +0800
Subject: [PATCH 1/2] [MLIR][Python] Add a method to get full name of MLIR
 types

---
 mlir/include/mlir/Bindings/Python/IRCore.h    |  4 +++
 mlir/include/mlir/Bindings/Python/IRTypes.h   | 31 +++++++++++++++++++
 mlir/lib/Bindings/Python/DialectAMDGPU.cpp    |  3 ++
 mlir/lib/Bindings/Python/DialectGPU.cpp       |  1 +
 mlir/lib/Bindings/Python/DialectLLVM.cpp      |  2 ++
 mlir/lib/Bindings/Python/DialectNVGPU.cpp     |  1 +
 mlir/lib/Bindings/Python/DialectPDL.cpp       |  6 ++++
 mlir/lib/Bindings/Python/DialectQuant.cpp     |  3 ++
 mlir/lib/Bindings/Python/DialectSMT.cpp       |  3 ++
 mlir/lib/Bindings/Python/DialectTransform.cpp |  5 +++
 mlir/test/python/ir/builtin_types.py          | 24 ++++++++++++++
 .../python/lib/PythonTestModuleNanobind.cpp   |  1 +
 12 files changed, 84 insertions(+)

diff --git a/mlir/include/mlir/Bindings/Python/IRCore.h b/mlir/include/mlir/Bindings/Python/IRCore.h
index 8a8d2a1b2270f..300389c48353c 100644
--- a/mlir/include/mlir/Bindings/Python/IRCore.h
+++ b/mlir/include/mlir/Bindings/Python/IRCore.h
@@ -979,6 +979,10 @@ class MLIR_PYTHON_API_EXPORTED PyConcreteType : public BaseTy {
       printAccum.parts.append(")");
       return printAccum.join();
     });
+    cls.def_prop_ro_static("type_name", [](nanobind::object & /*cls*/) {
+      return DerivedTy::name ? nanobind::str(DerivedTy::name)
+                             : nanobind::none();
+    });
 
     if (DerivedTy::getTypeIdFunction) {
       PyGlobals::get().registerTypeCaster(
diff --git a/mlir/include/mlir/Bindings/Python/IRTypes.h b/mlir/include/mlir/Bindings/Python/IRTypes.h
index b305dec188f5a..7a355ab8d521e 100644
--- a/mlir/include/mlir/Bindings/Python/IRTypes.h
+++ b/mlir/include/mlir/Bindings/Python/IRTypes.h
@@ -10,6 +10,7 @@
 #define MLIR_BINDINGS_PYTHON_IRTYPES_H
 
 #include "mlir-c/BuiltinTypes.h"
+#include "mlir/Bindings/Python/IRCore.h"
 
 namespace mlir {
 namespace python {
@@ -24,6 +25,7 @@ class MLIR_PYTHON_API_EXPORTED PyIntegerType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirIntegerTypeGetTypeID;
   static constexpr const char *pyClassName = "IntegerType";
+  static constexpr const char *name = "builtin.integer";
   using PyConcreteType::PyConcreteType;
 
   enum Signedness { Signless, Signed, Unsigned };
@@ -39,6 +41,7 @@ class MLIR_PYTHON_API_EXPORTED PyIndexType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirIndexTypeGetTypeID;
   static constexpr const char *pyClassName = "IndexType";
+  static constexpr const char *name = "builtin.index";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -49,6 +52,7 @@ class MLIR_PYTHON_API_EXPORTED PyFloatType
 public:
   static constexpr IsAFunctionTy isaFunction = mlirTypeIsAFloat;
   static constexpr const char *pyClassName = "FloatType";
+  static constexpr const char *name = nullptr;
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -62,6 +66,7 @@ class MLIR_PYTHON_API_EXPORTED PyFloat4E2M1FNType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat4E2M1FNTypeGetTypeID;
   static constexpr const char *pyClassName = "Float4E2M1FNType";
+  static constexpr const char *name = "builtin.f4E2M1FN";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -75,6 +80,7 @@ class MLIR_PYTHON_API_EXPORTED PyFloat6E2M3FNType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat6E2M3FNTypeGetTypeID;
   static constexpr const char *pyClassName = "Float6E2M3FNType";
+  static constexpr const char *name = "builtin.f6E2M3FN";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -88,6 +94,7 @@ class MLIR_PYTHON_API_EXPORTED PyFloat6E3M2FNType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat6E3M2FNTypeGetTypeID;
   static constexpr const char *pyClassName = "Float6E3M2FNType";
+  static constexpr const char *name = "builtin.f6E3M2FN";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -101,6 +108,7 @@ class MLIR_PYTHON_API_EXPORTED PyFloat8E4M3FNType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat8E4M3FNTypeGetTypeID;
   static constexpr const char *pyClassName = "Float8E4M3FNType";
+  static constexpr const char *name = "builtin.f8E4M3FN";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -114,6 +122,7 @@ class MLIR_PYTHON_API_EXPORTED PyFloat8E5M2Type
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat8E5M2TypeGetTypeID;
   static constexpr const char *pyClassName = "Float8E5M2Type";
+  static constexpr const char *name = "builtin.f8E5M2";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -127,6 +136,7 @@ class MLIR_PYTHON_API_EXPORTED PyFloat8E4M3Type
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat8E4M3TypeGetTypeID;
   static constexpr const char *pyClassName = "Float8E4M3Type";
+  static constexpr const char *name = "builtin.f8E4M3";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -140,6 +150,7 @@ class MLIR_PYTHON_API_EXPORTED PyFloat8E4M3FNUZType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat8E4M3FNUZTypeGetTypeID;
   static constexpr const char *pyClassName = "Float8E4M3FNUZType";
+  static constexpr const char *name = "builtin.f8E4M3FNUZ";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -153,6 +164,7 @@ class MLIR_PYTHON_API_EXPORTED PyFloat8E4M3B11FNUZType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat8E4M3B11FNUZTypeGetTypeID;
   static constexpr const char *pyClassName = "Float8E4M3B11FNUZType";
+  static constexpr const char *name = "builtin.f8E4M3B11FNUZ";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -166,6 +178,7 @@ class MLIR_PYTHON_API_EXPORTED PyFloat8E5M2FNUZType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat8E5M2FNUZTypeGetTypeID;
   static constexpr const char *pyClassName = "Float8E5M2FNUZType";
+  static constexpr const char *name = "builtin.f8E5M2FNUZ";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -179,6 +192,7 @@ class MLIR_PYTHON_API_EXPORTED PyFloat8E3M4Type
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat8E3M4TypeGetTypeID;
   static constexpr const char *pyClassName = "Float8E3M4Type";
+  static constexpr const char *name = "builtin.f8E3M4";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -192,6 +206,7 @@ class MLIR_PYTHON_API_EXPORTED PyFloat8E8M0FNUType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat8E8M0FNUTypeGetTypeID;
   static constexpr const char *pyClassName = "Float8E8M0FNUType";
+  static constexpr const char *name = "builtin.f8E8M0FNU";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -205,6 +220,7 @@ class MLIR_PYTHON_API_EXPORTED PyBF16Type
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirBFloat16TypeGetTypeID;
   static constexpr const char *pyClassName = "BF16Type";
+  static constexpr const char *name = "builtin.bf16";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -218,6 +234,7 @@ class MLIR_PYTHON_API_EXPORTED PyF16Type
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat16TypeGetTypeID;
   static constexpr const char *pyClassName = "F16Type";
+  static constexpr const char *name = "builtin.f16";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -231,6 +248,7 @@ class MLIR_PYTHON_API_EXPORTED PyTF32Type
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloatTF32TypeGetTypeID;
   static constexpr const char *pyClassName = "FloatTF32Type";
+  static constexpr const char *name = "builtin.tf32";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -244,6 +262,7 @@ class MLIR_PYTHON_API_EXPORTED PyF32Type
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat32TypeGetTypeID;
   static constexpr const char *pyClassName = "F32Type";
+  static constexpr const char *name = "builtin.f32";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -257,6 +276,7 @@ class MLIR_PYTHON_API_EXPORTED PyF64Type
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFloat64TypeGetTypeID;
   static constexpr const char *pyClassName = "F64Type";
+  static constexpr const char *name = "builtin.f64";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -269,6 +289,7 @@ class MLIR_PYTHON_API_EXPORTED PyNoneType : public PyConcreteType<PyNoneType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirNoneTypeGetTypeID;
   static constexpr const char *pyClassName = "NoneType";
+  static constexpr const char *name = "builtin.none";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -282,6 +303,7 @@ class MLIR_PYTHON_API_EXPORTED PyComplexType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirComplexTypeGetTypeID;
   static constexpr const char *pyClassName = "ComplexType";
+  static constexpr const char *name = "builtin.complex";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -293,6 +315,7 @@ class MLIR_PYTHON_API_EXPORTED MLIR_PYTHON_API_EXPORTED PyShapedType
 public:
   static const IsAFunctionTy isaFunction;
   static constexpr const char *pyClassName = "ShapedType";
+  static constexpr const char *name = nullptr;
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -309,6 +332,7 @@ class MLIR_PYTHON_API_EXPORTED PyVectorType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirVectorTypeGetTypeID;
   static constexpr const char *pyClassName = "VectorType";
+  static constexpr const char *name = "builtin.vector";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -334,6 +358,7 @@ class MLIR_PYTHON_API_EXPORTED PyRankedTensorType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirRankedTensorTypeGetTypeID;
   static constexpr const char *pyClassName = "RankedTensorType";
+  static constexpr const char *name = "builtin.tensor";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -347,6 +372,7 @@ class MLIR_PYTHON_API_EXPORTED PyUnrankedTensorType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirUnrankedTensorTypeGetTypeID;
   static constexpr const char *pyClassName = "UnrankedTensorType";
+  static constexpr const char *name = "builtin.unranked_tensor";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -360,6 +386,7 @@ class MLIR_PYTHON_API_EXPORTED PyMemRefType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirMemRefTypeGetTypeID;
   static constexpr const char *pyClassName = "MemRefType";
+  static constexpr const char *name = "builtin.memref";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -373,6 +400,7 @@ class MLIR_PYTHON_API_EXPORTED PyUnrankedMemRefType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirUnrankedMemRefTypeGetTypeID;
   static constexpr const char *pyClassName = "UnrankedMemRefType";
+  static constexpr const char *name = "builtin.unranked_memref";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -386,6 +414,7 @@ class MLIR_PYTHON_API_EXPORTED PyTupleType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirTupleTypeGetTypeID;
   static constexpr const char *pyClassName = "TupleType";
+  static constexpr const char *name = "builtin.tuple";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -399,6 +428,7 @@ class MLIR_PYTHON_API_EXPORTED PyFunctionType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirFunctionTypeGetTypeID;
   static constexpr const char *pyClassName = "FunctionType";
+  static constexpr const char *name = "builtin.function";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
@@ -412,6 +442,7 @@ class MLIR_PYTHON_API_EXPORTED PyOpaqueType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirOpaqueTypeGetTypeID;
   static constexpr const char *pyClassName = "OpaqueType";
+  static constexpr const char *name = "builtin.opaque";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c);
diff --git a/mlir/lib/Bindings/Python/DialectAMDGPU.cpp b/mlir/lib/Bindings/Python/DialectAMDGPU.cpp
index 0a0cb1d158abc..9402953c6a39f 100644
--- a/mlir/lib/Bindings/Python/DialectAMDGPU.cpp
+++ b/mlir/lib/Bindings/Python/DialectAMDGPU.cpp
@@ -26,6 +26,7 @@ struct TDMBaseType : PyConcreteType<TDMBaseType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirAMDGPUTDMBaseTypeGetTypeID;
   static constexpr const char *pyClassName = "TDMBaseType";
+  static constexpr const char *name = "amdgpu.tdm_base";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -47,6 +48,7 @@ struct TDMDescriptorType : PyConcreteType<TDMDescriptorType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirAMDGPUTDMDescriptorTypeGetTypeID;
   static constexpr const char *pyClassName = "TDMDescriptorType";
+  static constexpr const char *name = "amdgpu.tdm_descriptor";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -68,6 +70,7 @@ struct TDMGatherBaseType : PyConcreteType<TDMGatherBaseType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirAMDGPUTDMGatherBaseTypeGetTypeID;
   static constexpr const char *pyClassName = "TDMGatherBaseType";
+  static constexpr const char *name = "amdgpu.tdm_gather_base";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
diff --git a/mlir/lib/Bindings/Python/DialectGPU.cpp b/mlir/lib/Bindings/Python/DialectGPU.cpp
index c2720b33ebacc..88ddb1ed89b71 100644
--- a/mlir/lib/Bindings/Python/DialectGPU.cpp
+++ b/mlir/lib/Bindings/Python/DialectGPU.cpp
@@ -29,6 +29,7 @@ namespace gpu {
 struct AsyncTokenType : PyConcreteType<AsyncTokenType> {
   static constexpr IsAFunctionTy isaFunction = mlirTypeIsAGPUAsyncTokenType;
   static constexpr const char *pyClassName = "AsyncTokenType";
+  static constexpr const char *name = "gpu.async_token";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
diff --git a/mlir/lib/Bindings/Python/DialectLLVM.cpp b/mlir/lib/Bindings/Python/DialectLLVM.cpp
index a0fec7504ab6b..dd0ce05f8fa72 100644
--- a/mlir/lib/Bindings/Python/DialectLLVM.cpp
+++ b/mlir/lib/Bindings/Python/DialectLLVM.cpp
@@ -37,6 +37,7 @@ struct StructType : PyConcreteType<StructType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirLLVMStructTypeGetTypeID;
   static constexpr const char *pyClassName = "StructType";
+  static constexpr const char *name = "llvm.struct";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -169,6 +170,7 @@ struct PointerType : PyConcreteType<PointerType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirLLVMPointerTypeGetTypeID;
   static constexpr const char *pyClassName = "PointerType";
+  static constexpr const char *name = "llvm.ptr";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
diff --git a/mlir/lib/Bindings/Python/DialectNVGPU.cpp b/mlir/lib/Bindings/Python/DialectNVGPU.cpp
index 325db6d41c460..bd88ba76e9df2 100644
--- a/mlir/lib/Bindings/Python/DialectNVGPU.cpp
+++ b/mlir/lib/Bindings/Python/DialectNVGPU.cpp
@@ -24,6 +24,7 @@ struct TensorMapDescriptorType : PyConcreteType<TensorMapDescriptorType> {
   static constexpr IsAFunctionTy isaFunction =
       mlirTypeIsANVGPUTensorMapDescriptorType;
   static constexpr const char *pyClassName = "TensorMapDescriptorType";
+  static constexpr const char *name = "nvgpu.tensormap.descriptor";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
diff --git a/mlir/lib/Bindings/Python/DialectPDL.cpp b/mlir/lib/Bindings/Python/DialectPDL.cpp
index b180aed4f8719..b95ddf49582be 100644
--- a/mlir/lib/Bindings/Python/DialectPDL.cpp
+++ b/mlir/lib/Bindings/Python/DialectPDL.cpp
@@ -28,6 +28,7 @@ namespace pdl {
 struct PDLType : PyConcreteType<PDLType> {
   static constexpr IsAFunctionTy isaFunction = mlirTypeIsAPDLType;
   static constexpr const char *pyClassName = "PDLType";
+  static constexpr const char *name = "pdl.type";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {}
@@ -42,6 +43,7 @@ struct AttributeType : PyConcreteType<AttributeType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirPDLAttributeTypeGetTypeID;
   static constexpr const char *pyClassName = "AttributeType";
+  static constexpr const char *name = "pdl.attribute";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -65,6 +67,7 @@ struct OperationType : PyConcreteType<OperationType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirPDLOperationTypeGetTypeID;
   static constexpr const char *pyClassName = "OperationType";
+  static constexpr const char *name = "pdl.operation";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -88,6 +91,7 @@ struct RangeType : PyConcreteType<RangeType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirPDLRangeTypeGetTypeID;
   static constexpr const char *pyClassName = "RangeType";
+  static constexpr const char *name = "pdl.range";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -118,6 +122,7 @@ struct TypeType : PyConcreteType<TypeType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirPDLTypeTypeGetTypeID;
   static constexpr const char *pyClassName = "TypeType";
+  static constexpr const char *name = "pdl.type";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -141,6 +146,7 @@ struct ValueType : PyConcreteType<ValueType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirPDLValueTypeGetTypeID;
   static constexpr const char *pyClassName = "ValueType";
+  static constexpr const char *name = "pdl.value";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
diff --git a/mlir/lib/Bindings/Python/DialectQuant.cpp b/mlir/lib/Bindings/Python/DialectQuant.cpp
index 2f91b5f0c1d7d..e9a65a8162efc 100644
--- a/mlir/lib/Bindings/Python/DialectQuant.cpp
+++ b/mlir/lib/Bindings/Python/DialectQuant.cpp
@@ -31,6 +31,7 @@ namespace quant {
 struct QuantizedType : PyConcreteType<QuantizedType> {
   static constexpr IsAFunctionTy isaFunction = mlirTypeIsAQuantizedType;
   static constexpr const char *pyClassName = "QuantizedType";
+  static constexpr const char *name = nullptr;
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -198,6 +199,7 @@ struct AnyQuantizedType : PyConcreteType<AnyQuantizedType, QuantizedType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirAnyQuantizedTypeGetTypeID;
   static constexpr const char *pyClassName = "AnyQuantizedType";
+  static constexpr const char *name = "quant.any";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -229,6 +231,7 @@ struct UniformQuantizedType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirUniformQuantizedTypeGetTypeID;
   static constexpr const char *pyClassName = "UniformQuantizedType";
+  static constexpr const char *name = "quant.uniform";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
diff --git a/mlir/lib/Bindings/Python/DialectSMT.cpp b/mlir/lib/Bindings/Python/DialectSMT.cpp
index f13604abb4751..f8a33c1803a7c 100644
--- a/mlir/lib/Bindings/Python/DialectSMT.cpp
+++ b/mlir/lib/Bindings/Python/DialectSMT.cpp
@@ -30,6 +30,7 @@ namespace smt {
 struct BoolType : PyConcreteType<BoolType> {
   static constexpr IsAFunctionTy isaFunction = mlirSMTTypeIsABool;
   static constexpr const char *pyClassName = "BoolType";
+  static constexpr const char *name = "smt.bool";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -46,6 +47,7 @@ struct BoolType : PyConcreteType<BoolType> {
 struct BitVectorType : PyConcreteType<BitVectorType> {
   static constexpr IsAFunctionTy isaFunction = mlirSMTTypeIsABitVector;
   static constexpr const char *pyClassName = "BitVectorType";
+  static constexpr const char *name = "smt.bv";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -63,6 +65,7 @@ struct BitVectorType : PyConcreteType<BitVectorType> {
 struct IntType : PyConcreteType<IntType> {
   static constexpr IsAFunctionTy isaFunction = mlirSMTTypeIsAInt;
   static constexpr const char *pyClassName = "IntType";
+  static constexpr const char *name = "smt.int";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
diff --git a/mlir/lib/Bindings/Python/DialectTransform.cpp b/mlir/lib/Bindings/Python/DialectTransform.cpp
index df1a0c25ae171..aae0ca72d285d 100644
--- a/mlir/lib/Bindings/Python/DialectTransform.cpp
+++ b/mlir/lib/Bindings/Python/DialectTransform.cpp
@@ -31,6 +31,7 @@ struct AnyOpType : PyConcreteType<AnyOpType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirTransformAnyOpTypeGetTypeID;
   static constexpr const char *pyClassName = "AnyOpType";
+  static constexpr const char *name = "transform.any_op";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -54,6 +55,7 @@ struct AnyParamType : PyConcreteType<AnyParamType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirTransformAnyParamTypeGetTypeID;
   static constexpr const char *pyClassName = "AnyParamType";
+  static constexpr const char *name = "transform.any_param";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -77,6 +79,7 @@ struct AnyValueType : PyConcreteType<AnyValueType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirTransformAnyValueTypeGetTypeID;
   static constexpr const char *pyClassName = "AnyValueType";
+  static constexpr const char *name = "transform.any_value";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -101,6 +104,7 @@ struct OperationType : PyConcreteType<OperationType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirTransformOperationTypeGetTypeID;
   static constexpr const char *pyClassName = "OperationType";
+  static constexpr const char *name = "transform.op";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
@@ -136,6 +140,7 @@ struct ParamType : PyConcreteType<ParamType> {
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirTransformParamTypeGetTypeID;
   static constexpr const char *pyClassName = "ParamType";
+  static constexpr const char *name = "transform.param";
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {
diff --git a/mlir/test/python/ir/builtin_types.py b/mlir/test/python/ir/builtin_types.py
index fc39ff1aa5332..1438fdcf41dd4 100644
--- a/mlir/test/python/ir/builtin_types.py
+++ b/mlir/test/python/ir/builtin_types.py
@@ -191,6 +191,30 @@ def testStandardTypeCasts():
         print("Exception not produced")
 
 
+# CHECK-LABEL: TEST: testTypeName
+ at run
+def testTypeName():
+    with Context() as ctx:
+        # CHECK: builtin.integer
+        print(IntegerType.type_name)
+        # CHECK: builtin.f32
+        print(F32Type.type_name)
+        # CHECK: builtin.f6E2M3FN
+        print(Float6E2M3FNType.type_name)
+        # CHECK: builtin.vector
+        print(VectorType.type_name)
+        # CHECK: builtin.tensor
+        print(RankedTensorType.type_name)
+        # CHECK: builtin.unranked_tensor
+        print(UnrankedTensorType.type_name)
+        # CHECK: builtin.memref
+        print(MemRefType.type_name)
+        # CHECK: builtin.unranked_memref
+        print(UnrankedMemRefType.type_name)
+        # CHECK: builtin.none
+        print(NoneType.type_name)
+
+
 # CHECK-LABEL: TEST: testIntegerType
 @run
 def testIntegerType():
diff --git a/mlir/test/python/lib/PythonTestModuleNanobind.cpp b/mlir/test/python/lib/PythonTestModuleNanobind.cpp
index a296b5e814b4b..fa97b3e4339ea 100644
--- a/mlir/test/python/lib/PythonTestModuleNanobind.cpp
+++ b/mlir/test/python/lib/PythonTestModuleNanobind.cpp
@@ -34,6 +34,7 @@ struct PyTestType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirPythonTestTestTypeGetTypeID;
   static constexpr const char *pyClassName = "TestType";
+  static constexpr const char *name = "python_test.test_type";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c) {

>From 373b8709ff0b167bb9e113a70bfd75a06dacb523 Mon Sep 17 00:00:00 2001
From: PragmaTwice <twice at apache.org>
Date: Tue, 6 Jan 2026 20:21:49 +0800
Subject: [PATCH 2/2] fix standalone

---
 mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
index 78c96e8059a8a..19c5400555694 100644
--- a/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
+++ b/mlir/examples/standalone/python/StandaloneExtensionNanobind.cpp
@@ -24,6 +24,7 @@ struct PyCustomType
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirStandaloneCustomTypeGetTypeID;
   static constexpr const char *pyClassName = "CustomType";
+  static constexpr const char *name = "standalone.custom";
   using PyConcreteType::PyConcreteType;
 
   static void bindDerived(ClassTy &c) {



More information about the Mlir-commits mailing list