Skip to content

[MLIR][Python] Forward the name of MLIR attrs to Python side#174756

Merged
PragmaTwice merged 9 commits into
llvm:mainfrom
PragmaTwice:mlir-python-attr-name
Jan 7, 2026
Merged

[MLIR][Python] Forward the name of MLIR attrs to Python side#174756
PragmaTwice merged 9 commits into
llvm:mainfrom
PragmaTwice:mlir-python-attr-name

Conversation

@PragmaTwice
Copy link
Copy Markdown
Member

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.

@PragmaTwice PragmaTwice requested a review from ftynse January 7, 2026 12:30
@PragmaTwice PragmaTwice marked this pull request as ready for review January 7, 2026 12:30
@llvmbot llvmbot added mlir:llvm mlir:python MLIR Python bindings mlir labels Jan 7, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Jan 7, 2026

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-llvm

Author: Twice (PragmaTwice)

Changes

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.


Patch is 49.70 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/174756.diff

17 Files Affected:

  • (modified) mlir/include/mlir-c/BuiltinAttributes.h (+67)
  • (modified) mlir/include/mlir-c/Dialect/EmitC.h (+4)
  • (modified) mlir/include/mlir-c/Dialect/GPU.h (+2)
  • (modified) mlir/include/mlir-c/Dialect/IRDL.h (+4)
  • (modified) mlir/include/mlir-c/Dialect/LLVM.h (+42)
  • (modified) mlir/include/mlir-c/Dialect/SparseTensor.h (+2)
  • (modified) mlir/include/mlir/Bindings/Python/IRAttributes.h (+13)
  • (modified) mlir/include/mlir/Bindings/Python/IRCore.h (+8)
  • (modified) mlir/lib/Bindings/Python/DialectGPU.cpp (+1)
  • (modified) mlir/lib/Bindings/Python/DialectSparseTensor.cpp (+2)
  • (modified) mlir/lib/CAPI/Dialect/EmitC.cpp (+8)
  • (modified) mlir/lib/CAPI/Dialect/GPU.cpp (+4)
  • (modified) mlir/lib/CAPI/Dialect/IRDL.cpp (+8)
  • (modified) mlir/lib/CAPI/Dialect/LLVM.cpp (+78)
  • (modified) mlir/lib/CAPI/Dialect/SparseTensor.cpp (+4)
  • (modified) mlir/lib/CAPI/IR/BuiltinAttributes.cpp (+95)
  • (modified) mlir/test/python/ir/attributes.py (+28)
diff --git a/mlir/include/mlir-c/BuiltinAttributes.h b/mlir/include/mlir-c/BuiltinAttributes.h
index 1d0edf9ea809d..9ca547816b84c 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,48 +612,91 @@ 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);
+
+MLIR_CAPI_EXPORTED MlirStringRef mlirDenseBoolResourceElementsAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseUInt8ResourceElementsAttrGet(
     MlirType shapedType, MlirStringRef name, intptr_t numElements,
     const uint8_t *elements);
+
+MLIR_CAPI_EXPORTED MlirStringRef
+mlirDenseUInt8ResourceElementsAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseInt8ResourceElementsAttrGet(
     MlirType shapedType, MlirStringRef name, intptr_t numElements,
     const int8_t *elements);
+
+MLIR_CAPI_EXPORTED MlirStringRef mlirDenseInt8ResourceElementsAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirUnmanagedDenseUInt16ResourceElementsAttrGet(MlirType shapedType,
                                                 MlirStringRef name,
                                                 intptr_t numElements,
                                                 const uint16_t *elements);
+
+MLIR_CAPI_EXPORTED MlirStringRef
+mlirDenseUInt16ResourceElementsAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseInt16ResourceElementsAttrGet(
     MlirType shapedType, MlirStringRef name, intptr_t numElements,
     const int16_t *elements);
+
+MLIR_CAPI_EXPORTED MlirStringRef
+mlirDenseInt16ResourceElementsAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirUnmanagedDenseUInt32ResourceElementsAttrGet(MlirType shapedType,
                                                 MlirStringRef name,
                                                 intptr_t numElements,
                                                 const uint32_t *elements);
+
+MLIR_CAPI_EXPORTED MlirStringRef
+mlirDenseUInt32ResourceElementsAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseInt32ResourceElementsAttrGet(
     MlirType shapedType, MlirStringRef name, intptr_t numElements,
     const int32_t *elements);
+
+MLIR_CAPI_EXPORTED MlirStringRef
+mlirDenseInt32ResourceElementsAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirUnmanagedDenseUInt64ResourceElementsAttrGet(MlirType shapedType,
                                                 MlirStringRef name,
                                                 intptr_t numElements,
                                                 const uint64_t *elements);
+
+MLIR_CAPI_EXPORTED MlirStringRef
+mlirDenseUInt64ResourceElementsAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseInt64ResourceElementsAttrGet(
     MlirType shapedType, MlirStringRef name, intptr_t numElements,
     const int64_t *elements);
+
+MLIR_CAPI_EXPORTED MlirStringRef
+mlirDenseInt64ResourceElementsAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseFloatResourceElementsAttrGet(
     MlirType shapedType, MlirStringRef name, intptr_t numElements,
     const float *elements);
+
+MLIR_CAPI_EXPORTED MlirStringRef
+mlirDenseFloatResourceElementsAttrGetName(void);
+
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirUnmanagedDenseDoubleResourceElementsAttrGet(MlirType shapedType,
                                                 MlirStringRef name,
                                                 intptr_t numElements,
                                                 const double *elements);
 
+MLIR_CAPI_EXPORTED MlirStringRef
+mlirDenseDoubleResourceElementsAttrGetName(void);
+
 /// Returns the pos-th value (flat contiguous indexing) of a specific type
 /// contained by the given dense resource elements attribute.
 MLIR_CAPI_EXPORTED bool
@@ -697,6 +762,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 MlirString...
[truncated]

@PragmaTwice PragmaTwice marked this pull request as draft January 7, 2026 12:33
@PragmaTwice PragmaTwice marked this pull request as ready for review January 7, 2026 12:51
@PragmaTwice
Copy link
Copy Markdown
Member Author

This PR is ready for review now : )

Copy link
Copy Markdown
Contributor

@makslevental makslevental left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@PragmaTwice
Copy link
Copy Markdown
Member Author

I'm merging it.

@PragmaTwice PragmaTwice merged commit ae4bbd0 into llvm:main Jan 7, 2026
12 checks passed
PragmaTwice added a commit that referenced this pull request Jan 10, 2026
After #174756 I found that attribute name for `FloatAttr` is missing.
And this PR is to add it.

This is actually part of changes in #169045, but I think that we can
make it a separate PR to make #169045 easier to review.
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Jan 18, 2026
After llvm#174756 I found that attribute name for `FloatAttr` is missing.
And this PR is to add it.

This is actually part of changes in llvm#169045, but I think that we can
make it a separate PR to make llvm#169045 easier to review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants