MLIR 23.0.0git
LLVM.cpp
Go to the documentation of this file.
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
10#include "mlir-c/IR.h"
11#include "mlir-c/Support.h"
13#include "mlir/CAPI/Wrap.h"
17#include "llvm-c/Core.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/ADT/SmallVectorExtras.h"
20
21using namespace mlir;
22using namespace mlir::LLVM;
23
25
26MlirType mlirLLVMPointerTypeGet(MlirContext ctx, unsigned addressSpace) {
27 return wrap(LLVMPointerType::get(unwrap(ctx), addressSpace));
28}
29
31 return wrap(LLVM::LLVMPointerType::name);
32}
33
35 return wrap(LLVM::LLVMPointerType::getTypeID());
36}
37
38bool mlirTypeIsALLVMPointerType(MlirType type) {
39 return isa<LLVM::LLVMPointerType>(unwrap(type));
40}
41
42unsigned mlirLLVMPointerTypeGetAddressSpace(MlirType pointerType) {
43 return cast<LLVM::LLVMPointerType>(unwrap(pointerType)).getAddressSpace();
44}
45
46MlirType mlirLLVMVoidTypeGet(MlirContext ctx) {
47 return wrap(LLVMVoidType::get(unwrap(ctx)));
48}
49
50MlirStringRef mlirLLVMVoidTypeGetName(void) { return wrap(LLVMVoidType::name); }
51
52bool mlirTypeIsALLVMArrayType(MlirType type) {
53 return isa<LLVM::LLVMArrayType>(unwrap(type));
54}
55
57 return wrap(LLVM::LLVMArrayType::getTypeID());
58}
59
60MlirType mlirLLVMArrayTypeGet(MlirType elementType, unsigned numElements) {
61 return wrap(LLVMArrayType::get(unwrap(elementType), numElements));
62}
63
65 return wrap(LLVMArrayType::name);
66}
67
68MlirType mlirLLVMArrayTypeGetElementType(MlirType type) {
69 return wrap(cast<LLVM::LLVMArrayType>(unwrap(type)).getElementType());
70}
71
72unsigned mlirLLVMArrayTypeGetNumElements(MlirType type) {
73 return cast<LLVM::LLVMArrayType>(unwrap(type)).getNumElements();
74}
75
76MlirType mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes,
77 MlirType const *argumentTypes, bool isVarArg) {
78 SmallVector<Type, 2> argumentStorage;
79 return wrap(LLVMFunctionType::get(
80 unwrap(resultType),
81 unwrapList(nArgumentTypes, argumentTypes, argumentStorage), isVarArg));
82}
83
85 return wrap(LLVMFunctionType::name);
86}
87
88bool mlirTypeIsALLVMFunctionType(MlirType type) {
89 return isa<LLVM::LLVMFunctionType>(unwrap(type));
90}
91
93 return wrap(LLVM::LLVMFunctionType::getTypeID());
94}
95
97 return llvm::cast<LLVM::LLVMFunctionType>(unwrap(type)).getNumParams();
98}
99
100MlirType mlirLLVMFunctionTypeGetInput(MlirType type, intptr_t pos) {
101 assert(pos >= 0 && "pos in array must be positive");
102 return wrap(llvm::cast<LLVM::LLVMFunctionType>(unwrap(type))
103 .getParamType(static_cast<unsigned>(pos)));
104}
105
106MlirType mlirLLVMFunctionTypeGetReturnType(MlirType type) {
107 return wrap(llvm::cast<LLVM::LLVMFunctionType>(unwrap(type)).getReturnType());
108}
109
110bool mlirLLVMFunctionTypeIsVarArg(MlirType type) {
111 return llvm::cast<LLVM::LLVMFunctionType>(unwrap(type)).isVarArg();
112}
113
114bool mlirTypeIsALLVMStructType(MlirType type) {
115 return isa<LLVM::LLVMStructType>(unwrap(type));
116}
117
119 return wrap(LLVM::LLVMStructType::getTypeID());
120}
121
123 return wrap(LLVM::LLVMStructType::name);
124}
125
126bool mlirLLVMStructTypeIsLiteral(MlirType type) {
127 return !cast<LLVM::LLVMStructType>(unwrap(type)).isIdentified();
128}
129
131 return cast<LLVM::LLVMStructType>(unwrap(type)).getBody().size();
132}
133
134MlirType mlirLLVMStructTypeGetElementType(MlirType type, intptr_t position) {
135 return wrap(cast<LLVM::LLVMStructType>(unwrap(type)).getBody()[position]);
136}
137
138bool mlirLLVMStructTypeIsPacked(MlirType type) {
139 return cast<LLVM::LLVMStructType>(unwrap(type)).isPacked();
140}
141
143 return wrap(cast<LLVM::LLVMStructType>(unwrap(type)).getName());
144}
145
146bool mlirLLVMStructTypeIsOpaque(MlirType type) {
147 return cast<LLVM::LLVMStructType>(unwrap(type)).isOpaque();
148}
149
150MlirType mlirLLVMStructTypeLiteralGet(MlirContext ctx, intptr_t nFieldTypes,
151 MlirType const *fieldTypes,
152 bool isPacked) {
153 SmallVector<Type> fieldStorage;
154 return wrap(LLVMStructType::getLiteral(
155 unwrap(ctx), unwrapList(nFieldTypes, fieldTypes, fieldStorage),
156 isPacked));
157}
158
159MlirType mlirLLVMStructTypeLiteralGetChecked(MlirLocation loc,
160 intptr_t nFieldTypes,
161 MlirType const *fieldTypes,
162 bool isPacked) {
163 SmallVector<Type> fieldStorage;
164 return wrap(LLVMStructType::getLiteralChecked(
165 [loc]() { return emitError(unwrap(loc)); }, unwrap(loc)->getContext(),
166 unwrapList(nFieldTypes, fieldTypes, fieldStorage), isPacked));
167}
168
169MlirType mlirLLVMStructTypeOpaqueGet(MlirContext ctx, MlirStringRef name) {
170 return wrap(LLVMStructType::getOpaque(unwrap(name), unwrap(ctx)));
171}
172
173MlirType mlirLLVMStructTypeIdentifiedGet(MlirContext ctx, MlirStringRef name) {
174 return wrap(LLVMStructType::getIdentified(unwrap(ctx), unwrap(name)));
175}
176
178 intptr_t nFieldTypes,
179 MlirType const *fieldTypes,
180 bool isPacked) {
181 SmallVector<Type> fields;
182 return wrap(LLVMStructType::getNewIdentified(
183 unwrap(ctx), unwrap(name), unwrapList(nFieldTypes, fieldTypes, fields),
184 isPacked));
185}
186
188 intptr_t nFieldTypes,
189 MlirType const *fieldTypes,
190 bool isPacked) {
191 SmallVector<Type> fields;
192 return wrap(
193 cast<LLVM::LLVMStructType>(unwrap(structType))
194 .setBody(unwrapList(nFieldTypes, fieldTypes, fields), isPacked));
195}
196
197MlirAttribute 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(DIExpressionElemAttr::get(unwrap(ctx), opcode, list));
203}
204
206 return wrap(DIExpressionElemAttr::name);
207}
208
209MlirAttribute mlirLLVMDIExpressionAttrGet(MlirContext ctx, intptr_t nOperations,
210 MlirAttribute const *operations) {
211 SmallVector<Attribute> attrStorage;
212 attrStorage.reserve(nOperations);
213
214 return wrap(DIExpressionAttr::get(
215 unwrap(ctx),
216 llvm::map_to_vector(unwrapList(nOperations, operations, attrStorage),
217 llvm::CastTo<DIExpressionElemAttr>)));
218}
219
221 return wrap(DIExpressionAttr::name);
222}
223
224MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx) {
225 return wrap(DINullTypeAttr::get(unwrap(ctx)));
226}
227
229 return wrap(DINullTypeAttr::name);
230}
231
232MlirAttribute mlirLLVMDIBasicTypeAttrGet(MlirContext ctx, unsigned int tag,
233 MlirAttribute name,
234 uint64_t sizeInBits,
235 MlirLLVMTypeEncoding encoding) {
236
237 return wrap(DIBasicTypeAttr::get(
238 unwrap(ctx), tag, cast<StringAttr>(unwrap(name)), sizeInBits, encoding));
239}
240
242 return wrap(DIBasicTypeAttr::name);
243}
244
245MlirAttribute mlirLLVMDICompositeTypeAttrGetRecSelf(MlirAttribute recId) {
246 return wrap(
247 DICompositeTypeAttr::getRecSelf(cast<DistinctAttr>(unwrap(recId))));
248}
249
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) {
257 SmallVector<Attribute> elementsStorage;
258 elementsStorage.reserve(nElements);
259
260 return wrap(DICompositeTypeAttr::get(
261 unwrap(ctx), cast<DistinctAttr>(unwrap(recId)), isRecSelf, tag,
262 cast<StringAttr>(unwrap(name)), cast<DIFileAttr>(unwrap(file)), line,
263 cast<DIScopeAttr>(unwrap(scope)), cast<DITypeAttr>(unwrap(baseType)),
264 DIFlags(flags), sizeInBits, alignInBits,
265 cast<DIExpressionAttr>(unwrap(dataLocation)),
266 cast<DIExpressionAttr>(unwrap(rank)),
267 cast<DIExpressionAttr>(unwrap(allocated)),
268 cast<DIExpressionAttr>(unwrap(associated)),
269 llvm::map_to_vector(unwrapList(nElements, elements, elementsStorage),
270 llvm::CastTo<DINodeAttr>)));
271}
272
274 return wrap(DICompositeTypeAttr::name);
275}
276
278 MlirContext ctx, unsigned int tag, MlirAttribute name, MlirAttribute file,
279 uint32_t line, MlirAttribute scope, MlirAttribute baseType,
280 uint64_t sizeInBits, uint32_t alignInBits, uint64_t offsetInBits,
281 int64_t dwarfAddressSpace, int64_t flags, MlirAttribute extraData) {
282 std::optional<unsigned> addressSpace = std::nullopt;
283 if (dwarfAddressSpace >= 0)
284 addressSpace = (unsigned)dwarfAddressSpace;
285 return wrap(DIDerivedTypeAttr::get(
286 unwrap(ctx), tag, cast<StringAttr>(unwrap(name)),
287 cast<DIFileAttr>(unwrap(file)), line, cast<DIScopeAttr>(unwrap(scope)),
288 cast<DITypeAttr>(unwrap(baseType)), sizeInBits, alignInBits, offsetInBits,
289 addressSpace, DIFlags(flags), cast<DINodeAttr>(unwrap(extraData))));
290}
291
293 return wrap(DIDerivedTypeAttr::name);
294}
295
297 MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits,
298 uint32_t alignInBits, MlirAttribute stringLength,
299 MlirAttribute stringLengthExp, MlirAttribute stringLocationExp,
300 MlirLLVMTypeEncoding encoding) {
301 return wrap(DIStringTypeAttr::get(
302 unwrap(ctx), tag, cast<StringAttr>(unwrap(name)), sizeInBits, alignInBits,
303 cast<DIVariableAttr>(unwrap(stringLength)),
304 cast<DIExpressionAttr>(unwrap(stringLengthExp)),
305 cast<DIExpressionAttr>(unwrap(stringLocationExp)), encoding));
306}
307
309 return wrap(DIStringTypeAttr::name);
310}
311
312MlirAttribute
313mlirLLVMDIDerivedTypeAttrGetBaseType(MlirAttribute diDerivedType) {
314 return wrap(cast<DIDerivedTypeAttr>(unwrap(diDerivedType)).getBaseType());
315}
316
317MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx, MlirLLVMCConv cconv) {
318 return wrap(CConvAttr::get(unwrap(ctx), CConv(cconv)));
319}
320
321MlirStringRef mlirLLVMCConvAttrGetName(void) { return wrap(CConvAttr::name); }
322
323MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx, MlirLLVMComdat comdat) {
324 return wrap(ComdatAttr::get(unwrap(ctx), comdat::Comdat(comdat)));
325}
326
327MlirStringRef mlirLLVMComdatAttrGetName(void) { return wrap(ComdatAttr::name); }
328
329MlirAttribute mlirLLVMLinkageAttrGet(MlirContext ctx, MlirLLVMLinkage linkage) {
330 return wrap(LinkageAttr::get(unwrap(ctx), linkage::Linkage(linkage)));
331}
332
334 return wrap(LinkageAttr::name);
335}
336
337MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx, MlirAttribute name,
338 MlirAttribute directory) {
339 return wrap(DIFileAttr::get(unwrap(ctx), cast<StringAttr>(unwrap(name)),
340 cast<StringAttr>(unwrap(directory))));
341}
342
343MlirStringRef mlirLLVMDIFileAttrGetName(void) { return wrap(DIFileAttr::name); }
344
345MlirAttribute mlirLLVMDICompileUnitAttrGetRecSelf(MlirAttribute recId) {
346 return wrap(DICompileUnitAttr::getRecSelf(cast<DistinctAttr>(unwrap(recId))));
347}
348
350 MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,
351 unsigned int sourceLanguage, MlirAttribute file, MlirAttribute producer,
352 bool isOptimized, MlirLLVMDIEmissionKind emissionKind,
353 bool isDebugInfoForProfiling, MlirLLVMDINameTableKind nameTableKind,
354 MlirAttribute splitDebugFilename, intptr_t nImportedEntities,
355 MlirAttribute const *importedEntities) {
356 SmallVector<Attribute> importsStorage;
357 importsStorage.reserve(nImportedEntities);
358 return wrap(DICompileUnitAttr::get(
359 unwrap(ctx), cast<DistinctAttr>(unwrap(recId)), isRecSelf,
360 cast<DistinctAttr>(unwrap(id)), sourceLanguage,
361 cast<DIFileAttr>(unwrap(file)), cast<StringAttr>(unwrap(producer)),
362 isOptimized, DIEmissionKind(emissionKind), isDebugInfoForProfiling,
363 DINameTableKind(nameTableKind),
364 cast<StringAttr>(unwrap(splitDebugFilename)),
365 llvm::map_to_vector(
366 unwrapList(nImportedEntities, importedEntities, importsStorage),
367 llvm::CastTo<DINodeAttr>)));
368}
369
371 return wrap(DICompileUnitAttr::name);
372}
373
374MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, uint64_t value) {
375 return wrap(DIFlagsAttr::get(unwrap(ctx), DIFlags(value)));
376}
377
379 return wrap(DIFlagsAttr::name);
380}
381
382MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx,
383 MlirAttribute scope,
384 MlirAttribute file,
385 unsigned int line,
386 unsigned int column) {
387 return wrap(
388 DILexicalBlockAttr::get(unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
389 cast<DIFileAttr>(unwrap(file)), line, column));
390}
391
393 return wrap(DILexicalBlockAttr::name);
394}
395
396MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx,
397 MlirAttribute scope,
398 MlirAttribute file,
399 unsigned int discriminator) {
400 return wrap(DILexicalBlockFileAttr::get(
401 unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
402 cast<DIFileAttr>(unwrap(file)), discriminator));
403}
404
406 return wrap(DILexicalBlockFileAttr::name);
407}
408
410 MlirContext ctx, MlirAttribute scope, MlirAttribute name,
411 MlirAttribute diFile, unsigned int line, unsigned int arg,
412 unsigned int alignInBits, MlirAttribute diType, int64_t flags) {
413 return wrap(DILocalVariableAttr::get(
414 unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
415 cast<StringAttr>(unwrap(name)), cast<DIFileAttr>(unwrap(diFile)), line,
416 arg, alignInBits, cast<DITypeAttr>(unwrap(diType)), DIFlags(flags)));
417}
418
420 return wrap(DILocalVariableAttr::name);
421}
422
423MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx,
424 unsigned int callingConvention,
425 intptr_t nTypes,
426 MlirAttribute const *types) {
427 SmallVector<Attribute> attrStorage;
428 attrStorage.reserve(nTypes);
429
430 return wrap(DISubroutineTypeAttr::get(
431 unwrap(ctx), callingConvention,
432 llvm::map_to_vector(unwrapList(nTypes, types, attrStorage),
433 llvm::CastTo<DITypeAttr>)));
434}
435
437 return wrap(DISubroutineTypeAttr::name);
438}
439
440MlirAttribute mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId) {
441 return wrap(DISubprogramAttr::getRecSelf(cast<DistinctAttr>(unwrap(recId))));
442}
443
445 MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,
446 MlirAttribute compileUnit, MlirAttribute scope, MlirAttribute name,
447 MlirAttribute linkageName, MlirAttribute file, unsigned int line,
448 unsigned int scopeLine, uint64_t subprogramFlags, MlirAttribute type,
449 intptr_t nRetainedNodes, MlirAttribute const *retainedNodes,
450 intptr_t nAnnotations, MlirAttribute const *annotations) {
451 SmallVector<Attribute> nodesStorage;
452 nodesStorage.reserve(nRetainedNodes);
453
454 SmallVector<Attribute> annotationsStorage;
455 annotationsStorage.reserve(nAnnotations);
456
457 return wrap(DISubprogramAttr::get(
458 unwrap(ctx), cast<DistinctAttr>(unwrap(recId)), isRecSelf,
459 cast<DistinctAttr>(unwrap(id)),
460 cast<DICompileUnitAttr>(unwrap(compileUnit)),
461 cast<DIScopeAttr>(unwrap(scope)), cast<StringAttr>(unwrap(name)),
462 cast<StringAttr>(unwrap(linkageName)), cast<DIFileAttr>(unwrap(file)),
463 line, scopeLine, DISubprogramFlags(subprogramFlags),
464 cast<DISubroutineTypeAttr>(unwrap(type)),
465 llvm::map_to_vector(
466 unwrapList(nRetainedNodes, retainedNodes, nodesStorage),
467 llvm::CastTo<DINodeAttr>),
468 llvm::map_to_vector(
469 unwrapList(nAnnotations, annotations, annotationsStorage),
470 llvm::CastTo<DINodeAttr>)));
471}
472
474 return wrap(DISubprogramAttr::name);
475}
476
477MlirAttribute mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram) {
478 return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getScope());
479}
480
481unsigned int mlirLLVMDISubprogramAttrGetLine(MlirAttribute diSubprogram) {
482 return cast<DISubprogramAttr>(unwrap(diSubprogram)).getLine();
483}
484
485unsigned int mlirLLVMDISubprogramAttrGetScopeLine(MlirAttribute diSubprogram) {
486 return cast<DISubprogramAttr>(unwrap(diSubprogram)).getScopeLine();
487}
488
489MlirAttribute
490mlirLLVMDISubprogramAttrGetCompileUnit(MlirAttribute diSubprogram) {
491 return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getCompileUnit());
492}
493
494MlirAttribute mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram) {
495 return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getFile());
496}
497
498MlirAttribute mlirLLVMDISubprogramAttrGetType(MlirAttribute diSubprogram) {
499 return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getType());
500}
501
502MlirAttribute mlirLLVMDIModuleAttrGet(MlirContext ctx, MlirAttribute file,
503 MlirAttribute scope, MlirAttribute name,
504 MlirAttribute configMacros,
505 MlirAttribute includePath,
506 MlirAttribute apinotes, unsigned int line,
507 bool isDecl) {
508 return wrap(DIModuleAttr::get(
509 unwrap(ctx), cast<DIFileAttr>(unwrap(file)),
510 cast<DIScopeAttr>(unwrap(scope)), cast<StringAttr>(unwrap(name)),
511 cast<StringAttr>(unwrap(configMacros)),
512 cast<StringAttr>(unwrap(includePath)), cast<StringAttr>(unwrap(apinotes)),
513 line, isDecl));
514}
515
517 return wrap(DIModuleAttr::name);
518}
519
520MlirAttribute mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule) {
521 return wrap(cast<DIModuleAttr>(unwrap(diModule)).getScope());
522}
523
525 MlirContext ctx, unsigned int tag, MlirAttribute scope,
526 MlirAttribute entity, MlirAttribute file, unsigned int line,
527 MlirAttribute name, intptr_t nElements, MlirAttribute const *elements) {
528 SmallVector<Attribute> elementsStorage;
529 elementsStorage.reserve(nElements);
530 return wrap(DIImportedEntityAttr::get(
531 unwrap(ctx), tag, cast<DIScopeAttr>(unwrap(scope)),
532 cast<DINodeAttr>(unwrap(entity)), cast<DIFileAttr>(unwrap(file)), line,
533 cast<StringAttr>(unwrap(name)),
534 llvm::map_to_vector(unwrapList(nElements, elements, elementsStorage),
535 llvm::CastTo<DINodeAttr>)));
536}
537
539 return wrap(DIImportedEntityAttr::name);
540}
541
542MlirAttribute mlirLLVMDIAnnotationAttrGet(MlirContext ctx, MlirAttribute name,
543 MlirAttribute value) {
544 return wrap(DIAnnotationAttr::get(unwrap(ctx), cast<StringAttr>(unwrap(name)),
545 cast<StringAttr>(unwrap(value))));
546}
547
549 return wrap(DIAnnotationAttr::name);
550}
551
552//===----------------------------------------------------------------------===//
553// Metadata Attributes
554//===----------------------------------------------------------------------===//
555
556MlirAttribute mlirLLVMMDStringAttrGet(MlirContext ctx, MlirStringRef value) {
557 return wrap(MDStringAttr::get(unwrap(ctx),
558 StringAttr::get(unwrap(ctx), unwrap(value))));
559}
560
561bool mlirLLVMAttrIsAMDStringAttr(MlirAttribute attr) {
562 return isa<MDStringAttr>(unwrap(attr));
563}
564
566 return wrap(MDStringAttr::getTypeID());
567}
568
570 return wrap(cast<MDStringAttr>(unwrap(attr)).getValue().getValue());
571}
572
573MlirAttribute mlirLLVMMDConstantAttrGet(MlirContext ctx,
574 MlirAttribute valueAttr) {
575 return wrap(MDConstantAttr::get(unwrap(ctx), unwrap(valueAttr)));
576}
577
578bool mlirLLVMAttrIsAMDConstantAttr(MlirAttribute attr) {
579 return isa<MDConstantAttr>(unwrap(attr));
580}
581
583 return wrap(MDConstantAttr::getTypeID());
584}
585
586MlirAttribute mlirLLVMMDConstantAttrGetValue(MlirAttribute attr) {
587 return wrap((Attribute)cast<MDConstantAttr>(unwrap(attr)).getValue());
588}
589
590MlirAttribute mlirLLVMMDFuncAttrGet(MlirContext ctx, MlirAttribute name) {
591 return wrap(
592 MDFuncAttr::get(unwrap(ctx), cast<FlatSymbolRefAttr>(unwrap(name))));
593}
594
595bool mlirLLVMAttrIsAMDFuncAttr(MlirAttribute attr) {
596 return isa<MDFuncAttr>(unwrap(attr));
597}
598
600 return wrap(MDFuncAttr::getTypeID());
601}
602
603MlirAttribute mlirLLVMMDFuncAttrGetName(MlirAttribute attr) {
604 return wrap((Attribute)cast<MDFuncAttr>(unwrap(attr)).getName());
605}
606
607MlirAttribute mlirLLVMMDNodeAttrGet(MlirContext ctx, intptr_t nOperands,
608 MlirAttribute const *operands) {
609 SmallVector<Attribute> attrStorage;
610 attrStorage.reserve(nOperands);
611 return wrap(MDNodeAttr::get(unwrap(ctx),
612 unwrapList(nOperands, operands, attrStorage)));
613}
614
615bool mlirLLVMAttrIsAMDNodeAttr(MlirAttribute attr) {
616 return isa<MDNodeAttr>(unwrap(attr));
617}
618
620 return wrap(MDNodeAttr::getTypeID());
621}
622
624 return cast<MDNodeAttr>(unwrap(attr)).getOperands().size();
625}
626
627MlirAttribute mlirLLVMMDNodeAttrGetOperand(MlirAttribute attr, intptr_t index) {
628 return wrap(cast<MDNodeAttr>(unwrap(attr)).getOperands()[index]);
629}
static Type getElementType(Type type)
Determine the element type of type.
MlirStringRef mlirLLVMDIFlagsAttrGetName(void)
Definition LLVM.cpp:378
intptr_t mlirLLVMMDNodeAttrGetNumOperands(MlirAttribute attr)
Returns the number of operands in an LLVM MDNodeAttr.
Definition LLVM.cpp:623
MlirStringRef mlirLLVMDIModuleAttrGetName(void)
Definition LLVM.cpp:516
MlirStringRef mlirLLVMDIAnnotationAttrGetName(void)
Definition LLVM.cpp:548
bool mlirLLVMStructTypeIsLiteral(MlirType type)
Returns true if the type is a literal (unnamed) LLVM struct type.
Definition LLVM.cpp:126
MlirAttribute mlirLLVMLinkageAttrGet(MlirContext ctx, MlirLLVMLinkage linkage)
Creates a LLVM Linkage attribute.
Definition LLVM.cpp:329
MlirAttribute mlirLLVMMDFuncAttrGetName(MlirAttribute attr)
Returns the symbol name of an LLVM MDFuncAttr.
Definition LLVM.cpp:603
MlirStringRef mlirLLVMDIImportedEntityAttrGetName(void)
Definition LLVM.cpp:538
MlirTypeID mlirLLVMMDConstantAttrGetTypeID(void)
Returns the TypeID of MDConstantAttr.
Definition LLVM.cpp:582
MlirAttribute mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram)
Gets the file from this DISubprogramAttr.
Definition LLVM.cpp:494
bool mlirLLVMAttrIsAMDConstantAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDConstantAttr.
Definition LLVM.cpp:578
MlirStringRef mlirLLVMDICompileUnitAttrGetName(void)
Definition LLVM.cpp:370
MlirStringRef mlirLLVMMDStringAttrGetValue(MlirAttribute attr)
Returns the string value of an LLVM MDStringAttr.
Definition LLVM.cpp:569
MlirType mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes, MlirType const *argumentTypes, bool isVarArg)
Creates an llvm.func type.
Definition LLVM.cpp:76
MlirAttribute mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule)
Gets the scope of this DIModuleAttr.
Definition LLVM.cpp:520
bool mlirTypeIsALLVMArrayType(MlirType type)
Returns true if the type is an LLVM dialect array type.
Definition LLVM.cpp:52
MlirStringRef mlirLLVMDISubroutineTypeAttrGetName(void)
Definition LLVM.cpp:436
MlirAttribute mlirLLVMMDStringAttrGet(MlirContext ctx, MlirStringRef value)
Creates an LLVM MDStringAttr.
Definition LLVM.cpp:556
MlirType mlirLLVMFunctionTypeGetInput(MlirType type, intptr_t pos)
Returns the pos-th input type.
Definition LLVM.cpp:100
MlirTypeID mlirLLVMMDFuncAttrGetTypeID(void)
Returns the TypeID of MDFuncAttr.
Definition LLVM.cpp:599
MlirStringRef mlirLLVMCConvAttrGetName(void)
Definition LLVM.cpp:321
MlirStringRef mlirLLVMDILexicalBlockAttrGetName(void)
Definition LLVM.cpp:392
bool mlirTypeIsALLVMFunctionType(MlirType type)
Returns true if the type is an LLVM dialect function type.
Definition LLVM.cpp:88
MlirStringRef mlirLLVMDIStringTypeAttrGetName(void)
Definition LLVM.cpp:308
intptr_t mlirLLVMStructTypeGetNumElementTypes(MlirType type)
Returns the number of fields in the struct.
Definition LLVM.cpp:130
bool mlirLLVMAttrIsAMDNodeAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDNodeAttr.
Definition LLVM.cpp:615
MlirAttribute mlirLLVMDICompileUnitAttrGet(MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id, unsigned int sourceLanguage, MlirAttribute file, MlirAttribute producer, bool isOptimized, MlirLLVMDIEmissionKind emissionKind, bool isDebugInfoForProfiling, MlirLLVMDINameTableKind nameTableKind, MlirAttribute splitDebugFilename, intptr_t nImportedEntities, MlirAttribute const *importedEntities)
Creates a LLVM DICompileUnit attribute.
Definition LLVM.cpp:349
MlirTypeID mlirLLVMMDStringAttrGetTypeID(void)
Returns the TypeID of MDStringAttr.
Definition LLVM.cpp:565
MlirStringRef mlirLLVMStructTypeGetName(void)
Definition LLVM.cpp:122
intptr_t mlirLLVMFunctionTypeGetNumInputs(MlirType type)
Returns the number of input types.
Definition LLVM.cpp:96
MlirStringRef mlirLLVMDILexicalBlockFileAttrGetName(void)
Definition LLVM.cpp:405
MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx)
Creates a LLVM DINullType attribute.
Definition LLVM.cpp:224
MlirStringRef mlirLLVMPointerTypeGetName(void)
Definition LLVM.cpp:30
unsigned mlirLLVMArrayTypeGetNumElements(MlirType type)
Returns the number of elements in the llvm.array type.
Definition LLVM.cpp:72
MlirTypeID mlirLLVMArrayTypeGetTypeID()
Definition LLVM.cpp:56
MlirStringRef mlirLLVMDIFileAttrGetName(void)
Definition LLVM.cpp:343
MlirType mlirLLVMArrayTypeGetElementType(MlirType type)
Returns the element type of the llvm.array type.
Definition LLVM.cpp:68
MlirLogicalResult mlirLLVMStructTypeSetBody(MlirType structType, intptr_t nFieldTypes, MlirType const *fieldTypes, bool isPacked)
Sets the body of the identified struct if it hasn't been set yet.
Definition LLVM.cpp:187
MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx, MlirAttribute name, MlirAttribute directory)
Creates a LLVM DIFileAttr attribute.
Definition LLVM.cpp:337
MlirTypeID mlirLLVMPointerTypeGetTypeID()
Definition LLVM.cpp:34
bool mlirTypeIsALLVMStructType(MlirType type)
Returns true if the type is an LLVM dialect struct type.
Definition LLVM.cpp:114
MlirStringRef mlirLLVMStructTypeGetIdentifier(MlirType type)
Returns the identifier of the identified struct.
Definition LLVM.cpp:142
MlirAttribute mlirLLVMDIStringTypeAttrGet(MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits, uint32_t alignInBits, MlirAttribute stringLength, MlirAttribute stringLengthExp, MlirAttribute stringLocationExp, MlirLLVMTypeEncoding encoding)
Definition LLVM.cpp:296
MlirAttribute mlirLLVMDICompositeTypeAttrGet(MlirContext ctx, MlirAttribute recId, bool isRecSelf, 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, MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated, MlirAttribute associated)
Creates a LLVM DICompositeType attribute.
Definition LLVM.cpp:250
MlirAttribute mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram)
Gets the scope from this DISubprogramAttr.
Definition LLVM.cpp:477
MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx, MlirAttribute scope, MlirAttribute file, unsigned int line, unsigned int column)
Creates a LLVM DILexicalBlock attribute.
Definition LLVM.cpp:382
MlirAttribute mlirLLVMMDNodeAttrGet(MlirContext ctx, intptr_t nOperands, MlirAttribute const *operands)
Creates an LLVM MDNodeAttr.
Definition LLVM.cpp:607
MlirAttribute mlirLLVMDIExpressionElemAttrGet(MlirContext ctx, unsigned int opcode, intptr_t nArguments, uint64_t const *arguments)
Creates a LLVM DIExpressionElem attribute.
Definition LLVM.cpp:197
MlirAttribute mlirLLVMDICompileUnitAttrGetRecSelf(MlirAttribute recId)
Creates a self-referencing LLVM DICompileUnitAttr attribute.
Definition LLVM.cpp:345
bool mlirLLVMAttrIsAMDFuncAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDFuncAttr.
Definition LLVM.cpp:595
MlirAttribute mlirLLVMMDFuncAttrGet(MlirContext ctx, MlirAttribute name)
Creates an LLVM MDFuncAttr referencing a function symbol.
Definition LLVM.cpp:590
MlirAttribute mlirLLVMDICompositeTypeAttrGetRecSelf(MlirAttribute recId)
Creates a self-referencing LLVM DICompositeType attribute.
Definition LLVM.cpp:245
MlirStringRef mlirLLVMArrayTypeGetName(void)
Definition LLVM.cpp:64
MlirTypeID mlirLLVMStructTypeGetTypeID()
Definition LLVM.cpp:118
MlirAttribute mlirLLVMDIBasicTypeAttrGet(MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits, MlirLLVMTypeEncoding encoding)
Creates a LLVM DIBasicType attribute.
Definition LLVM.cpp:232
MlirType mlirLLVMFunctionTypeGetReturnType(MlirType type)
Returns the return type of the function type.
Definition LLVM.cpp:106
MlirAttribute mlirLLVMDIDerivedTypeAttrGet(MlirContext ctx, unsigned int tag, MlirAttribute name, MlirAttribute file, uint32_t line, MlirAttribute scope, MlirAttribute baseType, uint64_t sizeInBits, uint32_t alignInBits, uint64_t offsetInBits, int64_t dwarfAddressSpace, int64_t flags, MlirAttribute extraData)
Creates a LLVM DIDerivedType attribute.
Definition LLVM.cpp:277
MlirStringRef mlirLLVMDINullTypeAttrGetName(void)
Definition LLVM.cpp:228
MlirStringRef mlirLLVMDIDerivedTypeAttrGetName(void)
Definition LLVM.cpp:292
MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx, MlirLLVMComdat comdat)
Creates a LLVM Comdat attribute.
Definition LLVM.cpp:323
MlirAttribute mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId)
Creates a self-referencing LLVM DISubprogramAttr attribute.
Definition LLVM.cpp:440
MlirType mlirLLVMVoidTypeGet(MlirContext ctx)
Creates an llmv.void type.
Definition LLVM.cpp:46
MlirStringRef mlirLLVMDIBasicTypeAttrGetName(void)
Definition LLVM.cpp:241
MlirAttribute mlirLLVMDIImportedEntityAttrGet(MlirContext ctx, unsigned int tag, MlirAttribute scope, MlirAttribute entity, MlirAttribute file, unsigned int line, MlirAttribute name, intptr_t nElements, MlirAttribute const *elements)
Creates a LLVM DIImportedEntityAttr attribute.
Definition LLVM.cpp:524
MlirType mlirLLVMStructTypeIdentifiedNewGet(MlirContext ctx, MlirStringRef name, intptr_t nFieldTypes, MlirType const *fieldTypes, bool isPacked)
Creates an LLVM identified struct type with no body and a name starting with the given prefix.
Definition LLVM.cpp:177
MlirAttribute mlirLLVMMDConstantAttrGet(MlirContext ctx, MlirAttribute valueAttr)
Creates an LLVM MDConstantAttr wrapping an attribute.
Definition LLVM.cpp:573
MlirType mlirLLVMStructTypeGetElementType(MlirType type, intptr_t position)
Returns the positions-th field of the struct.
Definition LLVM.cpp:134
MlirType mlirLLVMStructTypeOpaqueGet(MlirContext ctx, MlirStringRef name)
Definition LLVM.cpp:169
MlirAttribute mlirLLVMMDNodeAttrGetOperand(MlirAttribute attr, intptr_t index)
Returns the operand at the given index of an LLVM MDNodeAttr.
Definition LLVM.cpp:627
MlirType mlirLLVMArrayTypeGet(MlirType elementType, unsigned numElements)
Creates an llvm.array type.
Definition LLVM.cpp:60
MlirAttribute mlirLLVMDISubprogramAttrGetType(MlirAttribute diSubprogram)
Gets the type from this DISubprogramAttr.
Definition LLVM.cpp:498
MlirTypeID mlirLLVMMDNodeAttrGetTypeID(void)
Returns the TypeID of MDNodeAttr.
Definition LLVM.cpp:619
bool mlirLLVMFunctionTypeIsVarArg(MlirType type)
Returns true if the function type is variadic.
Definition LLVM.cpp:110
MlirAttribute mlirLLVMDISubprogramAttrGetCompileUnit(MlirAttribute diSubprogram)
Gets the compile unit from this DISubprogram.
Definition LLVM.cpp:490
MlirAttribute mlirLLVMDIModuleAttrGet(MlirContext ctx, MlirAttribute file, MlirAttribute scope, MlirAttribute name, MlirAttribute configMacros, MlirAttribute includePath, MlirAttribute apinotes, unsigned int line, bool isDecl)
Creates a LLVM DIModuleAttr attribute.
Definition LLVM.cpp:502
MlirStringRef mlirLLVMDICompositeTypeAttrGetName(void)
Definition LLVM.cpp:273
bool mlirLLVMAttrIsAMDStringAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDStringAttr.
Definition LLVM.cpp:561
MlirStringRef mlirLLVMDIExpressionAttrGetName(void)
Definition LLVM.cpp:220
MlirStringRef mlirLLVMComdatAttrGetName(void)
Definition LLVM.cpp:327
MlirStringRef mlirLLVMDILocalVariableAttrGetName(void)
Definition LLVM.cpp:419
MlirStringRef mlirLLVMDISubprogramAttrGetName(void)
Definition LLVM.cpp:473
MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx, MlirLLVMCConv cconv)
Creates a LLVM CConv attribute.
Definition LLVM.cpp:317
MlirStringRef mlirLLVMLinkageAttrGetName(void)
Definition LLVM.cpp:333
MlirAttribute mlirLLVMDIAnnotationAttrGet(MlirContext ctx, MlirAttribute name, MlirAttribute value)
Creates a LLVM DIAnnotation attribute.
Definition LLVM.cpp:542
MlirType mlirLLVMStructTypeLiteralGetChecked(MlirLocation loc, intptr_t nFieldTypes, MlirType const *fieldTypes, bool isPacked)
Creates an LLVM literal (unnamed) struct type if possible.
Definition LLVM.cpp:159
MlirAttribute mlirLLVMMDConstantAttrGetValue(MlirAttribute attr)
Returns the attribute value of an LLVM MDConstantAttr.
Definition LLVM.cpp:586
MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx, MlirAttribute scope, MlirAttribute file, unsigned int discriminator)
Creates a LLVM DILexicalBlockFile attribute.
Definition LLVM.cpp:396
MlirAttribute mlirLLVMDIExpressionAttrGet(MlirContext ctx, intptr_t nOperations, MlirAttribute const *operations)
Creates a LLVM DIExpression attribute.
Definition LLVM.cpp:209
bool mlirLLVMStructTypeIsPacked(MlirType type)
Returns true if the struct is packed.
Definition LLVM.cpp:138
MlirAttribute mlirLLVMDISubprogramAttrGet(MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id, MlirAttribute compileUnit, MlirAttribute scope, MlirAttribute name, MlirAttribute linkageName, MlirAttribute file, unsigned int line, unsigned int scopeLine, uint64_t subprogramFlags, MlirAttribute type, intptr_t nRetainedNodes, MlirAttribute const *retainedNodes, intptr_t nAnnotations, MlirAttribute const *annotations)
Creates a LLVM DISubprogramAttr attribute.
Definition LLVM.cpp:444
unsigned mlirLLVMPointerTypeGetAddressSpace(MlirType pointerType)
Returns address space of llvm.ptr.
Definition LLVM.cpp:42
MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, uint64_t value)
Creates a LLVM DIFlags attribute.
Definition LLVM.cpp:374
MlirType mlirLLVMStructTypeIdentifiedGet(MlirContext ctx, MlirStringRef name)
Creates an LLVM identified struct type with no body.
Definition LLVM.cpp:173
MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx, unsigned int callingConvention, intptr_t nTypes, MlirAttribute const *types)
Creates a LLVM DISubroutineTypeAttr attribute.
Definition LLVM.cpp:423
MlirAttribute mlirLLVMDIDerivedTypeAttrGetBaseType(MlirAttribute diDerivedType)
Gets the base type from a LLVM DIDerivedType attribute.
Definition LLVM.cpp:313
bool mlirLLVMStructTypeIsOpaque(MlirType type)
Returns true is the struct is explicitly opaque (will not have a body) or uninitialized (will eventua...
Definition LLVM.cpp:146
bool mlirTypeIsALLVMPointerType(MlirType type)
Returns true if the type is an LLVM dialect pointer type.
Definition LLVM.cpp:38
MlirTypeID mlirLLVMFunctionTypeGetTypeID(void)
Returns the TypeID of an LLVM function type.
Definition LLVM.cpp:92
unsigned int mlirLLVMDISubprogramAttrGetLine(MlirAttribute diSubprogram)
Gets the line from this DISubprogramAttr.
Definition LLVM.cpp:481
MlirAttribute mlirLLVMDILocalVariableAttrGet(MlirContext ctx, MlirAttribute scope, MlirAttribute name, MlirAttribute diFile, unsigned int line, unsigned int arg, unsigned int alignInBits, MlirAttribute diType, int64_t flags)
Creates a LLVM DILocalVariableAttr attribute.
Definition LLVM.cpp:409
MlirStringRef mlirLLVMVoidTypeGetName(void)
Definition LLVM.cpp:50
unsigned int mlirLLVMDISubprogramAttrGetScopeLine(MlirAttribute diSubprogram)
Gets the scope line from this DISubprogram.
Definition LLVM.cpp:485
MlirType mlirLLVMStructTypeLiteralGet(MlirContext ctx, intptr_t nFieldTypes, MlirType const *fieldTypes, bool isPacked)
Creates an LLVM literal (unnamed) struct type.
Definition LLVM.cpp:150
MlirStringRef mlirLLVMDIExpressionElemAttrGetName(void)
Definition LLVM.cpp:205
MlirStringRef mlirLLVMFunctionTypeGetName(void)
Definition LLVM.cpp:84
#define MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Name, Namespace, ClassName)
static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
Definition Wrap.h:40
Attributes are known-constant values of operations.
Definition Attributes.h:25
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition Diagnostics.h:24
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition Diagnostics.h:19
MlirLLVMDINameTableKind
Definition LLVM.h:356
MLIR_CAPI_EXPORTED MlirType mlirLLVMPointerTypeGet(MlirContext ctx, unsigned addressSpace)
Creates an llvm.ptr type.
Definition LLVM.cpp:26
MlirLLVMLinkage
Definition LLVM.h:227
MlirLLVMComdat
Definition LLVM.h:211
MlirLLVMCConv
Definition LLVM.h:153
MlirLLVMDIEmissionKind
Definition LLVM.h:347
MlirLLVMTypeEncoding
Definition LLVM.h:267
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
Definition Utils.cpp:307
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
A logical result value, essentially a boolean with named states.
Definition Support.h:121
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:78