xref: /llvm-project/mlir/lib/CAPI/Dialect/LLVM.cpp (revision 5656cbca52545e608f6fb8b7c9a778c7c9b4b468)
135d4593eSAdam Paszke //===- LLVM.cpp - C Interface for LLVM dialect ----------------------------===//
235d4593eSAdam Paszke //
335d4593eSAdam Paszke // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
435d4593eSAdam Paszke // See https://llvm.org/LICENSE.txt for license information.
535d4593eSAdam Paszke // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
635d4593eSAdam Paszke //
735d4593eSAdam Paszke //===----------------------------------------------------------------------===//
835d4593eSAdam Paszke 
935d4593eSAdam Paszke #include "mlir-c/Dialect/LLVM.h"
103714f937SEdgar #include "mlir-c/IR.h"
113714f937SEdgar #include "mlir-c/Support.h"
1235d4593eSAdam Paszke #include "mlir/CAPI/Registration.h"
133714f937SEdgar #include "mlir/CAPI/Wrap.h"
143714f937SEdgar #include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
1535d4593eSAdam Paszke #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
1635d4593eSAdam Paszke #include "mlir/Dialect/LLVMIR/LLVMTypes.h"
173714f937SEdgar #include "llvm-c/Core.h"
183714f937SEdgar #include "llvm/ADT/SmallVector.h"
193714f937SEdgar #include "llvm/ADT/SmallVectorExtras.h"
2035d4593eSAdam Paszke 
2135d4593eSAdam Paszke using namespace mlir;
2235d4593eSAdam Paszke using namespace mlir::LLVM;
2335d4593eSAdam Paszke 
2435d4593eSAdam Paszke MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(LLVM, llvm, LLVMDialect)
2535d4593eSAdam Paszke 
2646edbce4SChristian Ulmann MlirType mlirLLVMPointerTypeGet(MlirContext ctx, unsigned addressSpace) {
2746edbce4SChristian Ulmann   return wrap(LLVMPointerType::get(unwrap(ctx), addressSpace));
2835d4593eSAdam Paszke }
298a2720d8SAdam Paszke 
3079d4d165SMaksim Levental bool mlirTypeIsALLVMPointerType(MlirType type) {
3179d4d165SMaksim Levental   return isa<LLVM::LLVMPointerType>(unwrap(type));
3279d4d165SMaksim Levental }
3379d4d165SMaksim Levental 
3479d4d165SMaksim Levental unsigned mlirLLVMPointerTypeGetAddressSpace(MlirType pointerType) {
3579d4d165SMaksim Levental   return cast<LLVM::LLVMPointerType>(unwrap(pointerType)).getAddressSpace();
3679d4d165SMaksim Levental }
3779d4d165SMaksim Levental 
388a2720d8SAdam Paszke MlirType mlirLLVMVoidTypeGet(MlirContext ctx) {
398a2720d8SAdam Paszke   return wrap(LLVMVoidType::get(unwrap(ctx)));
408a2720d8SAdam Paszke }
418a2720d8SAdam Paszke 
428a2720d8SAdam Paszke MlirType mlirLLVMArrayTypeGet(MlirType elementType, unsigned numElements) {
438a2720d8SAdam Paszke   return wrap(LLVMArrayType::get(unwrap(elementType), numElements));
448a2720d8SAdam Paszke }
458a2720d8SAdam Paszke 
468345a95aSWilliam Moses MlirType mlirLLVMArrayTypeGetElementType(MlirType type) {
478345a95aSWilliam Moses   return wrap(cast<LLVM::LLVMArrayType>(unwrap(type)).getElementType());
488345a95aSWilliam Moses }
498345a95aSWilliam Moses 
508a2720d8SAdam Paszke MlirType mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes,
518a2720d8SAdam Paszke                                  MlirType const *argumentTypes, bool isVarArg) {
528a2720d8SAdam Paszke   SmallVector<Type, 2> argumentStorage;
538a2720d8SAdam Paszke   return wrap(LLVMFunctionType::get(
548a2720d8SAdam Paszke       unwrap(resultType),
558a2720d8SAdam Paszke       unwrapList(nArgumentTypes, argumentTypes, argumentStorage), isVarArg));
568a2720d8SAdam Paszke }
578a2720d8SAdam Paszke 
58*5656cbcaSWilliam Moses intptr_t mlirLLVMFunctionTypeGetNumInputs(MlirType type) {
59*5656cbcaSWilliam Moses   return llvm::cast<LLVM::LLVMFunctionType>(unwrap(type)).getNumParams();
60*5656cbcaSWilliam Moses }
61*5656cbcaSWilliam Moses 
62*5656cbcaSWilliam Moses MlirType mlirLLVMFunctionTypeGetInput(MlirType type, intptr_t pos) {
63*5656cbcaSWilliam Moses   assert(pos >= 0 && "pos in array must be positive");
64*5656cbcaSWilliam Moses   return wrap(llvm::cast<LLVM::LLVMFunctionType>(unwrap(type))
65*5656cbcaSWilliam Moses                   .getParamType(static_cast<unsigned>(pos)));
66*5656cbcaSWilliam Moses }
67*5656cbcaSWilliam Moses 
68bd8fcf75SOleksandr "Alex" Zinenko bool mlirTypeIsALLVMStructType(MlirType type) {
69bd8fcf75SOleksandr "Alex" Zinenko   return isa<LLVM::LLVMStructType>(unwrap(type));
70bd8fcf75SOleksandr "Alex" Zinenko }
71bd8fcf75SOleksandr "Alex" Zinenko 
72bd8fcf75SOleksandr "Alex" Zinenko bool mlirLLVMStructTypeIsLiteral(MlirType type) {
73bd8fcf75SOleksandr "Alex" Zinenko   return !cast<LLVM::LLVMStructType>(unwrap(type)).isIdentified();
74bd8fcf75SOleksandr "Alex" Zinenko }
75bd8fcf75SOleksandr "Alex" Zinenko 
76bd8fcf75SOleksandr "Alex" Zinenko intptr_t mlirLLVMStructTypeGetNumElementTypes(MlirType type) {
77bd8fcf75SOleksandr "Alex" Zinenko   return cast<LLVM::LLVMStructType>(unwrap(type)).getBody().size();
78bd8fcf75SOleksandr "Alex" Zinenko }
79bd8fcf75SOleksandr "Alex" Zinenko 
80bd8fcf75SOleksandr "Alex" Zinenko MlirType mlirLLVMStructTypeGetElementType(MlirType type, intptr_t position) {
81bd8fcf75SOleksandr "Alex" Zinenko   return wrap(cast<LLVM::LLVMStructType>(unwrap(type)).getBody()[position]);
82bd8fcf75SOleksandr "Alex" Zinenko }
83bd8fcf75SOleksandr "Alex" Zinenko 
84bd8fcf75SOleksandr "Alex" Zinenko bool mlirLLVMStructTypeIsPacked(MlirType type) {
85bd8fcf75SOleksandr "Alex" Zinenko   return cast<LLVM::LLVMStructType>(unwrap(type)).isPacked();
86bd8fcf75SOleksandr "Alex" Zinenko }
87bd8fcf75SOleksandr "Alex" Zinenko 
88bd8fcf75SOleksandr "Alex" Zinenko MlirStringRef mlirLLVMStructTypeGetIdentifier(MlirType type) {
89bd8fcf75SOleksandr "Alex" Zinenko   return wrap(cast<LLVM::LLVMStructType>(unwrap(type)).getName());
90bd8fcf75SOleksandr "Alex" Zinenko }
91bd8fcf75SOleksandr "Alex" Zinenko 
92bd8fcf75SOleksandr "Alex" Zinenko bool mlirLLVMStructTypeIsOpaque(MlirType type) {
93bd8fcf75SOleksandr "Alex" Zinenko   return cast<LLVM::LLVMStructType>(unwrap(type)).isOpaque();
94bd8fcf75SOleksandr "Alex" Zinenko }
95bd8fcf75SOleksandr "Alex" Zinenko 
968a2720d8SAdam Paszke MlirType mlirLLVMStructTypeLiteralGet(MlirContext ctx, intptr_t nFieldTypes,
978a2720d8SAdam Paszke                                       MlirType const *fieldTypes,
988a2720d8SAdam Paszke                                       bool isPacked) {
99bd8fcf75SOleksandr "Alex" Zinenko   SmallVector<Type> fieldStorage;
1008a2720d8SAdam Paszke   return wrap(LLVMStructType::getLiteral(
1018a2720d8SAdam Paszke       unwrap(ctx), unwrapList(nFieldTypes, fieldTypes, fieldStorage),
1028a2720d8SAdam Paszke       isPacked));
1038a2720d8SAdam Paszke }
104bd8fcf75SOleksandr "Alex" Zinenko 
105bd8fcf75SOleksandr "Alex" Zinenko MlirType mlirLLVMStructTypeLiteralGetChecked(MlirLocation loc,
106bd8fcf75SOleksandr "Alex" Zinenko                                              intptr_t nFieldTypes,
107bd8fcf75SOleksandr "Alex" Zinenko                                              MlirType const *fieldTypes,
108bd8fcf75SOleksandr "Alex" Zinenko                                              bool isPacked) {
109bd8fcf75SOleksandr "Alex" Zinenko   SmallVector<Type> fieldStorage;
110bd8fcf75SOleksandr "Alex" Zinenko   return wrap(LLVMStructType::getLiteralChecked(
111bd8fcf75SOleksandr "Alex" Zinenko       [loc]() { return emitError(unwrap(loc)); }, unwrap(loc)->getContext(),
112bd8fcf75SOleksandr "Alex" Zinenko       unwrapList(nFieldTypes, fieldTypes, fieldStorage), isPacked));
113bd8fcf75SOleksandr "Alex" Zinenko }
114bd8fcf75SOleksandr "Alex" Zinenko 
115bd8fcf75SOleksandr "Alex" Zinenko MlirType mlirLLVMStructTypeOpaqueGet(MlirContext ctx, MlirStringRef name) {
116bd8fcf75SOleksandr "Alex" Zinenko   return wrap(LLVMStructType::getOpaque(unwrap(name), unwrap(ctx)));
117bd8fcf75SOleksandr "Alex" Zinenko }
118bd8fcf75SOleksandr "Alex" Zinenko 
119bd8fcf75SOleksandr "Alex" Zinenko MlirType mlirLLVMStructTypeIdentifiedGet(MlirContext ctx, MlirStringRef name) {
120bd8fcf75SOleksandr "Alex" Zinenko   return wrap(LLVMStructType::getIdentified(unwrap(ctx), unwrap(name)));
121bd8fcf75SOleksandr "Alex" Zinenko }
122bd8fcf75SOleksandr "Alex" Zinenko 
123bd8fcf75SOleksandr "Alex" Zinenko MlirType mlirLLVMStructTypeIdentifiedNewGet(MlirContext ctx, MlirStringRef name,
124bd8fcf75SOleksandr "Alex" Zinenko                                             intptr_t nFieldTypes,
125bd8fcf75SOleksandr "Alex" Zinenko                                             MlirType const *fieldTypes,
126bd8fcf75SOleksandr "Alex" Zinenko                                             bool isPacked) {
127bd8fcf75SOleksandr "Alex" Zinenko   SmallVector<Type> fields;
128bd8fcf75SOleksandr "Alex" Zinenko   return wrap(LLVMStructType::getNewIdentified(
129bd8fcf75SOleksandr "Alex" Zinenko       unwrap(ctx), unwrap(name), unwrapList(nFieldTypes, fieldTypes, fields),
130bd8fcf75SOleksandr "Alex" Zinenko       isPacked));
131bd8fcf75SOleksandr "Alex" Zinenko }
132bd8fcf75SOleksandr "Alex" Zinenko 
133bd8fcf75SOleksandr "Alex" Zinenko MlirLogicalResult mlirLLVMStructTypeSetBody(MlirType structType,
134bd8fcf75SOleksandr "Alex" Zinenko                                             intptr_t nFieldTypes,
135bd8fcf75SOleksandr "Alex" Zinenko                                             MlirType const *fieldTypes,
136bd8fcf75SOleksandr "Alex" Zinenko                                             bool isPacked) {
137bd8fcf75SOleksandr "Alex" Zinenko   SmallVector<Type> fields;
138bd8fcf75SOleksandr "Alex" Zinenko   return wrap(
139bd8fcf75SOleksandr "Alex" Zinenko       cast<LLVM::LLVMStructType>(unwrap(structType))
140bd8fcf75SOleksandr "Alex" Zinenko           .setBody(unwrapList(nFieldTypes, fieldTypes, fields), isPacked));
141bd8fcf75SOleksandr "Alex" Zinenko }
1423714f937SEdgar 
1433714f937SEdgar MlirAttribute mlirLLVMDIExpressionElemAttrGet(MlirContext ctx,
1443714f937SEdgar                                               unsigned int opcode,
1453714f937SEdgar                                               intptr_t nArguments,
1463714f937SEdgar                                               uint64_t const *arguments) {
1473714f937SEdgar   auto list = ArrayRef<uint64_t>(arguments, nArguments);
1483714f937SEdgar   return wrap(DIExpressionElemAttr::get(unwrap(ctx), opcode, list));
1493714f937SEdgar }
1503714f937SEdgar 
1513714f937SEdgar MlirAttribute mlirLLVMDIExpressionAttrGet(MlirContext ctx, intptr_t nOperations,
1523714f937SEdgar                                           MlirAttribute const *operations) {
1533714f937SEdgar   SmallVector<Attribute> attrStorage;
1543714f937SEdgar   attrStorage.reserve(nOperations);
1553714f937SEdgar 
1563714f937SEdgar   return wrap(DIExpressionAttr::get(
1573714f937SEdgar       unwrap(ctx),
1583714f937SEdgar       llvm::map_to_vector(
1593714f937SEdgar           unwrapList(nOperations, operations, attrStorage),
160a5757c5bSChristian Sigg           [](Attribute a) { return cast<DIExpressionElemAttr>(a); })));
1613714f937SEdgar }
1623714f937SEdgar 
1633714f937SEdgar MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx) {
1643714f937SEdgar   return wrap(DINullTypeAttr::get(unwrap(ctx)));
1653714f937SEdgar }
1663714f937SEdgar 
1673714f937SEdgar MlirAttribute mlirLLVMDIBasicTypeAttrGet(MlirContext ctx, unsigned int tag,
1683714f937SEdgar                                          MlirAttribute name,
1693714f937SEdgar                                          uint64_t sizeInBits,
1703714f937SEdgar                                          MlirLLVMTypeEncoding encoding) {
1713714f937SEdgar 
1723714f937SEdgar   return wrap(DIBasicTypeAttr::get(
1733714f937SEdgar       unwrap(ctx), tag, cast<StringAttr>(unwrap(name)), sizeInBits, encoding));
1743714f937SEdgar }
1753714f937SEdgar 
17675197553STobias Gysi MlirAttribute mlirLLVMDICompositeTypeAttrGetRecSelf(MlirAttribute recId) {
17775197553STobias Gysi   return wrap(
17875197553STobias Gysi       DICompositeTypeAttr::getRecSelf(cast<DistinctAttr>(unwrap(recId))));
17975197553STobias Gysi }
18075197553STobias Gysi 
1813714f937SEdgar MlirAttribute mlirLLVMDICompositeTypeAttrGet(
18275197553STobias Gysi     MlirContext ctx, MlirAttribute recId, bool isRecSelf, unsigned int tag,
18375197553STobias Gysi     MlirAttribute name, MlirAttribute file, uint32_t line, MlirAttribute scope,
1841e8dad3bSBilly Zhu     MlirAttribute baseType, int64_t flags, uint64_t sizeInBits,
185d8038373SAbid Qadeer     uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements,
186d8038373SAbid Qadeer     MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,
187d8038373SAbid Qadeer     MlirAttribute associated) {
1883714f937SEdgar   SmallVector<Attribute> elementsStorage;
1893714f937SEdgar   elementsStorage.reserve(nElements);
1903714f937SEdgar 
1913714f937SEdgar   return wrap(DICompositeTypeAttr::get(
19275197553STobias Gysi       unwrap(ctx), cast<DistinctAttr>(unwrap(recId)), isRecSelf, tag,
1931e8dad3bSBilly Zhu       cast<StringAttr>(unwrap(name)), cast<DIFileAttr>(unwrap(file)), line,
1941e8dad3bSBilly Zhu       cast<DIScopeAttr>(unwrap(scope)), cast<DITypeAttr>(unwrap(baseType)),
1951e8dad3bSBilly Zhu       DIFlags(flags), sizeInBits, alignInBits,
1963714f937SEdgar       llvm::map_to_vector(unwrapList(nElements, elements, elementsStorage),
197d8038373SAbid Qadeer                           [](Attribute a) { return cast<DINodeAttr>(a); }),
198d8038373SAbid Qadeer       cast<DIExpressionAttr>(unwrap(dataLocation)),
199d8038373SAbid Qadeer       cast<DIExpressionAttr>(unwrap(rank)),
200d8038373SAbid Qadeer       cast<DIExpressionAttr>(unwrap(allocated)),
201d8038373SAbid Qadeer       cast<DIExpressionAttr>(unwrap(associated))));
2023714f937SEdgar }
2033714f937SEdgar 
2045c35b63dSWilliam G Hatch MlirAttribute mlirLLVMDIDerivedTypeAttrGet(
2055c35b63dSWilliam G Hatch     MlirContext ctx, unsigned int tag, MlirAttribute name,
2065c35b63dSWilliam G Hatch     MlirAttribute baseType, uint64_t sizeInBits, uint32_t alignInBits,
2075c35b63dSWilliam G Hatch     uint64_t offsetInBits, int64_t dwarfAddressSpace, MlirAttribute extraData) {
2085c35b63dSWilliam G Hatch   std::optional<unsigned> addressSpace = std::nullopt;
2095c35b63dSWilliam G Hatch   if (dwarfAddressSpace >= 0)
2105c35b63dSWilliam G Hatch     addressSpace = (unsigned)dwarfAddressSpace;
2114095a326SChristian Ulmann   return wrap(DIDerivedTypeAttr::get(
2124095a326SChristian Ulmann       unwrap(ctx), tag, cast<StringAttr>(unwrap(name)),
2134095a326SChristian Ulmann       cast<DITypeAttr>(unwrap(baseType)), sizeInBits, alignInBits, offsetInBits,
2145c35b63dSWilliam G Hatch       addressSpace, cast<DINodeAttr>(unwrap(extraData))));
2153714f937SEdgar }
2163714f937SEdgar 
2174f320e6aSAbid Qadeer MlirAttribute mlirLLVMDIStringTypeAttrGet(
2184f320e6aSAbid Qadeer     MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits,
2194f320e6aSAbid Qadeer     uint32_t alignInBits, MlirAttribute stringLength,
2204f320e6aSAbid Qadeer     MlirAttribute stringLengthExp, MlirAttribute stringLocationExp,
2214f320e6aSAbid Qadeer     MlirLLVMTypeEncoding encoding) {
2224f320e6aSAbid Qadeer   return wrap(DIStringTypeAttr::get(
2234f320e6aSAbid Qadeer       unwrap(ctx), tag, cast<StringAttr>(unwrap(name)), sizeInBits, alignInBits,
2244f320e6aSAbid Qadeer       cast<DIVariableAttr>(unwrap(stringLength)),
2254f320e6aSAbid Qadeer       cast<DIExpressionAttr>(unwrap(stringLengthExp)),
2264f320e6aSAbid Qadeer       cast<DIExpressionAttr>(unwrap(stringLocationExp)), encoding));
2274f320e6aSAbid Qadeer }
2284f320e6aSAbid Qadeer 
2293714f937SEdgar MlirAttribute
2303714f937SEdgar mlirLLVMDIDerivedTypeAttrGetBaseType(MlirAttribute diDerivedType) {
2313714f937SEdgar   return wrap(cast<DIDerivedTypeAttr>(unwrap(diDerivedType)).getBaseType());
2323714f937SEdgar }
2333714f937SEdgar 
2343714f937SEdgar MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx, MlirLLVMCConv cconv) {
2353714f937SEdgar   return wrap(CConvAttr::get(unwrap(ctx), CConv(cconv)));
2363714f937SEdgar }
2373714f937SEdgar 
2383714f937SEdgar MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx, MlirLLVMComdat comdat) {
2393714f937SEdgar   return wrap(ComdatAttr::get(unwrap(ctx), comdat::Comdat(comdat)));
2403714f937SEdgar }
2413714f937SEdgar 
2423714f937SEdgar MlirAttribute mlirLLVMLinkageAttrGet(MlirContext ctx, MlirLLVMLinkage linkage) {
2433714f937SEdgar   return wrap(LinkageAttr::get(unwrap(ctx), linkage::Linkage(linkage)));
2443714f937SEdgar }
2453714f937SEdgar 
2463714f937SEdgar MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx, MlirAttribute name,
2473714f937SEdgar                                     MlirAttribute directory) {
2483714f937SEdgar   return wrap(DIFileAttr::get(unwrap(ctx), cast<StringAttr>(unwrap(name)),
2493714f937SEdgar                               cast<StringAttr>(unwrap(directory))));
2503714f937SEdgar }
2513714f937SEdgar 
2523714f937SEdgar MlirAttribute
2533714f937SEdgar mlirLLVMDICompileUnitAttrGet(MlirContext ctx, MlirAttribute id,
2543714f937SEdgar                              unsigned int sourceLanguage, MlirAttribute file,
2553714f937SEdgar                              MlirAttribute producer, bool isOptimized,
2566f633685SBilly Zhu                              MlirLLVMDIEmissionKind emissionKind,
2576f633685SBilly Zhu                              MlirLLVMDINameTableKind nameTableKind) {
2583714f937SEdgar   return wrap(DICompileUnitAttr::get(
2593714f937SEdgar       unwrap(ctx), cast<DistinctAttr>(unwrap(id)), sourceLanguage,
2603714f937SEdgar       cast<DIFileAttr>(unwrap(file)), cast<StringAttr>(unwrap(producer)),
2616f633685SBilly Zhu       isOptimized, DIEmissionKind(emissionKind),
2626f633685SBilly Zhu       DINameTableKind(nameTableKind)));
2633714f937SEdgar }
2643714f937SEdgar 
2653714f937SEdgar MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, uint64_t value) {
2663714f937SEdgar   return wrap(DIFlagsAttr::get(unwrap(ctx), DIFlags(value)));
2673714f937SEdgar }
2683714f937SEdgar 
2693714f937SEdgar MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx,
2703714f937SEdgar                                             MlirAttribute scope,
2713714f937SEdgar                                             MlirAttribute file,
2723714f937SEdgar                                             unsigned int line,
2733714f937SEdgar                                             unsigned int column) {
2743714f937SEdgar   return wrap(
2753714f937SEdgar       DILexicalBlockAttr::get(unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
2763714f937SEdgar                               cast<DIFileAttr>(unwrap(file)), line, column));
2773714f937SEdgar }
2783714f937SEdgar 
2793714f937SEdgar MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx,
2803714f937SEdgar                                                 MlirAttribute scope,
2813714f937SEdgar                                                 MlirAttribute file,
2823714f937SEdgar                                                 unsigned int discriminator) {
2833714f937SEdgar   return wrap(DILexicalBlockFileAttr::get(
2843714f937SEdgar       unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
2853714f937SEdgar       cast<DIFileAttr>(unwrap(file)), discriminator));
2863714f937SEdgar }
2873714f937SEdgar 
288ef8de68fSWalter Erquinigo MlirAttribute mlirLLVMDILocalVariableAttrGet(
289ef8de68fSWalter Erquinigo     MlirContext ctx, MlirAttribute scope, MlirAttribute name,
290ef8de68fSWalter Erquinigo     MlirAttribute diFile, unsigned int line, unsigned int arg,
291ef8de68fSWalter Erquinigo     unsigned int alignInBits, MlirAttribute diType, int64_t flags) {
2923714f937SEdgar   return wrap(DILocalVariableAttr::get(
2933714f937SEdgar       unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
2943714f937SEdgar       cast<StringAttr>(unwrap(name)), cast<DIFileAttr>(unwrap(diFile)), line,
295ef8de68fSWalter Erquinigo       arg, alignInBits, cast<DITypeAttr>(unwrap(diType)), DIFlags(flags)));
2963714f937SEdgar }
2973714f937SEdgar 
2983714f937SEdgar MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx,
2993714f937SEdgar                                               unsigned int callingConvention,
3003714f937SEdgar                                               intptr_t nTypes,
3013714f937SEdgar                                               MlirAttribute const *types) {
3023714f937SEdgar   SmallVector<Attribute> attrStorage;
3033714f937SEdgar   attrStorage.reserve(nTypes);
3043714f937SEdgar 
3053714f937SEdgar   return wrap(DISubroutineTypeAttr::get(
3063714f937SEdgar       unwrap(ctx), callingConvention,
3073714f937SEdgar       llvm::map_to_vector(unwrapList(nTypes, types, attrStorage),
308a5757c5bSChristian Sigg                           [](Attribute a) { return cast<DITypeAttr>(a); })));
3093714f937SEdgar }
3103714f937SEdgar 
31175197553STobias Gysi MlirAttribute mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId) {
31275197553STobias Gysi   return wrap(DISubprogramAttr::getRecSelf(cast<DistinctAttr>(unwrap(recId))));
31375197553STobias Gysi }
31475197553STobias Gysi 
3153714f937SEdgar MlirAttribute mlirLLVMDISubprogramAttrGet(
31675197553STobias Gysi     MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,
31775197553STobias Gysi     MlirAttribute compileUnit, MlirAttribute scope, MlirAttribute name,
31875197553STobias Gysi     MlirAttribute linkageName, MlirAttribute file, unsigned int line,
31975197553STobias Gysi     unsigned int scopeLine, uint64_t subprogramFlags, MlirAttribute type,
3202918e779SWalter Erquinigo     intptr_t nRetainedNodes, MlirAttribute const *retainedNodes,
3212918e779SWalter Erquinigo     intptr_t nAnnotations, MlirAttribute const *annotations) {
322bc4bedd5SAbid Qadeer   SmallVector<Attribute> nodesStorage;
323bc4bedd5SAbid Qadeer   nodesStorage.reserve(nRetainedNodes);
3242918e779SWalter Erquinigo 
3252918e779SWalter Erquinigo   SmallVector<Attribute> annotationsStorage;
3262918e779SWalter Erquinigo   annotationsStorage.reserve(nAnnotations);
3272918e779SWalter Erquinigo 
3283714f937SEdgar   return wrap(DISubprogramAttr::get(
32975197553STobias Gysi       unwrap(ctx), cast<DistinctAttr>(unwrap(recId)), isRecSelf,
33075197553STobias Gysi       cast<DistinctAttr>(unwrap(id)),
3313714f937SEdgar       cast<DICompileUnitAttr>(unwrap(compileUnit)),
3323714f937SEdgar       cast<DIScopeAttr>(unwrap(scope)), cast<StringAttr>(unwrap(name)),
3333714f937SEdgar       cast<StringAttr>(unwrap(linkageName)), cast<DIFileAttr>(unwrap(file)),
3343714f937SEdgar       line, scopeLine, DISubprogramFlags(subprogramFlags),
335bc4bedd5SAbid Qadeer       cast<DISubroutineTypeAttr>(unwrap(type)),
336bc4bedd5SAbid Qadeer       llvm::map_to_vector(
337bc4bedd5SAbid Qadeer           unwrapList(nRetainedNodes, retainedNodes, nodesStorage),
3382918e779SWalter Erquinigo           [](Attribute a) { return cast<DINodeAttr>(a); }),
3392918e779SWalter Erquinigo       llvm::map_to_vector(
3402918e779SWalter Erquinigo           unwrapList(nAnnotations, annotations, annotationsStorage),
341bc4bedd5SAbid Qadeer           [](Attribute a) { return cast<DINodeAttr>(a); })));
3423714f937SEdgar }
3433714f937SEdgar 
3443714f937SEdgar MlirAttribute mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram) {
3453714f937SEdgar   return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getScope());
3463714f937SEdgar }
3473714f937SEdgar 
3483714f937SEdgar unsigned int mlirLLVMDISubprogramAttrGetLine(MlirAttribute diSubprogram) {
3493714f937SEdgar   return cast<DISubprogramAttr>(unwrap(diSubprogram)).getLine();
3503714f937SEdgar }
3513714f937SEdgar 
3523714f937SEdgar unsigned int mlirLLVMDISubprogramAttrGetScopeLine(MlirAttribute diSubprogram) {
3533714f937SEdgar   return cast<DISubprogramAttr>(unwrap(diSubprogram)).getScopeLine();
3543714f937SEdgar }
3553714f937SEdgar 
3563714f937SEdgar MlirAttribute
3573714f937SEdgar mlirLLVMDISubprogramAttrGetCompileUnit(MlirAttribute diSubprogram) {
3583714f937SEdgar   return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getCompileUnit());
3593714f937SEdgar }
3603714f937SEdgar 
3613714f937SEdgar MlirAttribute mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram) {
3623714f937SEdgar   return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getFile());
3633714f937SEdgar }
3643714f937SEdgar 
3653714f937SEdgar MlirAttribute mlirLLVMDISubprogramAttrGetType(MlirAttribute diSubprogram) {
3663714f937SEdgar   return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getType());
3673714f937SEdgar }
3683714f937SEdgar 
3693714f937SEdgar MlirAttribute mlirLLVMDIModuleAttrGet(MlirContext ctx, MlirAttribute file,
3703714f937SEdgar                                       MlirAttribute scope, MlirAttribute name,
3713714f937SEdgar                                       MlirAttribute configMacros,
3723714f937SEdgar                                       MlirAttribute includePath,
3733714f937SEdgar                                       MlirAttribute apinotes, unsigned int line,
3743714f937SEdgar                                       bool isDecl) {
3753714f937SEdgar   return wrap(DIModuleAttr::get(
3763714f937SEdgar       unwrap(ctx), cast<DIFileAttr>(unwrap(file)),
3773714f937SEdgar       cast<DIScopeAttr>(unwrap(scope)), cast<StringAttr>(unwrap(name)),
3783714f937SEdgar       cast<StringAttr>(unwrap(configMacros)),
3793714f937SEdgar       cast<StringAttr>(unwrap(includePath)), cast<StringAttr>(unwrap(apinotes)),
3803714f937SEdgar       line, isDecl));
3813714f937SEdgar }
3823714f937SEdgar 
3833714f937SEdgar MlirAttribute mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule) {
3843714f937SEdgar   return wrap(cast<DIModuleAttr>(unwrap(diModule)).getScope());
3853714f937SEdgar }
386bc4bedd5SAbid Qadeer 
387bc4bedd5SAbid Qadeer MlirAttribute mlirLLVMDIImportedEntityAttrGet(
38875197553STobias Gysi     MlirContext ctx, unsigned int tag, MlirAttribute scope,
38975197553STobias Gysi     MlirAttribute entity, MlirAttribute file, unsigned int line,
39075197553STobias Gysi     MlirAttribute name, intptr_t nElements, MlirAttribute const *elements) {
391bc4bedd5SAbid Qadeer   SmallVector<Attribute> elementsStorage;
392bc4bedd5SAbid Qadeer   elementsStorage.reserve(nElements);
393bc4bedd5SAbid Qadeer   return wrap(DIImportedEntityAttr::get(
39475197553STobias Gysi       unwrap(ctx), tag, cast<DIScopeAttr>(unwrap(scope)),
39575197553STobias Gysi       cast<DINodeAttr>(unwrap(entity)), cast<DIFileAttr>(unwrap(file)), line,
39675197553STobias Gysi       cast<StringAttr>(unwrap(name)),
397bc4bedd5SAbid Qadeer       llvm::map_to_vector(unwrapList(nElements, elements, elementsStorage),
398bc4bedd5SAbid Qadeer                           [](Attribute a) { return cast<DINodeAttr>(a); })));
399bc4bedd5SAbid Qadeer }
4002918e779SWalter Erquinigo 
4012918e779SWalter Erquinigo MlirAttribute mlirLLVMDIAnnotationAttrGet(MlirContext ctx, MlirAttribute name,
4022918e779SWalter Erquinigo                                           MlirAttribute value) {
4032918e779SWalter Erquinigo   return wrap(DIAnnotationAttr::get(unwrap(ctx), cast<StringAttr>(unwrap(name)),
4042918e779SWalter Erquinigo                                     cast<StringAttr>(unwrap(value))));
4052918e779SWalter Erquinigo }
406