| 1 | //===- LLVM.cpp - C Interface for LLVM dialect ----------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "mlir-c/Dialect/LLVM.h" |
| 10 | #include "mlir-c/IR.h" |
| 11 | #include "mlir-c/Support.h" |
| 12 | #include "mlir/CAPI/Registration.h" |
| 13 | #include "mlir/CAPI/Wrap.h" |
| 14 | #include "mlir/Dialect/LLVMIR/LLVMAttrs.h" |
| 15 | #include "mlir/Dialect/LLVMIR/LLVMDialectDecl.h" |
| 16 | #include "mlir/Dialect/LLVMIR/LLVMTypes.h" |
| 17 | #include "llvm-c/Core.h" |
| 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | #include "llvm/ADT/SmallVectorExtras.h" |
| 20 | |
| 21 | using namespace mlir; |
| 22 | using namespace mlir::LLVM; |
| 23 | |
| 24 | MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(LLVM, llvm, LLVMDialect) |
| 25 | |
| 26 | MlirType mlirLLVMPointerTypeGet(MlirContext ctx, unsigned addressSpace) { |
| 27 | return wrap(cpp: LLVMPointerType::get(context: unwrap(c: ctx), addressSpace)); |
| 28 | } |
| 29 | |
| 30 | MlirStringRef mlirLLVMPointerTypeGetName(void) { |
| 31 | return wrap(ref: LLVM::LLVMPointerType::name); |
| 32 | } |
| 33 | |
| 34 | MlirTypeID mlirLLVMPointerTypeGetTypeID() { |
| 35 | return wrap(cpp: LLVM::LLVMPointerType::getTypeID()); |
| 36 | } |
| 37 | |
| 38 | bool mlirTypeIsALLVMPointerType(MlirType type) { |
| 39 | return isa<LLVM::LLVMPointerType>(Val: unwrap(c: type)); |
| 40 | } |
| 41 | |
| 42 | unsigned mlirLLVMPointerTypeGetAddressSpace(MlirType pointerType) { |
| 43 | return cast<LLVM::LLVMPointerType>(Val: unwrap(c: pointerType)).getAddressSpace(); |
| 44 | } |
| 45 | |
| 46 | MlirType mlirLLVMVoidTypeGet(MlirContext ctx) { |
| 47 | return wrap(cpp: LLVMVoidType::get(ctx: unwrap(c: ctx))); |
| 48 | } |
| 49 | |
| 50 | MlirStringRef mlirLLVMVoidTypeGetName(void) { return wrap(ref: LLVMVoidType::name); } |
| 51 | |
| 52 | bool mlirTypeIsALLVMArrayType(MlirType type) { |
| 53 | return isa<LLVM::LLVMArrayType>(Val: unwrap(c: type)); |
| 54 | } |
| 55 | |
| 56 | MlirTypeID mlirLLVMArrayTypeGetTypeID() { |
| 57 | return wrap(cpp: LLVM::LLVMArrayType::getTypeID()); |
| 58 | } |
| 59 | |
| 60 | MlirType mlirLLVMArrayTypeGet(MlirType elementType, unsigned numElements) { |
| 61 | return wrap(cpp: LLVMArrayType::get(elementType: unwrap(c: elementType), numElements)); |
| 62 | } |
| 63 | |
| 64 | MlirStringRef mlirLLVMArrayTypeGetName(void) { |
| 65 | return wrap(ref: LLVMArrayType::name); |
| 66 | } |
| 67 | |
| 68 | MlirType mlirLLVMArrayTypeGetElementType(MlirType type) { |
| 69 | return wrap(cpp: cast<LLVM::LLVMArrayType>(Val: unwrap(c: type)).getElementType()); |
| 70 | } |
| 71 | |
| 72 | unsigned mlirLLVMArrayTypeGetNumElements(MlirType type) { |
| 73 | return cast<LLVM::LLVMArrayType>(Val: unwrap(c: type)).getNumElements(); |
| 74 | } |
| 75 | |
| 76 | MlirType mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes, |
| 77 | MlirType const *argumentTypes, bool isVarArg) { |
| 78 | SmallVector<Type, 2> argumentStorage; |
| 79 | return wrap(cpp: LLVMFunctionType::get( |
| 80 | result: unwrap(c: resultType), |
| 81 | arguments: unwrapList(size: nArgumentTypes, first: argumentTypes, storage&: argumentStorage), isVarArg)); |
| 82 | } |
| 83 | |
| 84 | MlirStringRef mlirLLVMFunctionTypeGetName(void) { |
| 85 | return wrap(ref: LLVMFunctionType::name); |
| 86 | } |
| 87 | |
| 88 | bool mlirTypeIsALLVMFunctionType(MlirType type) { |
| 89 | return isa<LLVM::LLVMFunctionType>(Val: unwrap(c: type)); |
| 90 | } |
| 91 | |
| 92 | MlirTypeID mlirLLVMFunctionTypeGetTypeID(void) { |
| 93 | return wrap(cpp: LLVM::LLVMFunctionType::getTypeID()); |
| 94 | } |
| 95 | |
| 96 | intptr_t mlirLLVMFunctionTypeGetNumInputs(MlirType type) { |
| 97 | return llvm::cast<LLVM::LLVMFunctionType>(Val: unwrap(c: type)).getNumParams(); |
| 98 | } |
| 99 | |
| 100 | MlirType mlirLLVMFunctionTypeGetInput(MlirType type, intptr_t pos) { |
| 101 | assert(pos >= 0 && "pos in array must be positive" ); |
| 102 | return wrap(cpp: llvm::cast<LLVM::LLVMFunctionType>(Val: unwrap(c: type)) |
| 103 | .getParamType(i: static_cast<unsigned>(pos))); |
| 104 | } |
| 105 | |
| 106 | MlirType mlirLLVMFunctionTypeGetReturnType(MlirType type) { |
| 107 | return wrap(cpp: llvm::cast<LLVM::LLVMFunctionType>(Val: unwrap(c: type)).getReturnType()); |
| 108 | } |
| 109 | |
| 110 | bool mlirLLVMFunctionTypeIsVarArg(MlirType type) { |
| 111 | return llvm::cast<LLVM::LLVMFunctionType>(Val: unwrap(c: type)).isVarArg(); |
| 112 | } |
| 113 | |
| 114 | bool mlirTypeIsALLVMStructType(MlirType type) { |
| 115 | return isa<LLVM::LLVMStructType>(Val: unwrap(c: type)); |
| 116 | } |
| 117 | |
| 118 | MlirTypeID mlirLLVMStructTypeGetTypeID() { |
| 119 | return wrap(cpp: LLVM::LLVMStructType::getTypeID()); |
| 120 | } |
| 121 | |
| 122 | MlirStringRef mlirLLVMStructTypeGetName(void) { |
| 123 | return wrap(ref: LLVM::LLVMStructType::name); |
| 124 | } |
| 125 | |
| 126 | bool mlirLLVMStructTypeIsLiteral(MlirType type) { |
| 127 | return !cast<LLVM::LLVMStructType>(Val: unwrap(c: type)).isIdentified(); |
| 128 | } |
| 129 | |
| 130 | intptr_t mlirLLVMStructTypeGetNumElementTypes(MlirType type) { |
| 131 | return cast<LLVM::LLVMStructType>(Val: unwrap(c: type)).getBody().size(); |
| 132 | } |
| 133 | |
| 134 | MlirType mlirLLVMStructTypeGetElementType(MlirType type, intptr_t position) { |
| 135 | return wrap(cpp: cast<LLVM::LLVMStructType>(Val: unwrap(c: type)).getBody()[position]); |
| 136 | } |
| 137 | |
| 138 | bool mlirLLVMStructTypeIsPacked(MlirType type) { |
| 139 | return cast<LLVM::LLVMStructType>(Val: unwrap(c: type)).isPacked(); |
| 140 | } |
| 141 | |
| 142 | MlirStringRef mlirLLVMStructTypeGetIdentifier(MlirType type) { |
| 143 | return wrap(ref: cast<LLVM::LLVMStructType>(Val: unwrap(c: type)).getName()); |
| 144 | } |
| 145 | |
| 146 | bool mlirLLVMStructTypeIsOpaque(MlirType type) { |
| 147 | return cast<LLVM::LLVMStructType>(Val: unwrap(c: type)).isOpaque(); |
| 148 | } |
| 149 | |
| 150 | MlirType mlirLLVMStructTypeLiteralGet(MlirContext ctx, intptr_t nFieldTypes, |
| 151 | MlirType const *fieldTypes, |
| 152 | bool isPacked) { |
| 153 | SmallVector<Type> fieldStorage; |
| 154 | return wrap(cpp: LLVMStructType::getLiteral( |
| 155 | context: unwrap(c: ctx), types: unwrapList(size: nFieldTypes, first: fieldTypes, storage&: fieldStorage), |
| 156 | isPacked)); |
| 157 | } |
| 158 | |
| 159 | MlirType mlirLLVMStructTypeLiteralGetChecked(MlirLocation loc, |
| 160 | intptr_t nFieldTypes, |
| 161 | MlirType const *fieldTypes, |
| 162 | bool isPacked) { |
| 163 | SmallVector<Type> fieldStorage; |
| 164 | return wrap(cpp: LLVMStructType::getLiteralChecked( |
| 165 | emitError: [loc]() { return emitError(loc: unwrap(c: loc)); }, context: unwrap(c: loc)->getContext(), |
| 166 | types: unwrapList(size: nFieldTypes, first: fieldTypes, storage&: fieldStorage), isPacked)); |
| 167 | } |
| 168 | |
| 169 | MlirType mlirLLVMStructTypeOpaqueGet(MlirContext ctx, MlirStringRef name) { |
| 170 | return wrap(cpp: LLVMStructType::getOpaque(name: unwrap(ref: name), context: unwrap(c: ctx))); |
| 171 | } |
| 172 | |
| 173 | MlirType mlirLLVMStructTypeIdentifiedGet(MlirContext ctx, MlirStringRef name) { |
| 174 | return wrap(cpp: LLVMStructType::getIdentified(context: unwrap(c: ctx), name: unwrap(ref: name))); |
| 175 | } |
| 176 | |
| 177 | MlirType mlirLLVMStructTypeIdentifiedNewGet(MlirContext ctx, MlirStringRef name, |
| 178 | intptr_t nFieldTypes, |
| 179 | MlirType const *fieldTypes, |
| 180 | bool isPacked) { |
| 181 | SmallVector<Type> fields; |
| 182 | return wrap(cpp: LLVMStructType::getNewIdentified( |
| 183 | context: unwrap(c: ctx), name: unwrap(ref: name), elements: unwrapList(size: nFieldTypes, first: fieldTypes, storage&: fields), |
| 184 | isPacked)); |
| 185 | } |
| 186 | |
| 187 | MlirLogicalResult mlirLLVMStructTypeSetBody(MlirType structType, |
| 188 | intptr_t nFieldTypes, |
| 189 | MlirType const *fieldTypes, |
| 190 | bool isPacked) { |
| 191 | SmallVector<Type> fields; |
| 192 | return wrap( |
| 193 | res: cast<LLVM::LLVMStructType>(Val: unwrap(c: structType)) |
| 194 | .setBody(types: unwrapList(size: nFieldTypes, first: fieldTypes, storage&: fields), isPacked)); |
| 195 | } |
| 196 | |
| 197 | MlirAttribute mlirLLVMDIExpressionElemAttrGet(MlirContext ctx, |
| 198 | unsigned int opcode, |
| 199 | intptr_t nArguments, |
| 200 | uint64_t const *arguments) { |
| 201 | auto list = ArrayRef<uint64_t>(arguments, nArguments); |
| 202 | return wrap(cpp: DIExpressionElemAttr::get(context: unwrap(c: ctx), opcode, arguments: list)); |
| 203 | } |
| 204 | |
| 205 | MlirStringRef mlirLLVMDIExpressionElemAttrGetName(void) { |
| 206 | return wrap(ref: DIExpressionElemAttr::name); |
| 207 | } |
| 208 | |
| 209 | MlirAttribute mlirLLVMDIExpressionAttrGet(MlirContext ctx, intptr_t nOperations, |
| 210 | MlirAttribute const *operations) { |
| 211 | SmallVector<Attribute> attrStorage; |
| 212 | attrStorage.reserve(N: nOperations); |
| 213 | |
| 214 | return wrap(cpp: DIExpressionAttr::get( |
| 215 | context: unwrap(c: ctx), |
| 216 | operations: llvm::map_to_vector(C: unwrapList(size: nOperations, first: operations, storage&: attrStorage), |
| 217 | F: llvm::CastTo<DIExpressionElemAttr>))); |
| 218 | } |
| 219 | |
| 220 | MlirStringRef mlirLLVMDIExpressionAttrGetName(void) { |
| 221 | return wrap(ref: DIExpressionAttr::name); |
| 222 | } |
| 223 | |
| 224 | MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx) { |
| 225 | return wrap(cpp: DINullTypeAttr::get(ctx: unwrap(c: ctx))); |
| 226 | } |
| 227 | |
| 228 | MlirStringRef mlirLLVMDINullTypeAttrGetName(void) { |
| 229 | return wrap(ref: DINullTypeAttr::name); |
| 230 | } |
| 231 | |
| 232 | MlirAttribute mlirLLVMDIBasicTypeAttrGet(MlirContext ctx, unsigned int tag, |
| 233 | MlirAttribute name, |
| 234 | uint64_t sizeInBits, |
| 235 | MlirLLVMTypeEncoding encoding) { |
| 236 | |
| 237 | return wrap(cpp: DIBasicTypeAttr::get( |
| 238 | context: unwrap(c: ctx), tag, name: cast<StringAttr>(Val: unwrap(c: name)), sizeInBits, encoding)); |
| 239 | } |
| 240 | |
| 241 | MlirStringRef mlirLLVMDIBasicTypeAttrGetName(void) { |
| 242 | return wrap(ref: DIBasicTypeAttr::name); |
| 243 | } |
| 244 | |
| 245 | MlirAttribute mlirLLVMDICompositeTypeAttrGetRecSelf(MlirAttribute recId) { |
| 246 | return wrap( |
| 247 | cpp: DICompositeTypeAttr::getRecSelf(recId: cast<DistinctAttr>(Val: unwrap(c: recId)))); |
| 248 | } |
| 249 | |
| 250 | MlirAttribute mlirLLVMDICompositeTypeAttrGet( |
| 251 | MlirContext ctx, MlirAttribute recId, bool isRecSelf, unsigned int tag, |
| 252 | MlirAttribute name, MlirAttribute file, uint32_t line, MlirAttribute scope, |
| 253 | MlirAttribute baseType, int64_t flags, uint64_t sizeInBits, |
| 254 | uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements, |
| 255 | MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated, |
| 256 | MlirAttribute associated, MlirAttribute identifier, |
| 257 | MlirAttribute discriminator) { |
| 258 | SmallVector<Attribute> elementsStorage; |
| 259 | elementsStorage.reserve(N: nElements); |
| 260 | |
| 261 | return wrap(cpp: DICompositeTypeAttr::get( |
| 262 | context: unwrap(c: ctx), recId: cast<DistinctAttr>(Val: unwrap(c: recId)), isRecSelf, tag, |
| 263 | name: cast<StringAttr>(Val: unwrap(c: name)), file: cast<DIFileAttr>(Val: unwrap(c: file)), line, |
| 264 | scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), baseType: cast<DITypeAttr>(Val: unwrap(c: baseType)), |
| 265 | flags: DIFlags(flags), sizeInBits, alignInBits, |
| 266 | dataLocation: cast<DIExpressionAttr>(Val: unwrap(c: dataLocation)), |
| 267 | rank: cast<DIExpressionAttr>(Val: unwrap(c: rank)), |
| 268 | allocated: cast<DIExpressionAttr>(Val: unwrap(c: allocated)), |
| 269 | associated: cast<DIExpressionAttr>(Val: unwrap(c: associated)), |
| 270 | identifier: cast<StringAttr>(Val: unwrap(c: identifier)), |
| 271 | discriminator: cast<DIDerivedTypeAttr>(Val: unwrap(c: discriminator)), |
| 272 | elements: llvm::map_to_vector(C: unwrapList(size: nElements, first: elements, storage&: elementsStorage), |
| 273 | F: llvm::CastTo<DINodeAttr>))); |
| 274 | } |
| 275 | |
| 276 | MlirStringRef mlirLLVMDICompositeTypeAttrGetName(void) { |
| 277 | return wrap(ref: DICompositeTypeAttr::name); |
| 278 | } |
| 279 | |
| 280 | MlirAttribute mlirLLVMDIDerivedTypeAttrGet( |
| 281 | MlirContext ctx, unsigned int tag, MlirAttribute name, MlirAttribute file, |
| 282 | uint32_t line, MlirAttribute scope, MlirAttribute baseType, |
| 283 | uint64_t sizeInBits, uint32_t alignInBits, uint64_t offsetInBits, |
| 284 | int64_t dwarfAddressSpace, int64_t flags, MlirAttribute ) { |
| 285 | std::optional<unsigned> addressSpace = std::nullopt; |
| 286 | if (dwarfAddressSpace >= 0) |
| 287 | addressSpace = (unsigned)dwarfAddressSpace; |
| 288 | return wrap(cpp: DIDerivedTypeAttr::get( |
| 289 | context: unwrap(c: ctx), tag, name: cast<StringAttr>(Val: unwrap(c: name)), |
| 290 | file: cast<DIFileAttr>(Val: unwrap(c: file)), line, scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), |
| 291 | baseType: cast<DITypeAttr>(Val: unwrap(c: baseType)), sizeInBits, alignInBits, offsetInBits, |
| 292 | dwarfAddressSpace: addressSpace, flags: DIFlags(flags), extraData: unwrap(c: extraData))); |
| 293 | } |
| 294 | |
| 295 | MlirStringRef mlirLLVMDIDerivedTypeAttrGetName(void) { |
| 296 | return wrap(ref: DIDerivedTypeAttr::name); |
| 297 | } |
| 298 | |
| 299 | MlirAttribute mlirLLVMDIStringTypeAttrGet( |
| 300 | MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits, |
| 301 | uint32_t alignInBits, MlirAttribute stringLength, |
| 302 | MlirAttribute stringLengthExp, MlirAttribute stringLocationExp, |
| 303 | MlirLLVMTypeEncoding encoding, MlirAttribute charType) { |
| 304 | return wrap(cpp: DIStringTypeAttr::get( |
| 305 | context: unwrap(c: ctx), tag, name: cast<StringAttr>(Val: unwrap(c: name)), sizeInBits, alignInBits, |
| 306 | stringLength: cast<DIVariableAttr>(Val: unwrap(c: stringLength)), |
| 307 | stringLengthExp: cast<DIExpressionAttr>(Val: unwrap(c: stringLengthExp)), |
| 308 | stringLocationExp: cast<DIExpressionAttr>(Val: unwrap(c: stringLocationExp)), encoding, |
| 309 | charType: cast<DITypeAttr>(Val: unwrap(c: charType)))); |
| 310 | } |
| 311 | |
| 312 | MlirStringRef mlirLLVMDIStringTypeAttrGetName(void) { |
| 313 | return wrap(ref: DIStringTypeAttr::name); |
| 314 | } |
| 315 | |
| 316 | MlirAttribute |
| 317 | mlirLLVMDIDerivedTypeAttrGetBaseType(MlirAttribute diDerivedType) { |
| 318 | return wrap(cpp: cast<DIDerivedTypeAttr>(Val: unwrap(c: diDerivedType)).getBaseType()); |
| 319 | } |
| 320 | |
| 321 | MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx, MlirLLVMCConv cconv) { |
| 322 | return wrap(cpp: CConvAttr::get(context: unwrap(c: ctx), CallingConv: CConv(cconv))); |
| 323 | } |
| 324 | |
| 325 | MlirStringRef mlirLLVMCConvAttrGetName(void) { return wrap(ref: CConvAttr::name); } |
| 326 | |
| 327 | MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx, MlirLLVMComdat comdat) { |
| 328 | return wrap(cpp: ComdatAttr::get(context: unwrap(c: ctx), comdat: comdat::Comdat(comdat))); |
| 329 | } |
| 330 | |
| 331 | MlirStringRef mlirLLVMComdatAttrGetName(void) { return wrap(ref: ComdatAttr::name); } |
| 332 | |
| 333 | MlirAttribute mlirLLVMLinkageAttrGet(MlirContext ctx, MlirLLVMLinkage linkage) { |
| 334 | return wrap(cpp: LinkageAttr::get(context: unwrap(c: ctx), linkage: linkage::Linkage(linkage))); |
| 335 | } |
| 336 | |
| 337 | MlirStringRef mlirLLVMLinkageAttrGetName(void) { |
| 338 | return wrap(ref: LinkageAttr::name); |
| 339 | } |
| 340 | |
| 341 | MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx, MlirAttribute name, |
| 342 | MlirAttribute directory) { |
| 343 | return wrap(cpp: DIFileAttr::get(context: unwrap(c: ctx), name: cast<StringAttr>(Val: unwrap(c: name)), |
| 344 | directory: cast<StringAttr>(Val: unwrap(c: directory)))); |
| 345 | } |
| 346 | |
| 347 | MlirStringRef mlirLLVMDIFileAttrGetName(void) { return wrap(ref: DIFileAttr::name); } |
| 348 | |
| 349 | MlirAttribute mlirLLVMDICompileUnitAttrGetRecSelf(MlirAttribute recId) { |
| 350 | return wrap(cpp: DICompileUnitAttr::getRecSelf(recId: cast<DistinctAttr>(Val: unwrap(c: recId)))); |
| 351 | } |
| 352 | |
| 353 | MlirAttribute mlirLLVMDICompileUnitAttrGet( |
| 354 | MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id, |
| 355 | unsigned int sourceLanguage, MlirAttribute file, MlirAttribute producer, |
| 356 | bool isOptimized, MlirLLVMDIEmissionKind emissionKind, |
| 357 | bool isDebugInfoForProfiling, MlirLLVMDINameTableKind nameTableKind, |
| 358 | MlirAttribute splitDebugFilename, intptr_t nImportedEntities, |
| 359 | MlirAttribute const *importedEntities) { |
| 360 | return mlirLLVMDICompileUnitAttrGetWithSourceLanguageDialect( |
| 361 | ctx, recId, isRecSelf, id, sourceLanguage, |
| 362 | /*sourceLanguageDialect=*/0, file, producer, isOptimized, emissionKind, |
| 363 | isDebugInfoForProfiling, nameTableKind, splitDebugFilename, |
| 364 | nImportedEntities, importedEntities); |
| 365 | } |
| 366 | |
| 367 | MlirAttribute mlirLLVMDICompileUnitAttrGetWithSourceLanguageDialect( |
| 368 | MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id, |
| 369 | unsigned int sourceLanguage, unsigned int sourceLanguageDialect, |
| 370 | MlirAttribute file, MlirAttribute producer, bool isOptimized, |
| 371 | MlirLLVMDIEmissionKind emissionKind, bool isDebugInfoForProfiling, |
| 372 | MlirLLVMDINameTableKind nameTableKind, MlirAttribute splitDebugFilename, |
| 373 | intptr_t nImportedEntities, MlirAttribute const *importedEntities) { |
| 374 | SmallVector<Attribute> importsStorage; |
| 375 | importsStorage.reserve(N: nImportedEntities); |
| 376 | auto sourceLanguageAttr = DISourceLanguageNameAttr::get( |
| 377 | context: unwrap(c: ctx), language: sourceLanguage, /*name=*/0, /*version=*/std::nullopt, |
| 378 | dialect: sourceLanguageDialect); |
| 379 | return wrap(cpp: DICompileUnitAttr::get( |
| 380 | context: unwrap(c: ctx), recId: cast<DistinctAttr>(Val: unwrap(c: recId)), isRecSelf, |
| 381 | id: cast<DistinctAttr>(Val: unwrap(c: id)), sourceLanguage: sourceLanguageAttr, |
| 382 | file: cast<DIFileAttr>(Val: unwrap(c: file)), producer: cast<StringAttr>(Val: unwrap(c: producer)), |
| 383 | isOptimized, emissionKind: DIEmissionKind(emissionKind), isDebugInfoForProfiling, |
| 384 | nameTableKind: DINameTableKind(nameTableKind), |
| 385 | splitDebugFilename: cast<StringAttr>(Val: unwrap(c: splitDebugFilename)), |
| 386 | importedEntities: llvm::map_to_vector( |
| 387 | C: unwrapList(size: nImportedEntities, first: importedEntities, storage&: importsStorage), |
| 388 | F: llvm::CastTo<DINodeAttr>))); |
| 389 | } |
| 390 | |
| 391 | MlirAttribute mlirLLVMDICompileUnitAttrGetWithSourceLanguageName( |
| 392 | MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id, |
| 393 | unsigned int sourceLanguageName, uint32_t sourceLanguageVersion, |
| 394 | unsigned int sourceLanguageDialect, MlirAttribute file, |
| 395 | MlirAttribute producer, bool isOptimized, |
| 396 | MlirLLVMDIEmissionKind emissionKind, bool isDebugInfoForProfiling, |
| 397 | MlirLLVMDINameTableKind nameTableKind, MlirAttribute splitDebugFilename, |
| 398 | intptr_t nImportedEntities, MlirAttribute const *importedEntities) { |
| 399 | SmallVector<Attribute> importsStorage; |
| 400 | importsStorage.reserve(N: nImportedEntities); |
| 401 | auto sourceLanguageAttr = DISourceLanguageNameAttr::get( |
| 402 | context: unwrap(c: ctx), /*language=*/0, name: sourceLanguageName, |
| 403 | version: std::optional<uint32_t>(sourceLanguageVersion), dialect: sourceLanguageDialect); |
| 404 | return wrap(cpp: DICompileUnitAttr::get( |
| 405 | context: unwrap(c: ctx), recId: cast<DistinctAttr>(Val: unwrap(c: recId)), isRecSelf, |
| 406 | id: cast<DistinctAttr>(Val: unwrap(c: id)), sourceLanguage: sourceLanguageAttr, |
| 407 | file: cast<DIFileAttr>(Val: unwrap(c: file)), producer: cast<StringAttr>(Val: unwrap(c: producer)), |
| 408 | isOptimized, emissionKind: DIEmissionKind(emissionKind), isDebugInfoForProfiling, |
| 409 | nameTableKind: DINameTableKind(nameTableKind), |
| 410 | splitDebugFilename: cast<StringAttr>(Val: unwrap(c: splitDebugFilename)), |
| 411 | importedEntities: llvm::map_to_vector( |
| 412 | C: unwrapList(size: nImportedEntities, first: importedEntities, storage&: importsStorage), |
| 413 | F: llvm::CastTo<DINodeAttr>))); |
| 414 | } |
| 415 | |
| 416 | MlirStringRef mlirLLVMDICompileUnitAttrGetName(void) { |
| 417 | return wrap(ref: DICompileUnitAttr::name); |
| 418 | } |
| 419 | |
| 420 | MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, uint64_t value) { |
| 421 | return wrap(cpp: DIFlagsAttr::get(context: unwrap(c: ctx), val: DIFlags(value))); |
| 422 | } |
| 423 | |
| 424 | MlirStringRef mlirLLVMDIFlagsAttrGetName(void) { |
| 425 | return wrap(ref: DIFlagsAttr::name); |
| 426 | } |
| 427 | |
| 428 | MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx, |
| 429 | MlirAttribute scope, |
| 430 | MlirAttribute file, |
| 431 | unsigned int line, |
| 432 | unsigned int column) { |
| 433 | return wrap( |
| 434 | cpp: DILexicalBlockAttr::get(context: unwrap(c: ctx), scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), |
| 435 | file: cast<DIFileAttr>(Val: unwrap(c: file)), line, column)); |
| 436 | } |
| 437 | |
| 438 | MlirStringRef mlirLLVMDILexicalBlockAttrGetName(void) { |
| 439 | return wrap(ref: DILexicalBlockAttr::name); |
| 440 | } |
| 441 | |
| 442 | MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx, |
| 443 | MlirAttribute scope, |
| 444 | MlirAttribute file, |
| 445 | unsigned int discriminator) { |
| 446 | return wrap(cpp: DILexicalBlockFileAttr::get( |
| 447 | context: unwrap(c: ctx), scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), |
| 448 | file: cast<DIFileAttr>(Val: unwrap(c: file)), discriminator)); |
| 449 | } |
| 450 | |
| 451 | MlirStringRef mlirLLVMDILexicalBlockFileAttrGetName(void) { |
| 452 | return wrap(ref: DILexicalBlockFileAttr::name); |
| 453 | } |
| 454 | |
| 455 | MlirAttribute mlirLLVMDILocalVariableAttrGet( |
| 456 | MlirContext ctx, MlirAttribute scope, MlirAttribute name, |
| 457 | MlirAttribute diFile, unsigned int line, unsigned int arg, |
| 458 | unsigned int alignInBits, MlirAttribute diType, int64_t flags) { |
| 459 | return wrap(cpp: DILocalVariableAttr::get( |
| 460 | context: unwrap(c: ctx), scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), |
| 461 | name: cast<StringAttr>(Val: unwrap(c: name)), file: cast<DIFileAttr>(Val: unwrap(c: diFile)), line, |
| 462 | arg, alignInBits, type: cast<DITypeAttr>(Val: unwrap(c: diType)), flags: DIFlags(flags))); |
| 463 | } |
| 464 | |
| 465 | MlirStringRef mlirLLVMDILocalVariableAttrGetName(void) { |
| 466 | return wrap(ref: DILocalVariableAttr::name); |
| 467 | } |
| 468 | |
| 469 | MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx, |
| 470 | unsigned int callingConvention, |
| 471 | intptr_t nTypes, |
| 472 | MlirAttribute const *types) { |
| 473 | SmallVector<Attribute> attrStorage; |
| 474 | attrStorage.reserve(N: nTypes); |
| 475 | |
| 476 | return wrap(cpp: DISubroutineTypeAttr::get( |
| 477 | context: unwrap(c: ctx), callingConvention, |
| 478 | types: llvm::map_to_vector(C: unwrapList(size: nTypes, first: types, storage&: attrStorage), |
| 479 | F: llvm::CastTo<DITypeAttr>))); |
| 480 | } |
| 481 | |
| 482 | MlirStringRef mlirLLVMDISubroutineTypeAttrGetName(void) { |
| 483 | return wrap(ref: DISubroutineTypeAttr::name); |
| 484 | } |
| 485 | |
| 486 | MlirAttribute mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId) { |
| 487 | return wrap(cpp: DISubprogramAttr::getRecSelf(recId: cast<DistinctAttr>(Val: unwrap(c: recId)))); |
| 488 | } |
| 489 | |
| 490 | MlirAttribute mlirLLVMDISubprogramAttrGet( |
| 491 | MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id, |
| 492 | MlirAttribute compileUnit, MlirAttribute scope, MlirAttribute name, |
| 493 | MlirAttribute linkageName, MlirAttribute file, unsigned int line, |
| 494 | unsigned int scopeLine, uint64_t subprogramFlags, MlirAttribute type, |
| 495 | intptr_t nRetainedNodes, MlirAttribute const *retainedNodes, |
| 496 | intptr_t nAnnotations, MlirAttribute const *annotations) { |
| 497 | SmallVector<Attribute> nodesStorage; |
| 498 | nodesStorage.reserve(N: nRetainedNodes); |
| 499 | |
| 500 | SmallVector<Attribute> annotationsStorage; |
| 501 | annotationsStorage.reserve(N: nAnnotations); |
| 502 | |
| 503 | return wrap(cpp: DISubprogramAttr::get( |
| 504 | context: unwrap(c: ctx), recId: cast<DistinctAttr>(Val: unwrap(c: recId)), isRecSelf, |
| 505 | id: cast<DistinctAttr>(Val: unwrap(c: id)), |
| 506 | compileUnit: cast<DICompileUnitAttr>(Val: unwrap(c: compileUnit)), |
| 507 | scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), name: cast<StringAttr>(Val: unwrap(c: name)), |
| 508 | linkageName: cast<StringAttr>(Val: unwrap(c: linkageName)), file: cast<DIFileAttr>(Val: unwrap(c: file)), |
| 509 | line, scopeLine, subprogramFlags: DISubprogramFlags(subprogramFlags), |
| 510 | type: cast<DISubroutineTypeAttr>(Val: unwrap(c: type)), |
| 511 | retainedNodes: llvm::map_to_vector( |
| 512 | C: unwrapList(size: nRetainedNodes, first: retainedNodes, storage&: nodesStorage), |
| 513 | F: llvm::CastTo<Attribute>), |
| 514 | annotations: llvm::map_to_vector( |
| 515 | C: unwrapList(size: nAnnotations, first: annotations, storage&: annotationsStorage), |
| 516 | F: llvm::CastTo<DINodeAttr>))); |
| 517 | } |
| 518 | |
| 519 | MlirStringRef mlirLLVMDISubprogramAttrGetName(void) { |
| 520 | return wrap(ref: DISubprogramAttr::name); |
| 521 | } |
| 522 | |
| 523 | MlirAttribute mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram) { |
| 524 | return wrap(cpp: cast<DISubprogramAttr>(Val: unwrap(c: diSubprogram)).getScope()); |
| 525 | } |
| 526 | |
| 527 | unsigned int mlirLLVMDISubprogramAttrGetLine(MlirAttribute diSubprogram) { |
| 528 | return cast<DISubprogramAttr>(Val: unwrap(c: diSubprogram)).getLine(); |
| 529 | } |
| 530 | |
| 531 | unsigned int mlirLLVMDISubprogramAttrGetScopeLine(MlirAttribute diSubprogram) { |
| 532 | return cast<DISubprogramAttr>(Val: unwrap(c: diSubprogram)).getScopeLine(); |
| 533 | } |
| 534 | |
| 535 | MlirAttribute |
| 536 | mlirLLVMDISubprogramAttrGetCompileUnit(MlirAttribute diSubprogram) { |
| 537 | return wrap(cpp: cast<DISubprogramAttr>(Val: unwrap(c: diSubprogram)).getCompileUnit()); |
| 538 | } |
| 539 | |
| 540 | MlirAttribute mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram) { |
| 541 | return wrap(cpp: cast<DISubprogramAttr>(Val: unwrap(c: diSubprogram)).getFile()); |
| 542 | } |
| 543 | |
| 544 | MlirAttribute mlirLLVMDISubprogramAttrGetType(MlirAttribute diSubprogram) { |
| 545 | return wrap(cpp: cast<DISubprogramAttr>(Val: unwrap(c: diSubprogram)).getType()); |
| 546 | } |
| 547 | |
| 548 | MlirAttribute mlirLLVMDIModuleAttrGet(MlirContext ctx, MlirAttribute file, |
| 549 | MlirAttribute scope, MlirAttribute name, |
| 550 | MlirAttribute configMacros, |
| 551 | MlirAttribute includePath, |
| 552 | MlirAttribute apinotes, unsigned int line, |
| 553 | bool isDecl) { |
| 554 | return wrap(cpp: DIModuleAttr::get( |
| 555 | context: unwrap(c: ctx), file: cast<DIFileAttr>(Val: unwrap(c: file)), |
| 556 | scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), name: cast<StringAttr>(Val: unwrap(c: name)), |
| 557 | configMacros: cast<StringAttr>(Val: unwrap(c: configMacros)), |
| 558 | includePath: cast<StringAttr>(Val: unwrap(c: includePath)), apinotes: cast<StringAttr>(Val: unwrap(c: apinotes)), |
| 559 | line, isDecl)); |
| 560 | } |
| 561 | |
| 562 | MlirStringRef mlirLLVMDIModuleAttrGetName(void) { |
| 563 | return wrap(ref: DIModuleAttr::name); |
| 564 | } |
| 565 | |
| 566 | MlirAttribute mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule) { |
| 567 | return wrap(cpp: cast<DIModuleAttr>(Val: unwrap(c: diModule)).getScope()); |
| 568 | } |
| 569 | |
| 570 | MlirAttribute mlirLLVMDIImportedEntityAttrGet( |
| 571 | MlirContext ctx, unsigned int tag, MlirAttribute scope, |
| 572 | MlirAttribute entity, MlirAttribute file, unsigned int line, |
| 573 | MlirAttribute name, intptr_t nElements, MlirAttribute const *elements) { |
| 574 | SmallVector<Attribute> elementsStorage; |
| 575 | elementsStorage.reserve(N: nElements); |
| 576 | return wrap(cpp: DIImportedEntityAttr::get( |
| 577 | context: unwrap(c: ctx), tag, scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), |
| 578 | entity: cast<DINodeAttr>(Val: unwrap(c: entity)), file: cast<DIFileAttr>(Val: unwrap(c: file)), line, |
| 579 | name: cast<StringAttr>(Val: unwrap(c: name)), |
| 580 | elements: llvm::map_to_vector(C: unwrapList(size: nElements, first: elements, storage&: elementsStorage), |
| 581 | F: llvm::CastTo<DINodeAttr>))); |
| 582 | } |
| 583 | |
| 584 | MlirStringRef mlirLLVMDIImportedEntityAttrGetName(void) { |
| 585 | return wrap(ref: DIImportedEntityAttr::name); |
| 586 | } |
| 587 | |
| 588 | MlirAttribute mlirLLVMDIAnnotationAttrGet(MlirContext ctx, MlirAttribute name, |
| 589 | MlirAttribute value) { |
| 590 | return wrap(cpp: DIAnnotationAttr::get(context: unwrap(c: ctx), name: cast<StringAttr>(Val: unwrap(c: name)), |
| 591 | value: cast<StringAttr>(Val: unwrap(c: value)))); |
| 592 | } |
| 593 | |
| 594 | MlirStringRef mlirLLVMDIAnnotationAttrGetName(void) { |
| 595 | return wrap(ref: DIAnnotationAttr::name); |
| 596 | } |
| 597 | |
| 598 | //===----------------------------------------------------------------------===// |
| 599 | // Metadata Attributes |
| 600 | //===----------------------------------------------------------------------===// |
| 601 | |
| 602 | MlirAttribute mlirLLVMMDStringAttrGet(MlirContext ctx, MlirStringRef value) { |
| 603 | return wrap(cpp: MDStringAttr::get(context: unwrap(c: ctx), |
| 604 | value: StringAttr::get(context: unwrap(c: ctx), bytes: unwrap(ref: value)))); |
| 605 | } |
| 606 | |
| 607 | bool mlirLLVMAttrIsAMDStringAttr(MlirAttribute attr) { |
| 608 | return isa<MDStringAttr>(Val: unwrap(c: attr)); |
| 609 | } |
| 610 | |
| 611 | MlirTypeID mlirLLVMMDStringAttrGetTypeID(void) { |
| 612 | return wrap(cpp: MDStringAttr::getTypeID()); |
| 613 | } |
| 614 | |
| 615 | MlirStringRef mlirLLVMMDStringAttrGetValue(MlirAttribute attr) { |
| 616 | return wrap(ref: cast<MDStringAttr>(Val: unwrap(c: attr)).getValue().getValue()); |
| 617 | } |
| 618 | |
| 619 | MlirAttribute mlirLLVMMDConstantAttrGet(MlirContext ctx, |
| 620 | MlirAttribute valueAttr) { |
| 621 | return wrap(cpp: MDConstantAttr::get(context: unwrap(c: ctx), value: unwrap(c: valueAttr))); |
| 622 | } |
| 623 | |
| 624 | bool mlirLLVMAttrIsAMDConstantAttr(MlirAttribute attr) { |
| 625 | return isa<MDConstantAttr>(Val: unwrap(c: attr)); |
| 626 | } |
| 627 | |
| 628 | MlirTypeID mlirLLVMMDConstantAttrGetTypeID(void) { |
| 629 | return wrap(cpp: MDConstantAttr::getTypeID()); |
| 630 | } |
| 631 | |
| 632 | MlirAttribute mlirLLVMMDConstantAttrGetValue(MlirAttribute attr) { |
| 633 | return wrap(cpp: (Attribute)cast<MDConstantAttr>(Val: unwrap(c: attr)).getValue()); |
| 634 | } |
| 635 | |
| 636 | MlirAttribute mlirLLVMMDGlobalValueAttrGet(MlirContext ctx, |
| 637 | MlirAttribute name) { |
| 638 | return wrap(cpp: MDGlobalValueAttr::get(context: unwrap(c: ctx), |
| 639 | name: cast<FlatSymbolRefAttr>(Val: unwrap(c: name)))); |
| 640 | } |
| 641 | |
| 642 | bool mlirLLVMAttrIsAMDGlobalValueAttr(MlirAttribute attr) { |
| 643 | return isa<MDGlobalValueAttr>(Val: unwrap(c: attr)); |
| 644 | } |
| 645 | |
| 646 | MlirTypeID mlirLLVMMDGlobalValueAttrGetTypeID(void) { |
| 647 | return wrap(cpp: MDGlobalValueAttr::getTypeID()); |
| 648 | } |
| 649 | |
| 650 | MlirAttribute mlirLLVMMDGlobalValueAttrGetName(MlirAttribute attr) { |
| 651 | return wrap(cpp: (Attribute)cast<MDGlobalValueAttr>(Val: unwrap(c: attr)).getName()); |
| 652 | } |
| 653 | |
| 654 | MlirAttribute mlirLLVMMDNodeAttrGet(MlirContext ctx, intptr_t nOperands, |
| 655 | MlirAttribute const *operands) { |
| 656 | SmallVector<Attribute> attrStorage; |
| 657 | attrStorage.reserve(N: nOperands); |
| 658 | return wrap(cpp: MDNodeAttr::get(context: unwrap(c: ctx), |
| 659 | operands: unwrapList(size: nOperands, first: operands, storage&: attrStorage))); |
| 660 | } |
| 661 | |
| 662 | bool mlirLLVMAttrIsAMDNodeAttr(MlirAttribute attr) { |
| 663 | return isa<MDNodeAttr>(Val: unwrap(c: attr)); |
| 664 | } |
| 665 | |
| 666 | MlirTypeID mlirLLVMMDNodeAttrGetTypeID(void) { |
| 667 | return wrap(cpp: MDNodeAttr::getTypeID()); |
| 668 | } |
| 669 | |
| 670 | intptr_t mlirLLVMMDNodeAttrGetNumOperands(MlirAttribute attr) { |
| 671 | return cast<MDNodeAttr>(Val: unwrap(c: attr)).getOperands().size(); |
| 672 | } |
| 673 | |
| 674 | MlirAttribute mlirLLVMMDNodeAttrGetOperand(MlirAttribute attr, intptr_t index) { |
| 675 | return wrap(cpp: cast<MDNodeAttr>(Val: unwrap(c: attr)).getOperands()[index]); |
| 676 | } |
| 677 | |