| 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/LLVMDialect.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 | bool mlirTypeIsALLVMPointerType(MlirType type) { |
| 31 | return isa<LLVM::LLVMPointerType>(Val: unwrap(c: type)); |
| 32 | } |
| 33 | |
| 34 | unsigned mlirLLVMPointerTypeGetAddressSpace(MlirType pointerType) { |
| 35 | return cast<LLVM::LLVMPointerType>(Val: unwrap(c: pointerType)).getAddressSpace(); |
| 36 | } |
| 37 | |
| 38 | MlirType mlirLLVMVoidTypeGet(MlirContext ctx) { |
| 39 | return wrap(cpp: LLVMVoidType::get(ctx: unwrap(c: ctx))); |
| 40 | } |
| 41 | |
| 42 | MlirType mlirLLVMArrayTypeGet(MlirType elementType, unsigned numElements) { |
| 43 | return wrap(cpp: LLVMArrayType::get(elementType: unwrap(c: elementType), numElements)); |
| 44 | } |
| 45 | |
| 46 | MlirType mlirLLVMArrayTypeGetElementType(MlirType type) { |
| 47 | return wrap(cpp: cast<LLVM::LLVMArrayType>(Val: unwrap(c: type)).getElementType()); |
| 48 | } |
| 49 | |
| 50 | MlirType mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes, |
| 51 | MlirType const *argumentTypes, bool isVarArg) { |
| 52 | SmallVector<Type, 2> argumentStorage; |
| 53 | return wrap(cpp: LLVMFunctionType::get( |
| 54 | result: unwrap(c: resultType), |
| 55 | arguments: unwrapList(size: nArgumentTypes, first: argumentTypes, storage&: argumentStorage), isVarArg)); |
| 56 | } |
| 57 | |
| 58 | intptr_t mlirLLVMFunctionTypeGetNumInputs(MlirType type) { |
| 59 | return llvm::cast<LLVM::LLVMFunctionType>(Val: unwrap(c: type)).getNumParams(); |
| 60 | } |
| 61 | |
| 62 | MlirType mlirLLVMFunctionTypeGetInput(MlirType type, intptr_t pos) { |
| 63 | assert(pos >= 0 && "pos in array must be positive" ); |
| 64 | return wrap(cpp: llvm::cast<LLVM::LLVMFunctionType>(Val: unwrap(c: type)) |
| 65 | .getParamType(i: static_cast<unsigned>(pos))); |
| 66 | } |
| 67 | |
| 68 | MlirType mlirLLVMFunctionTypeGetReturnType(MlirType type) { |
| 69 | return wrap(cpp: llvm::cast<LLVM::LLVMFunctionType>(Val: unwrap(c: type)).getReturnType()); |
| 70 | } |
| 71 | |
| 72 | bool mlirTypeIsALLVMStructType(MlirType type) { |
| 73 | return isa<LLVM::LLVMStructType>(Val: unwrap(c: type)); |
| 74 | } |
| 75 | |
| 76 | bool mlirLLVMStructTypeIsLiteral(MlirType type) { |
| 77 | return !cast<LLVM::LLVMStructType>(Val: unwrap(c: type)).isIdentified(); |
| 78 | } |
| 79 | |
| 80 | intptr_t mlirLLVMStructTypeGetNumElementTypes(MlirType type) { |
| 81 | return cast<LLVM::LLVMStructType>(Val: unwrap(c: type)).getBody().size(); |
| 82 | } |
| 83 | |
| 84 | MlirType mlirLLVMStructTypeGetElementType(MlirType type, intptr_t position) { |
| 85 | return wrap(cpp: cast<LLVM::LLVMStructType>(Val: unwrap(c: type)).getBody()[position]); |
| 86 | } |
| 87 | |
| 88 | bool mlirLLVMStructTypeIsPacked(MlirType type) { |
| 89 | return cast<LLVM::LLVMStructType>(Val: unwrap(c: type)).isPacked(); |
| 90 | } |
| 91 | |
| 92 | MlirStringRef mlirLLVMStructTypeGetIdentifier(MlirType type) { |
| 93 | return wrap(ref: cast<LLVM::LLVMStructType>(Val: unwrap(c: type)).getName()); |
| 94 | } |
| 95 | |
| 96 | bool mlirLLVMStructTypeIsOpaque(MlirType type) { |
| 97 | return cast<LLVM::LLVMStructType>(Val: unwrap(c: type)).isOpaque(); |
| 98 | } |
| 99 | |
| 100 | MlirType mlirLLVMStructTypeLiteralGet(MlirContext ctx, intptr_t nFieldTypes, |
| 101 | MlirType const *fieldTypes, |
| 102 | bool isPacked) { |
| 103 | SmallVector<Type> fieldStorage; |
| 104 | return wrap(cpp: LLVMStructType::getLiteral( |
| 105 | context: unwrap(c: ctx), types: unwrapList(size: nFieldTypes, first: fieldTypes, storage&: fieldStorage), |
| 106 | isPacked)); |
| 107 | } |
| 108 | |
| 109 | MlirType mlirLLVMStructTypeLiteralGetChecked(MlirLocation loc, |
| 110 | intptr_t nFieldTypes, |
| 111 | MlirType const *fieldTypes, |
| 112 | bool isPacked) { |
| 113 | SmallVector<Type> fieldStorage; |
| 114 | return wrap(cpp: LLVMStructType::getLiteralChecked( |
| 115 | emitError: [loc]() { return emitError(loc: unwrap(c: loc)); }, context: unwrap(c: loc)->getContext(), |
| 116 | types: unwrapList(size: nFieldTypes, first: fieldTypes, storage&: fieldStorage), isPacked)); |
| 117 | } |
| 118 | |
| 119 | MlirType mlirLLVMStructTypeOpaqueGet(MlirContext ctx, MlirStringRef name) { |
| 120 | return wrap(cpp: LLVMStructType::getOpaque(name: unwrap(ref: name), context: unwrap(c: ctx))); |
| 121 | } |
| 122 | |
| 123 | MlirType mlirLLVMStructTypeIdentifiedGet(MlirContext ctx, MlirStringRef name) { |
| 124 | return wrap(cpp: LLVMStructType::getIdentified(context: unwrap(c: ctx), name: unwrap(ref: name))); |
| 125 | } |
| 126 | |
| 127 | MlirType mlirLLVMStructTypeIdentifiedNewGet(MlirContext ctx, MlirStringRef name, |
| 128 | intptr_t nFieldTypes, |
| 129 | MlirType const *fieldTypes, |
| 130 | bool isPacked) { |
| 131 | SmallVector<Type> fields; |
| 132 | return wrap(cpp: LLVMStructType::getNewIdentified( |
| 133 | context: unwrap(c: ctx), name: unwrap(ref: name), elements: unwrapList(size: nFieldTypes, first: fieldTypes, storage&: fields), |
| 134 | isPacked)); |
| 135 | } |
| 136 | |
| 137 | MlirLogicalResult mlirLLVMStructTypeSetBody(MlirType structType, |
| 138 | intptr_t nFieldTypes, |
| 139 | MlirType const *fieldTypes, |
| 140 | bool isPacked) { |
| 141 | SmallVector<Type> fields; |
| 142 | return wrap( |
| 143 | res: cast<LLVM::LLVMStructType>(Val: unwrap(c: structType)) |
| 144 | .setBody(types: unwrapList(size: nFieldTypes, first: fieldTypes, storage&: fields), isPacked)); |
| 145 | } |
| 146 | |
| 147 | MlirAttribute mlirLLVMDIExpressionElemAttrGet(MlirContext ctx, |
| 148 | unsigned int opcode, |
| 149 | intptr_t nArguments, |
| 150 | uint64_t const *arguments) { |
| 151 | auto list = ArrayRef<uint64_t>(arguments, nArguments); |
| 152 | return wrap(cpp: DIExpressionElemAttr::get(context: unwrap(c: ctx), opcode, arguments: list)); |
| 153 | } |
| 154 | |
| 155 | MlirAttribute mlirLLVMDIExpressionAttrGet(MlirContext ctx, intptr_t nOperations, |
| 156 | MlirAttribute const *operations) { |
| 157 | SmallVector<Attribute> attrStorage; |
| 158 | attrStorage.reserve(N: nOperations); |
| 159 | |
| 160 | return wrap(cpp: DIExpressionAttr::get( |
| 161 | context: unwrap(c: ctx), |
| 162 | operations: llvm::map_to_vector( |
| 163 | C: unwrapList(size: nOperations, first: operations, storage&: attrStorage), |
| 164 | F: [](Attribute a) { return cast<DIExpressionElemAttr>(Val&: a); }))); |
| 165 | } |
| 166 | |
| 167 | MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx) { |
| 168 | return wrap(cpp: DINullTypeAttr::get(ctx: unwrap(c: ctx))); |
| 169 | } |
| 170 | |
| 171 | MlirAttribute mlirLLVMDIBasicTypeAttrGet(MlirContext ctx, unsigned int tag, |
| 172 | MlirAttribute name, |
| 173 | uint64_t sizeInBits, |
| 174 | MlirLLVMTypeEncoding encoding) { |
| 175 | |
| 176 | return wrap(cpp: DIBasicTypeAttr::get( |
| 177 | context: unwrap(c: ctx), tag, name: cast<StringAttr>(Val: unwrap(c: name)), sizeInBits, encoding)); |
| 178 | } |
| 179 | |
| 180 | MlirAttribute mlirLLVMDICompositeTypeAttrGetRecSelf(MlirAttribute recId) { |
| 181 | return wrap( |
| 182 | cpp: DICompositeTypeAttr::getRecSelf(recId: cast<DistinctAttr>(Val: unwrap(c: recId)))); |
| 183 | } |
| 184 | |
| 185 | MlirAttribute mlirLLVMDICompositeTypeAttrGet( |
| 186 | MlirContext ctx, MlirAttribute recId, bool isRecSelf, unsigned int tag, |
| 187 | MlirAttribute name, MlirAttribute file, uint32_t line, MlirAttribute scope, |
| 188 | MlirAttribute baseType, int64_t flags, uint64_t sizeInBits, |
| 189 | uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements, |
| 190 | MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated, |
| 191 | MlirAttribute associated) { |
| 192 | SmallVector<Attribute> elementsStorage; |
| 193 | elementsStorage.reserve(N: nElements); |
| 194 | |
| 195 | return wrap(cpp: DICompositeTypeAttr::get( |
| 196 | context: unwrap(c: ctx), recId: cast<DistinctAttr>(Val: unwrap(c: recId)), isRecSelf, tag, |
| 197 | name: cast<StringAttr>(Val: unwrap(c: name)), file: cast<DIFileAttr>(Val: unwrap(c: file)), line, |
| 198 | scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), baseType: cast<DITypeAttr>(Val: unwrap(c: baseType)), |
| 199 | flags: DIFlags(flags), sizeInBits, alignInBits, |
| 200 | elements: llvm::map_to_vector(C: unwrapList(size: nElements, first: elements, storage&: elementsStorage), |
| 201 | F: [](Attribute a) { return cast<DINodeAttr>(Val&: a); }), |
| 202 | dataLocation: cast<DIExpressionAttr>(Val: unwrap(c: dataLocation)), |
| 203 | rank: cast<DIExpressionAttr>(Val: unwrap(c: rank)), |
| 204 | allocated: cast<DIExpressionAttr>(Val: unwrap(c: allocated)), |
| 205 | associated: cast<DIExpressionAttr>(Val: unwrap(c: associated)))); |
| 206 | } |
| 207 | |
| 208 | MlirAttribute mlirLLVMDIDerivedTypeAttrGet( |
| 209 | MlirContext ctx, unsigned int tag, MlirAttribute name, |
| 210 | MlirAttribute baseType, uint64_t sizeInBits, uint32_t alignInBits, |
| 211 | uint64_t offsetInBits, int64_t dwarfAddressSpace, MlirAttribute ) { |
| 212 | std::optional<unsigned> addressSpace = std::nullopt; |
| 213 | if (dwarfAddressSpace >= 0) |
| 214 | addressSpace = (unsigned)dwarfAddressSpace; |
| 215 | return wrap(cpp: DIDerivedTypeAttr::get( |
| 216 | context: unwrap(c: ctx), tag, name: cast<StringAttr>(Val: unwrap(c: name)), |
| 217 | baseType: cast<DITypeAttr>(Val: unwrap(c: baseType)), sizeInBits, alignInBits, offsetInBits, |
| 218 | dwarfAddressSpace: addressSpace, extraData: cast<DINodeAttr>(Val: unwrap(c: extraData)))); |
| 219 | } |
| 220 | |
| 221 | MlirAttribute mlirLLVMDIStringTypeAttrGet( |
| 222 | MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits, |
| 223 | uint32_t alignInBits, MlirAttribute stringLength, |
| 224 | MlirAttribute stringLengthExp, MlirAttribute stringLocationExp, |
| 225 | MlirLLVMTypeEncoding encoding) { |
| 226 | return wrap(cpp: DIStringTypeAttr::get( |
| 227 | context: unwrap(c: ctx), tag, name: cast<StringAttr>(Val: unwrap(c: name)), sizeInBits, alignInBits, |
| 228 | stringLength: cast<DIVariableAttr>(Val: unwrap(c: stringLength)), |
| 229 | stringLengthExp: cast<DIExpressionAttr>(Val: unwrap(c: stringLengthExp)), |
| 230 | stringLocationExp: cast<DIExpressionAttr>(Val: unwrap(c: stringLocationExp)), encoding)); |
| 231 | } |
| 232 | |
| 233 | MlirAttribute |
| 234 | mlirLLVMDIDerivedTypeAttrGetBaseType(MlirAttribute diDerivedType) { |
| 235 | return wrap(cpp: cast<DIDerivedTypeAttr>(Val: unwrap(c: diDerivedType)).getBaseType()); |
| 236 | } |
| 237 | |
| 238 | MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx, MlirLLVMCConv cconv) { |
| 239 | return wrap(cpp: CConvAttr::get(context: unwrap(c: ctx), CallingConv: CConv(cconv))); |
| 240 | } |
| 241 | |
| 242 | MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx, MlirLLVMComdat comdat) { |
| 243 | return wrap(cpp: ComdatAttr::get(context: unwrap(c: ctx), comdat: comdat::Comdat(comdat))); |
| 244 | } |
| 245 | |
| 246 | MlirAttribute mlirLLVMLinkageAttrGet(MlirContext ctx, MlirLLVMLinkage linkage) { |
| 247 | return wrap(cpp: LinkageAttr::get(context: unwrap(c: ctx), linkage: linkage::Linkage(linkage))); |
| 248 | } |
| 249 | |
| 250 | MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx, MlirAttribute name, |
| 251 | MlirAttribute directory) { |
| 252 | return wrap(cpp: DIFileAttr::get(context: unwrap(c: ctx), name: cast<StringAttr>(Val: unwrap(c: name)), |
| 253 | directory: cast<StringAttr>(Val: unwrap(c: directory)))); |
| 254 | } |
| 255 | |
| 256 | MlirAttribute |
| 257 | mlirLLVMDICompileUnitAttrGet(MlirContext ctx, MlirAttribute id, |
| 258 | unsigned int sourceLanguage, MlirAttribute file, |
| 259 | MlirAttribute producer, bool isOptimized, |
| 260 | MlirLLVMDIEmissionKind emissionKind, |
| 261 | MlirLLVMDINameTableKind nameTableKind) { |
| 262 | return wrap(cpp: DICompileUnitAttr::get( |
| 263 | context: unwrap(c: ctx), id: cast<DistinctAttr>(Val: unwrap(c: id)), sourceLanguage, |
| 264 | file: cast<DIFileAttr>(Val: unwrap(c: file)), producer: cast<StringAttr>(Val: unwrap(c: producer)), |
| 265 | isOptimized, emissionKind: DIEmissionKind(emissionKind), |
| 266 | nameTableKind: DINameTableKind(nameTableKind))); |
| 267 | } |
| 268 | |
| 269 | MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, uint64_t value) { |
| 270 | return wrap(cpp: DIFlagsAttr::get(context: unwrap(c: ctx), val: DIFlags(value))); |
| 271 | } |
| 272 | |
| 273 | MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx, |
| 274 | MlirAttribute scope, |
| 275 | MlirAttribute file, |
| 276 | unsigned int line, |
| 277 | unsigned int column) { |
| 278 | return wrap( |
| 279 | cpp: DILexicalBlockAttr::get(context: unwrap(c: ctx), scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), |
| 280 | file: cast<DIFileAttr>(Val: unwrap(c: file)), line, column)); |
| 281 | } |
| 282 | |
| 283 | MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx, |
| 284 | MlirAttribute scope, |
| 285 | MlirAttribute file, |
| 286 | unsigned int discriminator) { |
| 287 | return wrap(cpp: DILexicalBlockFileAttr::get( |
| 288 | context: unwrap(c: ctx), scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), |
| 289 | file: cast<DIFileAttr>(Val: unwrap(c: file)), discriminator)); |
| 290 | } |
| 291 | |
| 292 | MlirAttribute mlirLLVMDILocalVariableAttrGet( |
| 293 | MlirContext ctx, MlirAttribute scope, MlirAttribute name, |
| 294 | MlirAttribute diFile, unsigned int line, unsigned int arg, |
| 295 | unsigned int alignInBits, MlirAttribute diType, int64_t flags) { |
| 296 | return wrap(cpp: DILocalVariableAttr::get( |
| 297 | context: unwrap(c: ctx), scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), |
| 298 | name: cast<StringAttr>(Val: unwrap(c: name)), file: cast<DIFileAttr>(Val: unwrap(c: diFile)), line, |
| 299 | arg, alignInBits, type: cast<DITypeAttr>(Val: unwrap(c: diType)), flags: DIFlags(flags))); |
| 300 | } |
| 301 | |
| 302 | MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx, |
| 303 | unsigned int callingConvention, |
| 304 | intptr_t nTypes, |
| 305 | MlirAttribute const *types) { |
| 306 | SmallVector<Attribute> attrStorage; |
| 307 | attrStorage.reserve(N: nTypes); |
| 308 | |
| 309 | return wrap(cpp: DISubroutineTypeAttr::get( |
| 310 | context: unwrap(c: ctx), callingConvention, |
| 311 | types: llvm::map_to_vector(C: unwrapList(size: nTypes, first: types, storage&: attrStorage), |
| 312 | F: [](Attribute a) { return cast<DITypeAttr>(Val&: a); }))); |
| 313 | } |
| 314 | |
| 315 | MlirAttribute mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId) { |
| 316 | return wrap(cpp: DISubprogramAttr::getRecSelf(recId: cast<DistinctAttr>(Val: unwrap(c: recId)))); |
| 317 | } |
| 318 | |
| 319 | MlirAttribute mlirLLVMDISubprogramAttrGet( |
| 320 | MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id, |
| 321 | MlirAttribute compileUnit, MlirAttribute scope, MlirAttribute name, |
| 322 | MlirAttribute linkageName, MlirAttribute file, unsigned int line, |
| 323 | unsigned int scopeLine, uint64_t subprogramFlags, MlirAttribute type, |
| 324 | intptr_t nRetainedNodes, MlirAttribute const *retainedNodes, |
| 325 | intptr_t nAnnotations, MlirAttribute const *annotations) { |
| 326 | SmallVector<Attribute> nodesStorage; |
| 327 | nodesStorage.reserve(N: nRetainedNodes); |
| 328 | |
| 329 | SmallVector<Attribute> annotationsStorage; |
| 330 | annotationsStorage.reserve(N: nAnnotations); |
| 331 | |
| 332 | return wrap(cpp: DISubprogramAttr::get( |
| 333 | context: unwrap(c: ctx), recId: cast<DistinctAttr>(Val: unwrap(c: recId)), isRecSelf, |
| 334 | id: cast<DistinctAttr>(Val: unwrap(c: id)), |
| 335 | compileUnit: cast<DICompileUnitAttr>(Val: unwrap(c: compileUnit)), |
| 336 | scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), name: cast<StringAttr>(Val: unwrap(c: name)), |
| 337 | linkageName: cast<StringAttr>(Val: unwrap(c: linkageName)), file: cast<DIFileAttr>(Val: unwrap(c: file)), |
| 338 | line, scopeLine, subprogramFlags: DISubprogramFlags(subprogramFlags), |
| 339 | type: cast<DISubroutineTypeAttr>(Val: unwrap(c: type)), |
| 340 | retainedNodes: llvm::map_to_vector( |
| 341 | C: unwrapList(size: nRetainedNodes, first: retainedNodes, storage&: nodesStorage), |
| 342 | F: [](Attribute a) { return cast<DINodeAttr>(Val&: a); }), |
| 343 | annotations: llvm::map_to_vector( |
| 344 | C: unwrapList(size: nAnnotations, first: annotations, storage&: annotationsStorage), |
| 345 | F: [](Attribute a) { return cast<DINodeAttr>(Val&: a); }))); |
| 346 | } |
| 347 | |
| 348 | MlirAttribute mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram) { |
| 349 | return wrap(cpp: cast<DISubprogramAttr>(Val: unwrap(c: diSubprogram)).getScope()); |
| 350 | } |
| 351 | |
| 352 | unsigned int mlirLLVMDISubprogramAttrGetLine(MlirAttribute diSubprogram) { |
| 353 | return cast<DISubprogramAttr>(Val: unwrap(c: diSubprogram)).getLine(); |
| 354 | } |
| 355 | |
| 356 | unsigned int mlirLLVMDISubprogramAttrGetScopeLine(MlirAttribute diSubprogram) { |
| 357 | return cast<DISubprogramAttr>(Val: unwrap(c: diSubprogram)).getScopeLine(); |
| 358 | } |
| 359 | |
| 360 | MlirAttribute |
| 361 | mlirLLVMDISubprogramAttrGetCompileUnit(MlirAttribute diSubprogram) { |
| 362 | return wrap(cpp: cast<DISubprogramAttr>(Val: unwrap(c: diSubprogram)).getCompileUnit()); |
| 363 | } |
| 364 | |
| 365 | MlirAttribute mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram) { |
| 366 | return wrap(cpp: cast<DISubprogramAttr>(Val: unwrap(c: diSubprogram)).getFile()); |
| 367 | } |
| 368 | |
| 369 | MlirAttribute mlirLLVMDISubprogramAttrGetType(MlirAttribute diSubprogram) { |
| 370 | return wrap(cpp: cast<DISubprogramAttr>(Val: unwrap(c: diSubprogram)).getType()); |
| 371 | } |
| 372 | |
| 373 | MlirAttribute mlirLLVMDIModuleAttrGet(MlirContext ctx, MlirAttribute file, |
| 374 | MlirAttribute scope, MlirAttribute name, |
| 375 | MlirAttribute configMacros, |
| 376 | MlirAttribute includePath, |
| 377 | MlirAttribute apinotes, unsigned int line, |
| 378 | bool isDecl) { |
| 379 | return wrap(cpp: DIModuleAttr::get( |
| 380 | context: unwrap(c: ctx), file: cast<DIFileAttr>(Val: unwrap(c: file)), |
| 381 | scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), name: cast<StringAttr>(Val: unwrap(c: name)), |
| 382 | configMacros: cast<StringAttr>(Val: unwrap(c: configMacros)), |
| 383 | includePath: cast<StringAttr>(Val: unwrap(c: includePath)), apinotes: cast<StringAttr>(Val: unwrap(c: apinotes)), |
| 384 | line, isDecl)); |
| 385 | } |
| 386 | |
| 387 | MlirAttribute mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule) { |
| 388 | return wrap(cpp: cast<DIModuleAttr>(Val: unwrap(c: diModule)).getScope()); |
| 389 | } |
| 390 | |
| 391 | MlirAttribute mlirLLVMDIImportedEntityAttrGet( |
| 392 | MlirContext ctx, unsigned int tag, MlirAttribute scope, |
| 393 | MlirAttribute entity, MlirAttribute file, unsigned int line, |
| 394 | MlirAttribute name, intptr_t nElements, MlirAttribute const *elements) { |
| 395 | SmallVector<Attribute> elementsStorage; |
| 396 | elementsStorage.reserve(N: nElements); |
| 397 | return wrap(cpp: DIImportedEntityAttr::get( |
| 398 | context: unwrap(c: ctx), tag, scope: cast<DIScopeAttr>(Val: unwrap(c: scope)), |
| 399 | entity: cast<DINodeAttr>(Val: unwrap(c: entity)), file: cast<DIFileAttr>(Val: unwrap(c: file)), line, |
| 400 | name: cast<StringAttr>(Val: unwrap(c: name)), |
| 401 | elements: llvm::map_to_vector(C: unwrapList(size: nElements, first: elements, storage&: elementsStorage), |
| 402 | F: [](Attribute a) { return cast<DINodeAttr>(Val&: a); }))); |
| 403 | } |
| 404 | |
| 405 | MlirAttribute mlirLLVMDIAnnotationAttrGet(MlirContext ctx, MlirAttribute name, |
| 406 | MlirAttribute value) { |
| 407 | return wrap(cpp: DIAnnotationAttr::get(context: unwrap(c: ctx), name: cast<StringAttr>(Val: unwrap(c: name)), |
| 408 | value: cast<StringAttr>(Val: unwrap(c: value)))); |
| 409 | } |
| 410 | |