[Mlir-commits] [mlir] ae4bbd0 - [MLIR][Python] Forward the name of MLIR attrs to Python side (#174756)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Jan 7 06:57:18 PST 2026


Author: Twice
Date: 2026-01-07T22:57:14+08:00
New Revision: ae4bbd0ec693c2141d55ef5b2228e7b6244ad66f

URL: https://github.com/llvm/llvm-project/commit/ae4bbd0ec693c2141d55ef5b2228e7b6244ad66f
DIFF: https://github.com/llvm/llvm-project/commit/ae4bbd0ec693c2141d55ef5b2228e7b6244ad66f.diff

LOG: [MLIR][Python] Forward the name of MLIR attrs to Python side (#174756)

This PR is quite similiar to #174700.

In this PR, I added a C API for each (upstream) MLIR attributes to
retrieve its name (for example, `StringAttr -> mlirStringAttrGetName()
-> "builtin.string"`), and exposed a corresponding type_name class
attribute in the Python bindings (e.g., `StringAttr.attr_name ->
"builtin.string"`). This can be used in various places to avoid
hard-coded strings, such as eliminating the manual string in
`irdl.base("#builtin.string")`.

Note that parts of this PR (mainly mechanical changes) were produced via
GitHub Copilot and GPT-5.2. I have manually reviewed the changes and
verified them with tests to ensure correctness.

Added: 
    

Modified: 
    mlir/include/mlir-c/BuiltinAttributes.h
    mlir/include/mlir-c/Dialect/EmitC.h
    mlir/include/mlir-c/Dialect/GPU.h
    mlir/include/mlir-c/Dialect/IRDL.h
    mlir/include/mlir-c/Dialect/LLVM.h
    mlir/include/mlir-c/Dialect/SparseTensor.h
    mlir/include/mlir/Bindings/Python/IRAttributes.h
    mlir/include/mlir/Bindings/Python/IRCore.h
    mlir/lib/Bindings/Python/DialectGPU.cpp
    mlir/lib/Bindings/Python/DialectSparseTensor.cpp
    mlir/lib/CAPI/Dialect/EmitC.cpp
    mlir/lib/CAPI/Dialect/GPU.cpp
    mlir/lib/CAPI/Dialect/IRDL.cpp
    mlir/lib/CAPI/Dialect/LLVM.cpp
    mlir/lib/CAPI/Dialect/SparseTensor.cpp
    mlir/lib/CAPI/IR/BuiltinAttributes.cpp
    mlir/test/python/ir/attributes.py

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir-c/BuiltinAttributes.h b/mlir/include/mlir-c/BuiltinAttributes.h
index 1d0edf9ea809d..17c73f44cfc74 100644
--- a/mlir/include/mlir-c/BuiltinAttributes.h
+++ b/mlir/include/mlir-c/BuiltinAttributes.h
@@ -43,6 +43,8 @@ MLIR_CAPI_EXPORTED bool mlirAttributeIsAAffineMap(MlirAttribute attr);
 /// belongs to the same context as the affine map.
 MLIR_CAPI_EXPORTED MlirAttribute mlirAffineMapAttrGet(MlirAffineMap map);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirAffineMapAttrGetName(void);
+
 /// Returns the affine map wrapped in the given affine map attribute.
 MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapAttrGetValue(MlirAttribute attr);
 
@@ -61,6 +63,8 @@ MLIR_CAPI_EXPORTED bool mlirAttributeIsAArray(MlirAttribute attr);
 MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGet(
     MlirContext ctx, intptr_t numElements, MlirAttribute const *elements);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirArrayAttrGetName(void);
+
 /// Returns the number of elements stored in the given array attribute.
 MLIR_CAPI_EXPORTED intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr);
 
@@ -83,6 +87,8 @@ MLIR_CAPI_EXPORTED bool mlirAttributeIsADictionary(MlirAttribute attr);
 MLIR_CAPI_EXPORTED MlirAttribute mlirDictionaryAttrGet(
     MlirContext ctx, intptr_t numElements, MlirNamedAttribute const *elements);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirDictionaryAttrGetName(void);
+
 /// Returns the number of attributes contained in a dictionary attribute.
 MLIR_CAPI_EXPORTED intptr_t
 mlirDictionaryAttrGetNumElements(MlirAttribute attr);
@@ -143,6 +149,8 @@ MLIR_CAPI_EXPORTED bool mlirAttributeIsAInteger(MlirAttribute attr);
 MLIR_CAPI_EXPORTED MlirAttribute mlirIntegerAttrGet(MlirType type,
                                                     int64_t value);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirIntegerAttrGetName(void);
+
 /// Returns the value stored in the given integer attribute, assuming the value
 /// is of signless type and fits into a signed 64-bit integer.
 MLIR_CAPI_EXPORTED int64_t mlirIntegerAttrGetValueInt(MlirAttribute attr);
@@ -182,6 +190,8 @@ MLIR_CAPI_EXPORTED bool mlirAttributeIsAIntegerSet(MlirAttribute attr);
 /// belongs to the same context as the integer set.
 MLIR_CAPI_EXPORTED MlirAttribute mlirIntegerSetAttrGet(MlirIntegerSet set);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirIntegerSetAttrGetName(void);
+
 /// Returns the integer set wrapped in the given integer set attribute.
 MLIR_CAPI_EXPORTED MlirIntegerSet
 mlirIntegerSetAttrGetValue(MlirAttribute attr);
@@ -203,6 +213,8 @@ MLIR_CAPI_EXPORTED MlirAttribute
 mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace,
                   intptr_t dataLength, const char *data, MlirType type);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueAttrGetName(void);
+
 /// Returns the namespace of the dialect with which the given opaque attribute
 /// is associated. The namespace string is owned by the context.
 MLIR_CAPI_EXPORTED MlirStringRef
@@ -227,6 +239,8 @@ MLIR_CAPI_EXPORTED bool mlirAttributeIsAString(MlirAttribute attr);
 MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrGet(MlirContext ctx,
                                                    MlirStringRef str);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirStringAttrGetName(void);
+
 /// Creates a string attribute in the given context containing the given string.
 /// Additionally, the attribute has the given type.
 MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrTypedGet(MlirType type,
@@ -253,6 +267,8 @@ MLIR_CAPI_EXPORTED MlirAttribute
 mlirSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol,
                      intptr_t numReferences, MlirAttribute const *references);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolRefAttrGetName(void);
+
 /// Returns the string reference to the root referenced symbol. The data remains
 /// live as long as the context in which the attribute lives.
 MLIR_CAPI_EXPORTED MlirStringRef
@@ -291,6 +307,8 @@ MLIR_CAPI_EXPORTED bool mlirAttributeIsAFlatSymbolRef(MlirAttribute attr);
 MLIR_CAPI_EXPORTED MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx,
                                                           MlirStringRef symbol);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirFlatSymbolRefAttrGetName(void);
+
 /// Returns the referenced symbol as a string reference. The data remains live
 /// as long as the context in which the attribute lives.
 MLIR_CAPI_EXPORTED MlirStringRef
@@ -307,6 +325,8 @@ MLIR_CAPI_EXPORTED bool mlirAttributeIsAType(MlirAttribute attr);
 /// type.
 MLIR_CAPI_EXPORTED MlirAttribute mlirTypeAttrGet(MlirType type);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirTypeAttrGetName(void);
+
 /// Returns the type stored in the given type attribute.
 MLIR_CAPI_EXPORTED MlirType mlirTypeAttrGetValue(MlirAttribute attr);
 
@@ -323,6 +343,8 @@ MLIR_CAPI_EXPORTED bool mlirAttributeIsAUnit(MlirAttribute attr);
 /// Creates a unit attribute in the given context.
 MLIR_CAPI_EXPORTED MlirAttribute mlirUnitAttrGet(MlirContext ctx);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirUnitAttrGetName(void);
+
 /// Returns the typeID of a Unit attribute.
 MLIR_CAPI_EXPORTED MlirTypeID mlirUnitAttrGetTypeID(void);
 
@@ -590,6 +612,8 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseResourceElementsAttrGet(
                     size_t align),
     void *userData);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirDenseResourceElementsAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseBoolResourceElementsAttrGet(
     MlirType shapedType, MlirStringRef name, intptr_t numElements,
     const int *elements);
@@ -697,6 +721,8 @@ MLIR_CAPI_EXPORTED MlirAttribute
 mlirStridedLayoutAttrGet(MlirContext ctx, int64_t offset, intptr_t numStrides,
                          const int64_t *strides);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirStridedLayoutAttrGetName(void);
+
 // Returns the offset in the given strided layout layout attribute.
 MLIR_CAPI_EXPORTED int64_t mlirStridedLayoutAttrGetOffset(MlirAttribute attr);
 

diff  --git a/mlir/include/mlir-c/Dialect/EmitC.h b/mlir/include/mlir-c/Dialect/EmitC.h
index 78e09ffe53ff8..3bd4c5e016f79 100644
--- a/mlir/include/mlir-c/Dialect/EmitC.h
+++ b/mlir/include/mlir-c/Dialect/EmitC.h
@@ -125,6 +125,8 @@ MLIR_CAPI_EXPORTED bool mlirAttributeIsAEmitCCmpPredicate(MlirAttribute attr);
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirEmitCCmpPredicateAttrGet(MlirContext ctx, enum MlirEmitCCmpPredicate val);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirEmitCCmpPredicateAttrGetName(void);
+
 MLIR_CAPI_EXPORTED enum MlirEmitCCmpPredicate
 mlirEmitCCmpPredicateAttrGetValue(MlirAttribute attr);
 
@@ -139,6 +141,8 @@ MLIR_CAPI_EXPORTED bool mlirAttributeIsAEmitCOpaque(MlirAttribute attr);
 MLIR_CAPI_EXPORTED MlirAttribute mlirEmitCOpaqueAttrGet(MlirContext ctx,
                                                         MlirStringRef value);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirEmitCOpaqueAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirStringRef
 mlirEmitCOpaqueAttrGetValue(MlirAttribute attr);
 

diff  --git a/mlir/include/mlir-c/Dialect/GPU.h b/mlir/include/mlir-c/Dialect/GPU.h
index 4e7448d427cda..f87ac9924d355 100644
--- a/mlir/include/mlir-c/Dialect/GPU.h
+++ b/mlir/include/mlir-c/Dialect/GPU.h
@@ -39,6 +39,8 @@ MLIR_CAPI_EXPORTED MlirAttribute
 mlirGPUObjectAttrGet(MlirContext mlirCtx, MlirAttribute target, uint32_t format,
                      MlirStringRef objectStrRef, MlirAttribute mlirObjectProps);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirGPUObjectAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirAttribute mlirGPUObjectAttrGetWithKernels(
     MlirContext mlirCtx, MlirAttribute target, uint32_t format,
     MlirStringRef objectStrRef, MlirAttribute mlirObjectProps,

diff  --git a/mlir/include/mlir-c/Dialect/IRDL.h b/mlir/include/mlir-c/Dialect/IRDL.h
index d87ab864fb33f..16d1bc5482262 100644
--- a/mlir/include/mlir-c/Dialect/IRDL.h
+++ b/mlir/include/mlir-c/Dialect/IRDL.h
@@ -29,6 +29,8 @@ MLIR_CAPI_EXPORTED MlirLogicalResult mlirLoadIRDLDialects(MlirModule module);
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirIRDLVariadicityAttrGet(MlirContext ctx, MlirStringRef value);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirIRDLVariadicityAttrGetName(void);
+
 //===----------------------------------------------------------------------===//
 // VariadicityArrayAttr
 //===----------------------------------------------------------------------===//
@@ -36,6 +38,8 @@ mlirIRDLVariadicityAttrGet(MlirContext ctx, MlirStringRef value);
 MLIR_CAPI_EXPORTED MlirAttribute mlirIRDLVariadicityArrayAttrGet(
     MlirContext ctx, intptr_t nValues, MlirAttribute const *values);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirIRDLVariadicityArrayAttrGetName(void);
+
 #ifdef __cplusplus
 }
 #endif

diff  --git a/mlir/include/mlir-c/Dialect/LLVM.h b/mlir/include/mlir-c/Dialect/LLVM.h
index 35f3717ad2372..8c512530d163d 100644
--- a/mlir/include/mlir-c/Dialect/LLVM.h
+++ b/mlir/include/mlir-c/Dialect/LLVM.h
@@ -188,6 +188,8 @@ typedef enum MlirLLVMCConv MlirLLVMCConv;
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx,
                                                       MlirLLVMCConv cconv);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMCConvAttrGetName(void);
+
 enum MlirLLVMComdat {
   MlirLLVMComdatAny = 0,
   MlirLLVMComdatExactMatch = 1,
@@ -201,6 +203,8 @@ typedef enum MlirLLVMComdat MlirLLVMComdat;
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx,
                                                        MlirLLVMComdat comdat);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMComdatAttrGetName(void);
+
 enum MlirLLVMLinkage {
   MlirLLVMLinkageExternal = 0,
   MlirLLVMLinkageAvailableExternally = 1,
@@ -220,18 +224,26 @@ typedef enum MlirLLVMLinkage MlirLLVMLinkage;
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirLLVMLinkageAttrGet(MlirContext ctx, MlirLLVMLinkage linkage);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMLinkageAttrGetName(void);
+
 /// Creates a LLVM DINullType attribute.
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDINullTypeAttrGetName(void);
+
 /// Creates a LLVM DIExpressionElem attribute.
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirLLVMDIExpressionElemAttrGet(MlirContext ctx, unsigned int opcode,
                                 intptr_t nArguments, uint64_t const *arguments);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIExpressionElemAttrGetName(void);
+
 /// Creates a LLVM DIExpression attribute.
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIExpressionAttrGet(
     MlirContext ctx, intptr_t nOperations, MlirAttribute const *operations);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIExpressionAttrGetName(void);
+
 enum MlirLLVMTypeEncoding {
   MlirLLVMTypeEncodingAddress = 0x1,
   MlirLLVMTypeEncodingBoolean = 0x2,
@@ -261,6 +273,8 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIBasicTypeAttrGet(
     MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits,
     MlirLLVMTypeEncoding encoding);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIBasicTypeAttrGetName(void);
+
 /// Creates a self-referencing LLVM DICompositeType attribute.
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirLLVMDICompositeTypeAttrGetRecSelf(MlirAttribute recId);
@@ -274,6 +288,8 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompositeTypeAttrGet(
     MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,
     MlirAttribute associated);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDICompositeTypeAttrGetName(void);
+
 /// Creates a LLVM DIDerivedType attribute.  Note that `dwarfAddressSpace` is an
 /// optional field, where `MLIR_CAPI_DWARF_ADDRESS_SPACE_NULL` indicates null
 /// and non-negative values indicate a value present.
@@ -282,12 +298,16 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIDerivedTypeAttrGet(
     MlirAttribute baseType, uint64_t sizeInBits, uint32_t alignInBits,
     uint64_t offsetInBits, int64_t dwarfAddressSpace, MlirAttribute extraData);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIDerivedTypeAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIStringTypeAttrGet(
     MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits,
     uint32_t alignInBits, MlirAttribute stringLength,
     MlirAttribute stringLengthExp, MlirAttribute stringLocationExp,
     MlirLLVMTypeEncoding encoding);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIStringTypeAttrGetName(void);
+
 /// Constant to represent std::nullopt for dwarfAddressSpace to omit the field.
 #define MLIR_CAPI_DWARF_ADDRESS_SPACE_NULL -1
 
@@ -300,6 +320,8 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx,
                                                        MlirAttribute name,
                                                        MlirAttribute directory);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIFileAttrGetName(void);
+
 enum MlirLLVMDIEmissionKind {
   MlirLLVMDIEmissionKindNone = 0,
   MlirLLVMDIEmissionKindFull = 1,
@@ -323,26 +345,36 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompileUnitAttrGet(
     MlirLLVMDIEmissionKind emissionKind, MlirLLVMDINameTableKind nameTableKind,
     MlirAttribute splitDebugFilename);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDICompileUnitAttrGetName(void);
+
 /// Creates a LLVM DIFlags attribute.
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx,
                                                         uint64_t value);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIFlagsAttrGetName(void);
+
 /// Creates a LLVM DILexicalBlock attribute.
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILexicalBlockAttrGet(
     MlirContext ctx, MlirAttribute scope, MlirAttribute file, unsigned int line,
     unsigned int column);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDILexicalBlockAttrGetName(void);
+
 /// Creates a LLVM DILexicalBlockFile attribute.
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(
     MlirContext ctx, MlirAttribute scope, MlirAttribute file,
     unsigned int discriminator);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDILexicalBlockFileAttrGetName(void);
+
 /// Creates a LLVM DILocalVariableAttr attribute.
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILocalVariableAttrGet(
     MlirContext ctx, MlirAttribute scope, MlirAttribute name,
     MlirAttribute diFile, unsigned int line, unsigned int arg,
     unsigned int alignInBits, MlirAttribute diType, int64_t flags);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDILocalVariableAttrGetName(void);
+
 /// Creates a self-referencing LLVM DISubprogramAttr attribute.
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId);
@@ -356,10 +388,14 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDISubprogramAttrGet(
     intptr_t nRetainedNodes, MlirAttribute const *retainedNodes,
     intptr_t nAnnotations, MlirAttribute const *annotations);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDISubprogramAttrGetName(void);
+
 /// Creates a LLVM DIAnnotation attribute.
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIAnnotationAttrGet(
     MlirContext ctx, MlirAttribute name, MlirAttribute value);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIAnnotationAttrGetName(void);
+
 /// Gets the scope from this DISubprogramAttr.
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram);
@@ -389,18 +425,24 @@ MLIR_CAPI_EXPORTED MlirAttribute
 mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx, unsigned int callingConvention,
                                 intptr_t nTypes, MlirAttribute const *types);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDISubroutineTypeAttrGetName(void);
+
 /// Creates a LLVM DIModuleAttr attribute.
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIModuleAttrGet(
     MlirContext ctx, MlirAttribute file, MlirAttribute scope,
     MlirAttribute name, MlirAttribute configMacros, MlirAttribute includePath,
     MlirAttribute apinotes, unsigned int line, bool isDecl);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIModuleAttrGetName(void);
+
 /// Creates a LLVM DIImportedEntityAttr attribute.
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIImportedEntityAttrGet(
     MlirContext ctx, unsigned int tag, MlirAttribute scope,
     MlirAttribute entity, MlirAttribute file, unsigned int line,
     MlirAttribute name, intptr_t nElements, MlirAttribute const *elements);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIImportedEntityAttrGetName(void);
+
 /// Gets the scope of this DIModuleAttr.
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule);

diff  --git a/mlir/include/mlir-c/Dialect/SparseTensor.h b/mlir/include/mlir-c/Dialect/SparseTensor.h
index c816c1b58690e..60ae49f37d653 100644
--- a/mlir/include/mlir-c/Dialect/SparseTensor.h
+++ b/mlir/include/mlir-c/Dialect/SparseTensor.h
@@ -57,6 +57,8 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGet(
     MlirAffineMap lvlTodim, int posWidth, int crdWidth,
     MlirAttribute explicitVal, MlirAttribute implicitVal);
 
+MLIR_CAPI_EXPORTED MlirStringRef mlirSparseTensorEncodingAttrGetName(void);
+
 /// Returns the level-rank of the `sparse_tensor.encoding` attribute.
 MLIR_CAPI_EXPORTED intptr_t
 mlirSparseTensorEncodingGetLvlRank(MlirAttribute attr);

diff  --git a/mlir/include/mlir/Bindings/Python/IRAttributes.h b/mlir/include/mlir/Bindings/Python/IRAttributes.h
index d64e32037664c..05d64b0d91b1b 100644
--- a/mlir/include/mlir/Bindings/Python/IRAttributes.h
+++ b/mlir/include/mlir/Bindings/Python/IRAttributes.h
@@ -77,6 +77,7 @@ class MLIR_PYTHON_API_EXPORTED PyAffineMapAttribute
   using PyConcreteAttribute::PyConcreteAttribute;
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirAffineMapAttrGetTypeID;
+  static inline const MlirStringRef name = mlirAffineMapAttrGetName();
 
   static void bindDerived(ClassTy &c);
 };
@@ -89,6 +90,7 @@ class MLIR_PYTHON_API_EXPORTED PyIntegerSetAttribute
   using PyConcreteAttribute::PyConcreteAttribute;
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirIntegerSetAttrGetTypeID;
+  static inline const MlirStringRef name = mlirIntegerSetAttrGetName();
 
   static void bindDerived(ClassTy &c);
 };
@@ -291,6 +293,7 @@ class MLIR_PYTHON_API_EXPORTED PyArrayAttribute
   using PyConcreteAttribute::PyConcreteAttribute;
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirArrayAttrGetTypeID;
+  static inline const MlirStringRef name = mlirArrayAttrGetName();
 
   class PyArrayAttributeIterator {
   public:
@@ -332,6 +335,7 @@ class MLIR_PYTHON_API_EXPORTED PyIntegerAttribute
   static constexpr IsAFunctionTy isaFunction = mlirAttributeIsAInteger;
   static constexpr const char *pyClassName = "IntegerAttr";
   using PyConcreteAttribute::PyConcreteAttribute;
+  static inline const MlirStringRef name = mlirIntegerAttrGetName();
 
   static void bindDerived(ClassTy &c);
 
@@ -356,6 +360,7 @@ class MLIR_PYTHON_API_EXPORTED PySymbolRefAttribute
   static constexpr IsAFunctionTy isaFunction = mlirAttributeIsASymbolRef;
   static constexpr const char *pyClassName = "SymbolRefAttr";
   using PyConcreteAttribute::PyConcreteAttribute;
+  static inline const MlirStringRef name = mlirSymbolRefAttrGetName();
 
   static PySymbolRefAttribute fromList(const std::vector<std::string> &symbols,
                                        PyMlirContext &context);
@@ -369,6 +374,7 @@ class MLIR_PYTHON_API_EXPORTED PyFlatSymbolRefAttribute
   static constexpr IsAFunctionTy isaFunction = mlirAttributeIsAFlatSymbolRef;
   static constexpr const char *pyClassName = "FlatSymbolRefAttr";
   using PyConcreteAttribute::PyConcreteAttribute;
+  static inline const MlirStringRef name = mlirFlatSymbolRefAttrGetName();
 
   static void bindDerived(ClassTy &c);
 };
@@ -381,6 +387,7 @@ class MLIR_PYTHON_API_EXPORTED PyOpaqueAttribute
   using PyConcreteAttribute::PyConcreteAttribute;
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirOpaqueAttrGetTypeID;
+  static inline const MlirStringRef name = mlirOpaqueAttrGetName();
 
   static void bindDerived(ClassTy &c);
 };
@@ -507,6 +514,8 @@ class MLIR_PYTHON_API_EXPORTED PyDenseResourceElementsAttribute
       mlirAttributeIsADenseResourceElements;
   static constexpr const char *pyClassName = "DenseResourceElementsAttr";
   using PyConcreteAttribute::PyConcreteAttribute;
+  static inline const MlirStringRef name =
+      mlirDenseResourceElementsAttrGetName();
 
   static PyDenseResourceElementsAttribute
   getFromBuffer(const nb_buffer &buffer, const std::string &name,
@@ -524,6 +533,7 @@ class MLIR_PYTHON_API_EXPORTED PyDictAttribute
   using PyConcreteAttribute::PyConcreteAttribute;
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirDictionaryAttrGetTypeID;
+  static inline const MlirStringRef name = mlirDictionaryAttrGetName();
 
   intptr_t dunderLen() const;
 
@@ -555,6 +565,7 @@ class MLIR_PYTHON_API_EXPORTED PyTypeAttribute
   using PyConcreteAttribute::PyConcreteAttribute;
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirTypeAttrGetTypeID;
+  static inline const MlirStringRef name = mlirTypeAttrGetName();
 
   static void bindDerived(ClassTy &c);
 };
@@ -568,6 +579,7 @@ class MLIR_PYTHON_API_EXPORTED PyUnitAttribute
   using PyConcreteAttribute::PyConcreteAttribute;
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirUnitAttrGetTypeID;
+  static inline const MlirStringRef name = mlirUnitAttrGetName();
 
   static void bindDerived(ClassTy &c);
 };
@@ -581,6 +593,7 @@ class MLIR_PYTHON_API_EXPORTED PyStridedLayoutAttribute
   using PyConcreteAttribute::PyConcreteAttribute;
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirStridedLayoutAttrGetTypeID;
+  static inline const MlirStringRef name = mlirStridedLayoutAttrGetName();
 
   static void bindDerived(ClassTy &c);
 };

diff  --git a/mlir/include/mlir/Bindings/Python/IRCore.h b/mlir/include/mlir/Bindings/Python/IRCore.h
index 729cbb6df3267..4af8420851bc1 100644
--- a/mlir/include/mlir/Bindings/Python/IRCore.h
+++ b/mlir/include/mlir/Bindings/Python/IRCore.h
@@ -1066,6 +1066,7 @@ class MLIR_PYTHON_API_EXPORTED PyConcreteAttribute : public BaseTy {
   using IsAFunctionTy = bool (*)(MlirAttribute);
   using GetTypeIDFunctionTy = MlirTypeID (*)();
   static constexpr GetTypeIDFunctionTy getTypeIdFunction = nullptr;
+  static inline const MlirStringRef name{};
   using Base = PyConcreteAttribute;
 
   PyConcreteAttribute() = default;
@@ -1136,6 +1137,12 @@ class MLIR_PYTHON_API_EXPORTED PyConcreteAttribute : public BaseTy {
           /*replace*/ true);
     }
 
+    if (DerivedTy::name.length != 0) {
+      cls.def_prop_ro_static("attr_name", [](nanobind::object & /*self*/) {
+        return nanobind::str(DerivedTy::name.data, DerivedTy::name.length);
+      });
+    }
+
     DerivedTy::bindDerived(cls);
   }
 
@@ -1151,6 +1158,7 @@ class MLIR_PYTHON_API_EXPORTED PyStringAttribute
   using PyConcreteAttribute::PyConcreteAttribute;
   static constexpr GetTypeIDFunctionTy getTypeIdFunction =
       mlirStringAttrGetTypeID;
+  static inline const MlirStringRef name = mlirStringAttrGetName();
 
   static void bindDerived(ClassTy &c);
 };

diff  --git a/mlir/lib/Bindings/Python/DialectGPU.cpp b/mlir/lib/Bindings/Python/DialectGPU.cpp
index a3af9eed48e7a..067abda53d0a8 100644
--- a/mlir/lib/Bindings/Python/DialectGPU.cpp
+++ b/mlir/lib/Bindings/Python/DialectGPU.cpp
@@ -51,6 +51,7 @@ struct AsyncTokenType : PyConcreteType<AsyncTokenType> {
 struct ObjectAttr : PyConcreteAttribute<ObjectAttr> {
   static constexpr IsAFunctionTy isaFunction = mlirAttributeIsAGPUObjectAttr;
   static constexpr const char *pyClassName = "ObjectAttr";
+  static inline const MlirStringRef name = mlirGPUObjectAttrGetName();
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {

diff  --git a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
index ad0c81ec31bb0..b8c8b58c88d0b 100644
--- a/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
+++ b/mlir/lib/Bindings/Python/DialectSparseTensor.cpp
@@ -46,6 +46,8 @@ struct EncodingAttr : PyConcreteAttribute<EncodingAttr> {
   static constexpr IsAFunctionTy isaFunction =
       mlirAttributeIsASparseTensorEncodingAttr;
   static constexpr const char *pyClassName = "EncodingAttr";
+  static inline const MlirStringRef name =
+      mlirSparseTensorEncodingAttrGetName();
   using Base::Base;
 
   static void bindDerived(ClassTy &c) {

diff  --git a/mlir/lib/CAPI/Dialect/EmitC.cpp b/mlir/lib/CAPI/Dialect/EmitC.cpp
index 285d995d6653f..941a9d07c60b1 100644
--- a/mlir/lib/CAPI/Dialect/EmitC.cpp
+++ b/mlir/lib/CAPI/Dialect/EmitC.cpp
@@ -187,6 +187,10 @@ MlirAttribute mlirEmitCCmpPredicateAttrGet(MlirContext ctx,
       unwrap(ctx), static_cast<emitc::CmpPredicate>(val)));
 }
 
+MlirStringRef mlirEmitCCmpPredicateAttrGetName(void) {
+  return wrap(emitc::CmpPredicateAttr::name);
+}
+
 MlirEmitCCmpPredicate mlirEmitCCmpPredicateAttrGetValue(MlirAttribute attr) {
   return static_cast<MlirEmitCCmpPredicate>(
       llvm::cast<emitc::CmpPredicateAttr>(unwrap(attr)).getValue());
@@ -208,6 +212,10 @@ MlirAttribute mlirEmitCOpaqueAttrGet(MlirContext ctx, MlirStringRef value) {
   return wrap((Attribute)emitc::OpaqueAttr::get(unwrap(ctx), unwrap(value)));
 }
 
+MlirStringRef mlirEmitCOpaqueAttrGetName(void) {
+  return wrap(emitc::OpaqueAttr::name);
+}
+
 MlirStringRef mlirEmitCOpaqueAttrGetValue(MlirAttribute attr) {
   return wrap(llvm::cast<emitc::OpaqueAttr>(unwrap(attr)).getValue());
 }

diff  --git a/mlir/lib/CAPI/Dialect/GPU.cpp b/mlir/lib/CAPI/Dialect/GPU.cpp
index 943ca17a57ee2..df41f3462942d 100644
--- a/mlir/lib/CAPI/Dialect/GPU.cpp
+++ b/mlir/lib/CAPI/Dialect/GPU.cpp
@@ -52,6 +52,10 @@ MlirAttribute mlirGPUObjectAttrGet(MlirContext mlirCtx, MlirAttribute target,
       StringAttr::get(ctx, object), objectProps, nullptr));
 }
 
+MlirStringRef mlirGPUObjectAttrGetName(void) {
+  return wrap(gpu::ObjectAttr::name);
+}
+
 MlirAttribute mlirGPUObjectAttrGetWithKernels(MlirContext mlirCtx,
                                               MlirAttribute target,
                                               uint32_t format,

diff  --git a/mlir/lib/CAPI/Dialect/IRDL.cpp b/mlir/lib/CAPI/Dialect/IRDL.cpp
index 43f420bf6db05..0cd65abd2c505 100644
--- a/mlir/lib/CAPI/Dialect/IRDL.cpp
+++ b/mlir/lib/CAPI/Dialect/IRDL.cpp
@@ -26,6 +26,10 @@ MlirAttribute mlirIRDLVariadicityAttrGet(MlirContext ctx, MlirStringRef value) {
       unwrap(ctx), mlir::irdl::symbolizeVariadicity(unwrap(value)).value()));
 }
 
+MlirStringRef mlirIRDLVariadicityAttrGetName(void) {
+  return wrap(mlir::irdl::VariadicityAttr::name);
+}
+
 //===----------------------------------------------------------------------===//
 // VariadicityArrayAttr
 //===----------------------------------------------------------------------===//
@@ -43,3 +47,7 @@ MlirAttribute mlirIRDLVariadicityArrayAttrGet(MlirContext ctx, intptr_t nValues,
   return wrap(
       mlir::irdl::VariadicityArrayAttr::get(unwrap(ctx), variadicities));
 }
+
+MlirStringRef mlirIRDLVariadicityArrayAttrGetName(void) {
+  return wrap(mlir::irdl::VariadicityArrayAttr::name);
+}

diff  --git a/mlir/lib/CAPI/Dialect/LLVM.cpp b/mlir/lib/CAPI/Dialect/LLVM.cpp
index 49eff0508f80d..31084f1609e90 100644
--- a/mlir/lib/CAPI/Dialect/LLVM.cpp
+++ b/mlir/lib/CAPI/Dialect/LLVM.cpp
@@ -178,6 +178,10 @@ MlirAttribute mlirLLVMDIExpressionElemAttrGet(MlirContext ctx,
   return wrap(DIExpressionElemAttr::get(unwrap(ctx), opcode, list));
 }
 
+MlirStringRef mlirLLVMDIExpressionElemAttrGetName(void) {
+  return wrap(DIExpressionElemAttr::name);
+}
+
 MlirAttribute mlirLLVMDIExpressionAttrGet(MlirContext ctx, intptr_t nOperations,
                                           MlirAttribute const *operations) {
   SmallVector<Attribute> attrStorage;
@@ -189,10 +193,18 @@ MlirAttribute mlirLLVMDIExpressionAttrGet(MlirContext ctx, intptr_t nOperations,
                           llvm::CastTo<DIExpressionElemAttr>)));
 }
 
+MlirStringRef mlirLLVMDIExpressionAttrGetName(void) {
+  return wrap(DIExpressionAttr::name);
+}
+
 MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx) {
   return wrap(DINullTypeAttr::get(unwrap(ctx)));
 }
 
+MlirStringRef mlirLLVMDINullTypeAttrGetName(void) {
+  return wrap(DINullTypeAttr::name);
+}
+
 MlirAttribute mlirLLVMDIBasicTypeAttrGet(MlirContext ctx, unsigned int tag,
                                          MlirAttribute name,
                                          uint64_t sizeInBits,
@@ -202,6 +214,10 @@ MlirAttribute mlirLLVMDIBasicTypeAttrGet(MlirContext ctx, unsigned int tag,
       unwrap(ctx), tag, cast<StringAttr>(unwrap(name)), sizeInBits, encoding));
 }
 
+MlirStringRef mlirLLVMDIBasicTypeAttrGetName(void) {
+  return wrap(DIBasicTypeAttr::name);
+}
+
 MlirAttribute mlirLLVMDICompositeTypeAttrGetRecSelf(MlirAttribute recId) {
   return wrap(
       DICompositeTypeAttr::getRecSelf(cast<DistinctAttr>(unwrap(recId))));
@@ -230,6 +246,10 @@ MlirAttribute mlirLLVMDICompositeTypeAttrGet(
                           llvm::CastTo<DINodeAttr>)));
 }
 
+MlirStringRef mlirLLVMDICompositeTypeAttrGetName(void) {
+  return wrap(DICompositeTypeAttr::name);
+}
+
 MlirAttribute mlirLLVMDIDerivedTypeAttrGet(
     MlirContext ctx, unsigned int tag, MlirAttribute name,
     MlirAttribute baseType, uint64_t sizeInBits, uint32_t alignInBits,
@@ -243,6 +263,10 @@ MlirAttribute mlirLLVMDIDerivedTypeAttrGet(
       addressSpace, cast<DINodeAttr>(unwrap(extraData))));
 }
 
+MlirStringRef mlirLLVMDIDerivedTypeAttrGetName(void) {
+  return wrap(DIDerivedTypeAttr::name);
+}
+
 MlirAttribute mlirLLVMDIStringTypeAttrGet(
     MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits,
     uint32_t alignInBits, MlirAttribute stringLength,
@@ -255,6 +279,10 @@ MlirAttribute mlirLLVMDIStringTypeAttrGet(
       cast<DIExpressionAttr>(unwrap(stringLocationExp)), encoding));
 }
 
+MlirStringRef mlirLLVMDIStringTypeAttrGetName(void) {
+  return wrap(DIStringTypeAttr::name);
+}
+
 MlirAttribute
 mlirLLVMDIDerivedTypeAttrGetBaseType(MlirAttribute diDerivedType) {
   return wrap(cast<DIDerivedTypeAttr>(unwrap(diDerivedType)).getBaseType());
@@ -264,20 +292,30 @@ MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx, MlirLLVMCConv cconv) {
   return wrap(CConvAttr::get(unwrap(ctx), CConv(cconv)));
 }
 
+MlirStringRef mlirLLVMCConvAttrGetName(void) { return wrap(CConvAttr::name); }
+
 MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx, MlirLLVMComdat comdat) {
   return wrap(ComdatAttr::get(unwrap(ctx), comdat::Comdat(comdat)));
 }
 
+MlirStringRef mlirLLVMComdatAttrGetName(void) { return wrap(ComdatAttr::name); }
+
 MlirAttribute mlirLLVMLinkageAttrGet(MlirContext ctx, MlirLLVMLinkage linkage) {
   return wrap(LinkageAttr::get(unwrap(ctx), linkage::Linkage(linkage)));
 }
 
+MlirStringRef mlirLLVMLinkageAttrGetName(void) {
+  return wrap(LinkageAttr::name);
+}
+
 MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx, MlirAttribute name,
                                     MlirAttribute directory) {
   return wrap(DIFileAttr::get(unwrap(ctx), cast<StringAttr>(unwrap(name)),
                               cast<StringAttr>(unwrap(directory))));
 }
 
+MlirStringRef mlirLLVMDIFileAttrGetName(void) { return wrap(DIFileAttr::name); }
+
 MlirAttribute mlirLLVMDICompileUnitAttrGet(
     MlirContext ctx, MlirAttribute id, unsigned int sourceLanguage,
     MlirAttribute file, MlirAttribute producer, bool isOptimized,
@@ -290,10 +328,18 @@ MlirAttribute mlirLLVMDICompileUnitAttrGet(
       cast<StringAttr>(unwrap(splitDebugFilename))));
 }
 
+MlirStringRef mlirLLVMDICompileUnitAttrGetName(void) {
+  return wrap(DICompileUnitAttr::name);
+}
+
 MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, uint64_t value) {
   return wrap(DIFlagsAttr::get(unwrap(ctx), DIFlags(value)));
 }
 
+MlirStringRef mlirLLVMDIFlagsAttrGetName(void) {
+  return wrap(DIFlagsAttr::name);
+}
+
 MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx,
                                             MlirAttribute scope,
                                             MlirAttribute file,
@@ -304,6 +350,10 @@ MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx,
                               cast<DIFileAttr>(unwrap(file)), line, column));
 }
 
+MlirStringRef mlirLLVMDILexicalBlockAttrGetName(void) {
+  return wrap(DILexicalBlockAttr::name);
+}
+
 MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx,
                                                 MlirAttribute scope,
                                                 MlirAttribute file,
@@ -313,6 +363,10 @@ MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx,
       cast<DIFileAttr>(unwrap(file)), discriminator));
 }
 
+MlirStringRef mlirLLVMDILexicalBlockFileAttrGetName(void) {
+  return wrap(DILexicalBlockFileAttr::name);
+}
+
 MlirAttribute mlirLLVMDILocalVariableAttrGet(
     MlirContext ctx, MlirAttribute scope, MlirAttribute name,
     MlirAttribute diFile, unsigned int line, unsigned int arg,
@@ -323,6 +377,10 @@ MlirAttribute mlirLLVMDILocalVariableAttrGet(
       arg, alignInBits, cast<DITypeAttr>(unwrap(diType)), DIFlags(flags)));
 }
 
+MlirStringRef mlirLLVMDILocalVariableAttrGetName(void) {
+  return wrap(DILocalVariableAttr::name);
+}
+
 MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx,
                                               unsigned int callingConvention,
                                               intptr_t nTypes,
@@ -336,6 +394,10 @@ MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx,
                           llvm::CastTo<DITypeAttr>)));
 }
 
+MlirStringRef mlirLLVMDISubroutineTypeAttrGetName(void) {
+  return wrap(DISubroutineTypeAttr::name);
+}
+
 MlirAttribute mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId) {
   return wrap(DISubprogramAttr::getRecSelf(cast<DistinctAttr>(unwrap(recId))));
 }
@@ -369,6 +431,10 @@ MlirAttribute mlirLLVMDISubprogramAttrGet(
           llvm::CastTo<DINodeAttr>)));
 }
 
+MlirStringRef mlirLLVMDISubprogramAttrGetName(void) {
+  return wrap(DISubprogramAttr::name);
+}
+
 MlirAttribute mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram) {
   return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getScope());
 }
@@ -408,6 +474,10 @@ MlirAttribute mlirLLVMDIModuleAttrGet(MlirContext ctx, MlirAttribute file,
       line, isDecl));
 }
 
+MlirStringRef mlirLLVMDIModuleAttrGetName(void) {
+  return wrap(DIModuleAttr::name);
+}
+
 MlirAttribute mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule) {
   return wrap(cast<DIModuleAttr>(unwrap(diModule)).getScope());
 }
@@ -426,8 +496,16 @@ MlirAttribute mlirLLVMDIImportedEntityAttrGet(
                           llvm::CastTo<DINodeAttr>)));
 }
 
+MlirStringRef mlirLLVMDIImportedEntityAttrGetName(void) {
+  return wrap(DIImportedEntityAttr::name);
+}
+
 MlirAttribute mlirLLVMDIAnnotationAttrGet(MlirContext ctx, MlirAttribute name,
                                           MlirAttribute value) {
   return wrap(DIAnnotationAttr::get(unwrap(ctx), cast<StringAttr>(unwrap(name)),
                                     cast<StringAttr>(unwrap(value))));
 }
+
+MlirStringRef mlirLLVMDIAnnotationAttrGetName(void) {
+  return wrap(DIAnnotationAttr::name);
+}

diff  --git a/mlir/lib/CAPI/Dialect/SparseTensor.cpp b/mlir/lib/CAPI/Dialect/SparseTensor.cpp
index cf25b5263678f..aab3b640bd9cc 100644
--- a/mlir/lib/CAPI/Dialect/SparseTensor.cpp
+++ b/mlir/lib/CAPI/Dialect/SparseTensor.cpp
@@ -62,6 +62,10 @@ MlirAttribute mlirSparseTensorEncodingAttrGet(
       crdWidth, unwrap(explicitVal), unwrap(implicitVal)));
 }
 
+MlirStringRef mlirSparseTensorEncodingAttrGetName(void) {
+  return wrap(SparseTensorEncodingAttr::name);
+}
+
 MlirAffineMap mlirSparseTensorEncodingAttrGetDimToLvl(MlirAttribute attr) {
   return wrap(cast<SparseTensorEncodingAttr>(unwrap(attr)).getDimToLvl());
 }

diff  --git a/mlir/lib/CAPI/IR/BuiltinAttributes.cpp b/mlir/lib/CAPI/IR/BuiltinAttributes.cpp
index 8d57ab6b59e79..eebf82215eab0 100644
--- a/mlir/lib/CAPI/IR/BuiltinAttributes.cpp
+++ b/mlir/lib/CAPI/IR/BuiltinAttributes.cpp
@@ -41,6 +41,10 @@ MlirAttribute mlirAffineMapAttrGet(MlirAffineMap map) {
   return wrap(AffineMapAttr::get(unwrap(map)));
 }
 
+MlirStringRef mlirAffineMapAttrGetName(void) {
+  return wrap(AffineMapAttr::name);
+}
+
 MlirAffineMap mlirAffineMapAttrGetValue(MlirAttribute attr) {
   return wrap(llvm::cast<AffineMapAttr>(unwrap(attr)).getValue());
 }
@@ -65,6 +69,8 @@ MlirAttribute mlirArrayAttrGet(MlirContext ctx, intptr_t numElements,
                                              elements, attrs)));
 }
 
+MlirStringRef mlirArrayAttrGetName(void) { return wrap(ArrayAttr::name); }
+
 intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr) {
   return static_cast<intptr_t>(llvm::cast<ArrayAttr>(unwrap(attr)).size());
 }
@@ -93,6 +99,10 @@ MlirAttribute mlirDictionaryAttrGet(MlirContext ctx, intptr_t numElements,
   return wrap(DictionaryAttr::get(unwrap(ctx), attributes));
 }
 
+MlirStringRef mlirDictionaryAttrGetName(void) {
+  return wrap(DictionaryAttr::name);
+}
+
 intptr_t mlirDictionaryAttrGetNumElements(MlirAttribute attr) {
   return static_cast<intptr_t>(llvm::cast<DictionaryAttr>(unwrap(attr)).size());
 }
@@ -149,6 +159,8 @@ MlirAttribute mlirIntegerAttrGet(MlirType type, int64_t value) {
   return wrap(IntegerAttr::get(unwrap(type), value));
 }
 
+MlirStringRef mlirIntegerAttrGetName(void) { return wrap(IntegerAttr::name); }
+
 int64_t mlirIntegerAttrGetValueInt(MlirAttribute attr) {
   return llvm::cast<IntegerAttr>(unwrap(attr)).getInt();
 }
@@ -197,6 +209,10 @@ MlirAttribute mlirIntegerSetAttrGet(MlirIntegerSet set) {
   return wrap(IntegerSetAttr::get(unwrap(set)));
 }
 
+MlirStringRef mlirIntegerSetAttrGetName(void) {
+  return wrap(IntegerSetAttr::name);
+}
+
 MlirIntegerSet mlirIntegerSetAttrGetValue(MlirAttribute attr) {
   return wrap(llvm::cast<IntegerSetAttr>(unwrap(attr)).getValue());
 }
@@ -217,6 +233,8 @@ MlirAttribute mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace,
                       StringRef(data, dataLength), unwrap(type)));
 }
 
+MlirStringRef mlirOpaqueAttrGetName(void) { return wrap(OpaqueAttr::name); }
+
 MlirStringRef mlirOpaqueAttrGetDialectNamespace(MlirAttribute attr) {
   return wrap(
       llvm::cast<OpaqueAttr>(unwrap(attr)).getDialectNamespace().strref());
@@ -242,6 +260,8 @@ MlirAttribute mlirStringAttrGet(MlirContext ctx, MlirStringRef str) {
   return wrap((Attribute)StringAttr::get(unwrap(ctx), unwrap(str)));
 }
 
+MlirStringRef mlirStringAttrGetName(void) { return wrap(StringAttr::name); }
+
 MlirAttribute mlirStringAttrTypedGet(MlirType type, MlirStringRef str) {
   return wrap((Attribute)StringAttr::get(unwrap(str), unwrap(type)));
 }
@@ -273,6 +293,10 @@ MlirAttribute mlirSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol,
   return wrap(SymbolRefAttr::get(symbolAttr, refs));
 }
 
+MlirStringRef mlirSymbolRefAttrGetName(void) {
+  return wrap(SymbolRefAttr::name);
+}
+
 MlirStringRef mlirSymbolRefAttrGetRootReference(MlirAttribute attr) {
   return wrap(
       llvm::cast<SymbolRefAttr>(unwrap(attr)).getRootReference().getValue());
@@ -314,6 +338,10 @@ MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol) {
   return wrap(FlatSymbolRefAttr::get(unwrap(ctx), unwrap(symbol)));
 }
 
+MlirStringRef mlirFlatSymbolRefAttrGetName(void) {
+  return wrap(FlatSymbolRefAttr::name);
+}
+
 MlirStringRef mlirFlatSymbolRefAttrGetValue(MlirAttribute attr) {
   return wrap(llvm::cast<FlatSymbolRefAttr>(unwrap(attr)).getValue());
 }
@@ -330,6 +358,8 @@ MlirAttribute mlirTypeAttrGet(MlirType type) {
   return wrap(TypeAttr::get(unwrap(type)));
 }
 
+MlirStringRef mlirTypeAttrGetName(void) { return wrap(TypeAttr::name); }
+
 MlirType mlirTypeAttrGetValue(MlirAttribute attr) {
   return wrap(llvm::cast<TypeAttr>(unwrap(attr)).getValue());
 }
@@ -348,6 +378,8 @@ MlirAttribute mlirUnitAttrGet(MlirContext ctx) {
   return wrap(UnitAttr::get(unwrap(ctx)));
 }
 
+MlirStringRef mlirUnitAttrGetName(void) { return wrap(UnitAttr::name); }
+
 MlirTypeID mlirUnitAttrGetTypeID(void) { return wrap(UnitAttr::getTypeID()); }
 
 //===----------------------------------------------------------------------===//
@@ -810,6 +842,10 @@ MlirAttribute mlirUnmanagedDenseResourceElementsAttrGet(
                                      unwrap(name), std::move(blob)));
 }
 
+MlirStringRef mlirDenseResourceElementsAttrGetName(void) {
+  return wrap(DenseResourceElementsAttr::name);
+}
+
 template <typename U, typename T>
 static MlirAttribute getDenseResource(MlirType shapedType, MlirStringRef name,
                                       intptr_t numElements, const T *elements) {
@@ -981,6 +1017,10 @@ MlirAttribute mlirStridedLayoutAttrGet(MlirContext ctx, int64_t offset,
                                      ArrayRef<int64_t>(strides, numStrides)));
 }
 
+MlirStringRef mlirStridedLayoutAttrGetName(void) {
+  return wrap(StridedLayoutAttr::name);
+}
+
 int64_t mlirStridedLayoutAttrGetOffset(MlirAttribute attr) {
   return llvm::cast<StridedLayoutAttr>(unwrap(attr)).getOffset();
 }

diff  --git a/mlir/test/python/ir/attributes.py b/mlir/test/python/ir/attributes.py
index 5ab671bd4d298..15a5b5ed3a81c 100644
--- a/mlir/test/python/ir/attributes.py
+++ b/mlir/test/python/ir/attributes.py
@@ -717,3 +717,33 @@ def testConcreteAttributesRoundTrip():
         print(repr(Attribute.parse("42.0 : f32")))
 
         assert IntegerAttr.static_typeid is not None
+
+
+# CHECK-LABEL: TEST: testAttrNames
+ at run
+def testAttrNames():
+    with Context():
+        # CHECK: builtin.affine_map
+        print(AffineMapAttr.attr_name)
+        # CHECK: builtin.integer_set
+        print(IntegerSetAttr.attr_name)
+        # CHECK: builtin.array
+        print(ArrayAttr.attr_name)
+        # CHECK: builtin.integer
+        print(IntegerAttr.attr_name)
+        # CHECK: builtin.symbol_ref
+        print(SymbolRefAttr.attr_name)
+        # CHECK: builtin.opaque
+        print(OpaqueAttr.attr_name)
+        # CHECK: builtin.dictionary
+        print(DictAttr.attr_name)
+        # CHECK: builtin.type
+        print(TypeAttr.attr_name)
+        # CHECK: builtin.unit
+        print(UnitAttr.attr_name)
+        # CHECK: builtin.strided_layout
+        print(StridedLayoutAttr.attr_name)
+        # CHECK: builtin.dense_resource_elements
+        print(DenseResourceElementsAttr.attr_name)
+        # CHECK: builtin.string
+        print(StringAttr.attr_name)


        


More information about the Mlir-commits mailing list