[Mlir-commits] [mlir] [mlir-c] expand the mlir llvm dialect C api with more attributes/enums (PR #84453)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jul 2 08:02:44 PDT 2024


https://github.com/edg-l updated https://github.com/llvm/llvm-project/pull/84453

>From 384536baab4a29b5ac685440f474419d2436dc0e Mon Sep 17 00:00:00 2001
From: Edgar Luque <git at edgarluque.com>
Date: Fri, 8 Mar 2024 11:04:51 +0100
Subject: [PATCH] [mlir-c] expand the mlir llvm dialect C api

---
 mlir/include/mlir-c/Dialect/LLVM.h | 256 ++++++++++++++++++++++++++++-
 mlir/lib/CAPI/Dialect/LLVM.cpp     | 110 ++++++++++++-
 mlir/test/CAPI/llvm.c              |  15 +-
 3 files changed, 365 insertions(+), 16 deletions(-)

diff --git a/mlir/include/mlir-c/Dialect/LLVM.h b/mlir/include/mlir-c/Dialect/LLVM.h
index d823afb659c8d..68c502b1ca6b9 100644
--- a/mlir/include/mlir-c/Dialect/LLVM.h
+++ b/mlir/include/mlir-c/Dialect/LLVM.h
@@ -227,12 +227,54 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIBasicTypeAttrGet(
     MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits,
     MlirLLVMTypeEncoding encoding);
 
+enum MlirLLVMDIFlags {
+  MlirLLVMDIFlagsZero = 0,
+  MlirLLVMDIFlagsBit0 = 1,
+  MlirLLVMDIFlagsBit1 = 2,
+  MlirLLVMDIFlagsPrivate = 1,
+  MlirLLVMDIFlagsProtected = 2,
+  MlirLLVMDIFlagsPublic = 3,
+  MlirLLVMDIFlagsFwdDecl = 4,
+  MlirLLVMDIFlagsAppleBlock = 8,
+  MlirLLVMDIFlagsReservedBit4 = 16,
+  MlirLLVMDIFlagsVirtual = 32,
+  MlirLLVMDIFlagsArtificial = 64,
+  MlirLLVMDIFlagsExplicit = 128,
+  MlirLLVMDIFlagsPrototyped = 256,
+  MlirLLVMDIFlagsObjcClassComplete = 512,
+  MlirLLVMDIFlagsObjectPointer = 1024,
+  MlirLLVMDIFlagsVector = 2048,
+  MlirLLVMDIFlagsStaticMember = 4096,
+  MlirLLVMDIFlagsLValueReference = 8192,
+  MlirLLVMDIFlagsRValueReference = 16384,
+  MlirLLVMDIFlagsExportSymbols = 32768,
+  MlirLLVMDIFlagsSingleInheritance = 65536,
+  MlirLLVMDIFlagsMultipleInheritance = 65536,
+  MlirLLVMDIFlagsVirtualInheritance = 65536,
+  MlirLLVMDIFlagsIntroducedVirtual = 262144,
+  MlirLLVMDIFlagsBitField = 524288,
+  MlirLLVMDIFlagsNoReturn = 1048576,
+  MlirLLVMDIFlagsTypePassByValue = 4194304,
+  MlirLLVMDIFlagsTypePassByReference = 8388608,
+  MlirLLVMDIFlagsEnumClass = 16777216,
+  MlirLLVMDIFlagsThunk = 33554432,
+  MlirLLVMDIFlagsNonTrivial = 67108864,
+  MlirLLVMDIFlagsBigEndian = 134217728,
+  MlirLLVMDIFlagsLittleEndian = 268435456,
+  MlirLLVMDIFlagsAllCallsDescribed = 536870912,
+};
+typedef enum MlirLLVMDIFlags MlirLLVMDIFlags;
+
+/// Creates a LLVM DIFlags attribute.
+MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx,
+                                                        MlirLLVMDIFlags value);
+
 /// Creates a LLVM DICompositeType attribute.
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompositeTypeAttrGet(
     MlirContext ctx, unsigned int tag, MlirAttribute name, MlirAttribute file,
-    uint32_t line, MlirAttribute scope, MlirAttribute baseType, int64_t flags,
-    uint64_t sizeInBits, uint64_t alignInBits, intptr_t nElements,
-    MlirAttribute const *elements);
+    uint32_t line, MlirAttribute scope, MlirAttribute baseType,
+    MlirLLVMDIFlags flags, uint64_t sizeInBits, uint64_t alignInBits,
+    intptr_t nElements, MlirAttribute const *elements);
 
 /// Creates a LLVM DIDerivedType attribute.
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIDerivedTypeAttrGet(
@@ -263,10 +305,6 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompileUnitAttrGet(
     MlirAttribute file, MlirAttribute producer, bool isOptimized,
     MlirLLVMDIEmissionKind emissionKind);
 
-/// Creates a LLVM DIFlags attribute.
-MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx,
-                                                        uint64_t value);
-
 /// Creates a LLVM DILexicalBlock attribute.
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILexicalBlockAttrGet(
     MlirContext ctx, MlirAttribute scope, MlirAttribute file, unsigned int line,
@@ -283,12 +321,33 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILocalVariableAttrGet(
     MlirAttribute diFile, unsigned int line, unsigned int arg,
     unsigned int alignInBits, MlirAttribute diType);
 
+/// Creates a LLVM DINamespaceAttr attribute.
+MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDINamespaceAttrGet(MlirContext ctx,
+                                                            MlirAttribute name,
+                                                            MlirAttribute scope,
+                                                            bool exportSymbols);
+
+enum MlirLLVMDISubprogramFlags {
+  MlirLLVMDISubprogramFlagsVirtual = 1,
+  MlirLLVMDISubprogramFlagsPureVirtual = 2,
+  MlirLLVMDISubprogramFlagsLocalToUnit = 4,
+  MlirLLVMDISubprogramFlagsDefinition = 8,
+  MlirLLVMDISubprogramFlagsOptimized = 16,
+  MlirLLVMDISubprogramFlagsPure = 32,
+  MlirLLVMDISubprogramFlagsElemental = 64,
+  MlirLLVMDISubprogramFlagsRecursive = 128,
+  MlirLLVMDISubprogramFlagsMainSubprogram = 256,
+  MlirLLVMDISubprogramFlagsDeleted = 512,
+  MlirLLVMDISubprogramFlagsObjCDirect = 2048,
+};
+typedef enum MlirLLVMDISubprogramFlags MlirLLVMDISubprogramFlags;
+
 /// Creates a LLVM DISubprogramAttr attribute.
 MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDISubprogramAttrGet(
     MlirContext ctx, MlirAttribute id, MlirAttribute compileUnit,
     MlirAttribute scope, MlirAttribute name, MlirAttribute linkageName,
     MlirAttribute file, unsigned int line, unsigned int scopeLine,
-    uint64_t subprogramFlags, MlirAttribute type);
+    MlirLLVMDISubprogramFlags subprogramFlags, MlirAttribute type);
 
 /// Gets the scope from this DISubprogramAttr.
 MLIR_CAPI_EXPORTED MlirAttribute
@@ -314,6 +373,18 @@ mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram);
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirLLVMDISubprogramAttrGetType(MlirAttribute diSubprogram);
 
+/// Gets the linkage name from this DISubprogramAttr.
+MLIR_CAPI_EXPORTED MlirIdentifier
+mlirLLVMDISubprogramAttrGetLinkageName(MlirAttribute diSubprogram);
+
+/// Gets the name from this DISubprogramAttr.
+MLIR_CAPI_EXPORTED MlirIdentifier
+mlirLLVMDISubprogramAttrGetName(MlirAttribute diSubprogram);
+
+/// Gets the subprogram flags from this DISubprogramAttr.
+MLIR_CAPI_EXPORTED MlirLLVMDISubprogramFlags
+mlirLLVMDISubprogramAttrGetSubprogramFlags(MlirAttribute diSubprogram);
+
 /// Creates a LLVM DISubroutineTypeAttr attribute.
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx, unsigned int callingConvention,
@@ -329,6 +400,175 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIModuleAttrGet(
 MLIR_CAPI_EXPORTED MlirAttribute
 mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule);
 
+/// Gets the api notes of this DIModuleAttr.
+MLIR_CAPI_EXPORTED MlirIdentifier
+mlirLLVMDIModuleAttrGetApinotes(MlirAttribute diModule);
+
+/// Gets the config macros of this DIModuleAttr.
+MLIR_CAPI_EXPORTED MlirIdentifier
+mlirLLVMDIModuleAttrGetConfigMacros(MlirAttribute diModule);
+
+/// Gets the file of this DIModuleAttr.
+MLIR_CAPI_EXPORTED MlirAttribute
+mlirLLVMDIModuleAttrGetFile(MlirAttribute diModule);
+
+/// Gets the include path of this DIModuleAttr.
+MLIR_CAPI_EXPORTED MlirIdentifier
+mlirLLVMDIModuleAttrGetIncludePath(MlirAttribute diModule);
+
+/// Gets whether this DIModuleAttr is a declaration.
+MLIR_CAPI_EXPORTED bool mlirLLVMDIModuleAttrGetIsDecl(MlirAttribute diModule);
+
+/// Creates a LLVM DISubrange attribute.
+///
+/// All parameters have the type IntegerAttr.
+MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDISubrangeAttrGet(
+    MlirContext ctx, MlirAttribute count, MlirAttribute lowerBound,
+    MlirAttribute upperBound, MlirAttribute stride);
+
+enum MlirLLVMAtomicOrdering {
+  MlirLLVMAtomicOrderingNot_atomic = 0,
+  MlirLLVMAtomicOrderingUnordered = 1,
+  MlirLLVMAtomicOrderingMonotonic = 2,
+  MlirLLVMAtomicOrderingAcquire = 4,
+  MlirLLVMAtomicOrderingRelease = 5,
+  MlirLLVMAtomicOrderingAcq_rel = 6,
+  MlirLLVMAtomicOrderingSeq_cst = 7,
+};
+typedef enum MlirLLVMAtomicOrdering MlirLLVMAtomicOrdering;
+
+/// Creates a LLVM AtomicOrderingAttr.
+MLIR_CAPI_EXPORTED MlirAttribute
+mlirLLVMAtomicOrderingAttrGet(MlirContext ctx, MlirLLVMAtomicOrdering ordering);
+
+enum MlirLLVMAtomicBinOp {
+  MlirLLVMAtomicBinOpxchg = 0,
+  MlirLLVMAtomicBinOpadd = 1,
+  MlirLLVMAtomicBinOpsub = 2,
+  MlirLLVMAtomicBinOp_and = 3,
+  MlirLLVMAtomicBinOpnand = 4,
+  MlirLLVMAtomicBinOp_or = 5,
+  MlirLLVMAtomicBinOp_xor = 6,
+  MlirLLVMAtomicBinOpmax = 7,
+  MlirLLVMAtomicBinOpmin = 8,
+  MlirLLVMAtomicBinOpumax = 9,
+  MlirLLVMAtomicBinOpumin = 10,
+  MlirLLVMAtomicBinOpfadd = 11,
+  MlirLLVMAtomicBinOpfsub = 12,
+  MlirLLVMAtomicBinOpfmax = 13,
+  MlirLLVMAtomicBinOpfmin = 14,
+  MlirLLVMAtomicBinOpuinc_wrap = 15,
+  MlirLLVMAtomicBinOpudec_wrap = 16,
+};
+typedef enum MlirLLVMAtomicBinOp MlirLLVMAtomicBinOp;
+
+/// Creates a LLVM AtomicBinOpAttr.
+MLIR_CAPI_EXPORTED MlirAttribute
+mlirLLVMAtomicBinOpAttrGet(MlirContext ctx, MlirLLVMAtomicBinOp val);
+
+enum MlirLLVMVisibility {
+  MlirLLVMVisibilityDefault = 0,
+  MlirLLVMVisibilityHidden = 1,
+  MlirLLVMVisibilityProtected = 2,
+};
+typedef enum MlirLLVMVisibility MlirLLVMVisibility;
+
+/// Creates a LLVM VisibilityAttr.
+MLIR_CAPI_EXPORTED MlirAttribute
+mlirLLVMVisibilityAttrGet(MlirContext ctx, MlirLLVMVisibility visibility);
+
+enum MlirLLVMUnnamedAddr {
+  MlirLLVMUnnamedAddrNone = 0,
+  MlirLLVMUnnamedAddrLocal = 1,
+  MlirLLVMUnnamedAddrGlobal = 2,
+};
+typedef enum MlirLLVMUnnamedAddr MlirLLVMUnnamedAddr;
+
+/// Creates a LLVM UnnamedAddrAttr.
+MLIR_CAPI_EXPORTED MlirAttribute
+mlirLLVMUnnamedAddrAttrGet(MlirContext ctx, MlirLLVMUnnamedAddr val);
+
+enum MlirLLVMICmpPredicate {
+  MlirLLVMICmpPredicateEq = 0,
+  MlirLLVMICmpPredicateNe = 1,
+  MlirLLVMICmpPredicateSlt = 2,
+  MlirLLVMICmpPredicateSle = 3,
+  MlirLLVMICmpPredicateSgt = 4,
+  MlirLLVMICmpPredicateSge = 5,
+  MlirLLVMICmpPredicateUlt = 6,
+  MlirLLVMICmpPredicateUle = 7,
+  MlirLLVMICmpPredicateUgt = 8,
+  MlirLLVMICmpPredicateUge = 9,
+};
+typedef enum MlirLLVMICmpPredicate MlirLLVMICmpPredicate;
+
+/// Creates a LLVM ICmpPredicateAttr.
+MLIR_CAPI_EXPORTED MlirAttribute
+mlirLLVMICmpPredicateAttrGet(MlirContext ctx, MlirLLVMICmpPredicate val);
+
+enum MlirLLVMFCmpPredicate {
+  MlirLLVMFCmpPredicate_false = 0,
+  MlirLLVMFCmpPredicateOeq = 1,
+  MlirLLVMFCmpPredicateOgt = 2,
+  MlirLLVMFCmpPredicateOge = 3,
+  MlirLLVMFCmpPredicateOlt = 4,
+  MlirLLVMFCmpPredicateOle = 5,
+  MlirLLVMFCmpPredicateOne = 6,
+  MlirLLVMFCmpPredicateOrd = 7,
+  MlirLLVMFCmpPredicateUeq = 8,
+  MlirLLVMFCmpPredicateUgt = 9,
+  MlirLLVMFCmpPredicateUge = 10,
+  MlirLLVMFCmpPredicateUlt = 11,
+  MlirLLVMFCmpPredicateUle = 12,
+  MlirLLVMFCmpPredicateUne = 13,
+  MlirLLVMFCmpPredicateUno = 14,
+  MlirLLVMFCmpPredicate_true = 15,
+};
+typedef enum MlirLLVMFCmpPredicate MlirLLVMFCmpPredicate;
+/// Creates a LLVM FCmpPredicateAttr.
+MLIR_CAPI_EXPORTED MlirAttribute
+mlirLLVMFCmpPredicateAttrGet(MlirContext ctx, MlirLLVMFCmpPredicate val);
+
+enum MlirLLVMFramePointerKind {
+  MlirLLVMFramePointerKindNone = 0,
+  MlirLLVMFramePointerKindNonLeaf = 1,
+  MlirLLVMFramePointerKindAll = 2,
+};
+typedef enum MlirLLVMFramePointerKind MlirLLVMFramePointerKind;
+
+/// Creates a LLVM FramePointerKindAttr.
+MLIR_CAPI_EXPORTED MlirAttribute
+mlirLLVMFramePointerKindAttrGet(MlirContext ctx, MlirLLVMFramePointerKind val);
+
+enum MlirLLVMFastmathFlags {
+  MlirLLVMFastmathFlagsNone = 0,
+  MlirLLVMFastmathFlagsNnan = 1,
+  MlirLLVMFastmathFlagsNinf = 2,
+  MlirLLVMFastmathFlagsNsz = 4,
+  MlirLLVMFastmathFlagsArcp = 8,
+  MlirLLVMFastmathFlagsContract = 16,
+  MlirLLVMFastmathFlagsAfn = 32,
+  MlirLLVMFastmathFlagsReassoc = 64,
+  MlirLLVMFastmathFlagsFast = 127,
+};
+typedef enum MlirLLVMFastmathFlags MlirLLVMFastmathFlags;
+
+/// Creates a LLVM FastmathFlagsAttr.
+MLIR_CAPI_EXPORTED MlirAttribute
+mlirLLVMFastmathFlagsAttrGet(MlirContext ctx, MlirLLVMFastmathFlags val);
+
+enum MlirLLVMModRefInfo {
+  MlirLLVMModRefInfoNoModRef = 0,
+  MlirLLVMModRefInfoRef = 1,
+  MlirLLVMModRefInfoMod = 2,
+  MlirLLVMModRefInfoModRef = 3,
+};
+typedef enum MlirLLVMModRefInfo MlirLLVMModRefInfo;
+
+/// Creates a LLVM ModRefInfoAttr.
+MLIR_CAPI_EXPORTED MlirAttribute
+mlirLLVMModRefInfoAttrGet(MlirContext ctx, MlirLLVMModRefInfo val);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/mlir/lib/CAPI/Dialect/LLVM.cpp b/mlir/lib/CAPI/Dialect/LLVM.cpp
index 2d938ce5f4834..16bf1590fea00 100644
--- a/mlir/lib/CAPI/Dialect/LLVM.cpp
+++ b/mlir/lib/CAPI/Dialect/LLVM.cpp
@@ -14,7 +14,6 @@
 #include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
-#include "llvm-c/Core.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/SmallVectorExtras.h"
 
@@ -153,9 +152,9 @@ MlirAttribute mlirLLVMDIBasicTypeAttrGet(MlirContext ctx, unsigned int tag,
 
 MlirAttribute mlirLLVMDICompositeTypeAttrGet(
     MlirContext ctx, unsigned int tag, MlirAttribute name, MlirAttribute file,
-    uint32_t line, MlirAttribute scope, MlirAttribute baseType, int64_t flags,
-    uint64_t sizeInBits, uint64_t alignInBits, intptr_t nElements,
-    MlirAttribute const *elements) {
+    uint32_t line, MlirAttribute scope, MlirAttribute baseType,
+    MlirLLVMDIFlags flags, uint64_t sizeInBits, uint64_t alignInBits,
+    intptr_t nElements, MlirAttribute const *elements) {
   SmallVector<Attribute> elementsStorage;
   elementsStorage.reserve(nElements);
 
@@ -203,6 +202,14 @@ MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx, MlirAttribute name,
                               cast<StringAttr>(unwrap(directory))));
 }
 
+MlirAttribute mlirLLVMDINamespaceAttrGet(MlirContext ctx, MlirAttribute name,
+                                         MlirAttribute scope,
+                                         bool exportSymbols) {
+  return wrap(DINamespaceAttr::get(unwrap(ctx), cast<StringAttr>(unwrap(name)),
+                                   cast<DIScopeAttr>(unwrap(scope)),
+                                   exportSymbols));
+}
+
 MlirAttribute
 mlirLLVMDICompileUnitAttrGet(MlirContext ctx, MlirAttribute id,
                              unsigned int sourceLanguage, MlirAttribute file,
@@ -214,7 +221,7 @@ mlirLLVMDICompileUnitAttrGet(MlirContext ctx, MlirAttribute id,
       isOptimized, DIEmissionKind(emissionKind)));
 }
 
-MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, uint64_t value) {
+MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, MlirLLVMDIFlags value) {
   return wrap(DIFlagsAttr::get(unwrap(ctx), DIFlags(value)));
 }
 
@@ -265,7 +272,7 @@ MlirAttribute mlirLLVMDISubprogramAttrGet(
     MlirContext ctx, MlirAttribute id, MlirAttribute compileUnit,
     MlirAttribute scope, MlirAttribute name, MlirAttribute linkageName,
     MlirAttribute file, unsigned int line, unsigned int scopeLine,
-    uint64_t subprogramFlags, MlirAttribute type) {
+    MlirLLVMDISubprogramFlags subprogramFlags, MlirAttribute type) {
   return wrap(DISubprogramAttr::get(
       unwrap(ctx), cast<DistinctAttr>(unwrap(id)),
       cast<DICompileUnitAttr>(unwrap(compileUnit)),
@@ -300,6 +307,21 @@ MlirAttribute mlirLLVMDISubprogramAttrGetType(MlirAttribute diSubprogram) {
   return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getType());
 }
 
+MlirIdentifier
+mlirLLVMDISubprogramAttrGetLinkageName(MlirAttribute diSubprogram) {
+  return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getLinkageName());
+}
+
+MlirIdentifier mlirLLVMDISubprogramAttrGetName(MlirAttribute diSubprogram) {
+  return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getName());
+}
+
+MlirLLVMDISubprogramFlags
+mlirLLVMDISubprogramAttrGetSubprogramFlags(MlirAttribute diSubprogram) {
+  return static_cast<MlirLLVMDISubprogramFlags>(
+      cast<DISubprogramAttr>(unwrap(diSubprogram)).getSubprogramFlags());
+}
+
 MlirAttribute mlirLLVMDIModuleAttrGet(MlirContext ctx, MlirAttribute file,
                                       MlirAttribute scope, MlirAttribute name,
                                       MlirAttribute configMacros,
@@ -317,3 +339,79 @@ MlirAttribute mlirLLVMDIModuleAttrGet(MlirContext ctx, MlirAttribute file,
 MlirAttribute mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule) {
   return wrap(cast<DIModuleAttr>(unwrap(diModule)).getScope());
 }
+
+MlirIdentifier mlirLLVMDIModuleAttrGetApinotes(MlirAttribute diModule) {
+  return wrap(cast<DIModuleAttr>(unwrap(diModule)).getApinotes());
+}
+
+MlirIdentifier mlirLLVMDIModuleAttrGetConfigMacros(MlirAttribute diModule) {
+  return wrap(cast<DIModuleAttr>(unwrap(diModule)).getConfigMacros());
+}
+
+MlirAttribute mlirLLVMDIModuleAttrGetFile(MlirAttribute diModule) {
+  return wrap(cast<DIModuleAttr>(unwrap(diModule)).getFile());
+}
+
+MlirIdentifier mlirLLVMDIModuleAttrGetIncludePath(MlirAttribute diModule) {
+  return wrap(cast<DIModuleAttr>(unwrap(diModule)).getIncludePath());
+}
+
+bool mlirLLVMDIModuleAttrGetIsDecl(MlirAttribute diModule) {
+  return cast<DIModuleAttr>(unwrap(diModule)).getIsDecl();
+}
+
+MlirAttribute mlirLLVMDISubrangeAttrGet(MlirContext ctx, MlirAttribute count,
+                                        MlirAttribute lowerBound,
+                                        MlirAttribute upperBound,
+                                        MlirAttribute stride) {
+  return wrap(DISubrangeAttr::get(unwrap(ctx), cast<IntegerAttr>(unwrap(count)),
+                                  cast<IntegerAttr>(unwrap(lowerBound)),
+                                  cast<IntegerAttr>(unwrap(upperBound)),
+                                  cast<IntegerAttr>(unwrap(stride))));
+}
+
+MlirAttribute mlirLLVMAtomicOrderingAttrGet(MlirContext ctx,
+                                            MlirLLVMAtomicOrdering ordering) {
+  return wrap(AtomicOrderingAttr::get(unwrap(ctx), AtomicOrdering(ordering)));
+}
+
+MlirAttribute mlirLLVMAtomicBinOpAttrGet(MlirContext ctx,
+                                         MlirLLVMAtomicBinOp val) {
+  return wrap(AtomicBinOpAttr::get(unwrap(ctx), AtomicBinOp(val)));
+}
+
+MlirAttribute mlirLLVMVisibilityAttrGet(MlirContext ctx,
+                                        MlirLLVMVisibility visibility) {
+  return wrap(VisibilityAttr::get(unwrap(ctx), Visibility(visibility)));
+}
+
+MlirAttribute mlirLLVMUnnamedAddrAttrGet(MlirContext ctx,
+                                         MlirLLVMUnnamedAddr val) {
+  return wrap(UnnamedAddrAttr::get(unwrap(ctx), UnnamedAddr(val)));
+}
+
+MlirAttribute mlirLLVMICmpPredicateAttrGet(MlirContext ctx,
+                                           MlirLLVMICmpPredicate val) {
+  return wrap(ICmpPredicateAttr::get(unwrap(ctx), ICmpPredicate(val)));
+}
+
+MlirAttribute mlirLLVMFCmpPredicateAttrGet(MlirContext ctx,
+                                           MlirLLVMFCmpPredicate val) {
+  return wrap(FCmpPredicateAttr::get(unwrap(ctx), FCmpPredicate(val)));
+}
+
+MlirAttribute mlirLLVMFramePointerKindAttrGet(MlirContext ctx,
+                                              MlirLLVMFramePointerKind val) {
+  return wrap(FramePointerKindAttr::get(
+      unwrap(ctx), framePointerKind::FramePointerKind(val)));
+}
+
+MlirAttribute mlirLLVMFastmathFlagsAttrGet(MlirContext ctx,
+                                           MlirLLVMFastmathFlags val) {
+  return wrap(FastmathFlagsAttr::get(unwrap(ctx), FastmathFlags(val)));
+}
+
+MlirAttribute mlirLLVMModRefInfoAttrGet(MlirContext ctx,
+                                        MlirLLVMModRefInfo val) {
+  return wrap(ModRefInfoAttr::get(unwrap(ctx), ModRefInfo(val)));
+}
diff --git a/mlir/test/CAPI/llvm.c b/mlir/test/CAPI/llvm.c
index 2fd98b29f487c..610f86a40426a 100644
--- a/mlir/test/CAPI/llvm.c
+++ b/mlir/test/CAPI/llvm.c
@@ -281,8 +281,8 @@ static void testDebugInfoAttributes(MlirContext ctx) {
   // CHECK: #llvm.di_compile_unit<{{.*}}>
   mlirAttributeDump(mlirLLVMDIModuleAttrGetScope(di_module));
 
-  // CHECK: 1 : i32
-  mlirAttributeDump(mlirLLVMDIFlagsAttrGet(ctx, 0x1));
+  // CHECK: 16777216 : i32
+  mlirAttributeDump(mlirLLVMDIFlagsAttrGet(ctx, MlirLLVMDIFlagsEnumClass));
 
   // CHECK: #llvm.di_lexical_block<{{.*}}>
   mlirAttributeDump(
@@ -332,6 +332,17 @@ static void testDebugInfoAttributes(MlirContext ctx) {
 
   // CHECK: #llvm.di_expression<[(1)]>
   mlirAttributeDump(mlirLLVMDIExpressionAttrGet(ctx, 1, &expression_elem));
+
+  // CHECK: #llvm.di_namespace<{{.*}}>
+  mlirAttributeDump(mlirLLVMDINamespaceAttrGet(ctx, foo, compile_unit, true));
+
+  MlirType type = mlirIntegerTypeGet(ctx, 64);
+
+  // CHECK: #llvm.di_subrange<count = 1 : i64, lowerBound = 1 : i64, upperBound
+  // CHECK-SAME: = 10 : i64, stride = 1 : i64>
+  mlirAttributeDump(mlirLLVMDISubrangeAttrGet(
+      ctx, mlirIntegerAttrGet(type, 1), mlirIntegerAttrGet(type, 1),
+      mlirIntegerAttrGet(type, 10), mlirIntegerAttrGet(type, 1)));
 }
 
 int main(void) {



More information about the Mlir-commits mailing list