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, MlirAttribute identifier,
257 MlirAttribute discriminator) {
258 SmallVector<Attribute> elementsStorage;
259 elementsStorage.reserve(nElements);
260
261 return wrap(DICompositeTypeAttr::get(
262 unwrap(ctx), cast<DistinctAttr>(unwrap(recId)), isRecSelf, tag,
263 cast<StringAttr>(unwrap(name)), cast<DIFileAttr>(unwrap(file)), line,
264 cast<DIScopeAttr>(unwrap(scope)), cast<DITypeAttr>(unwrap(baseType)),
265 DIFlags(flags), sizeInBits, alignInBits,
266 cast<DIExpressionAttr>(unwrap(dataLocation)),
267 cast<DIExpressionAttr>(unwrap(rank)),
268 cast<DIExpressionAttr>(unwrap(allocated)),
269 cast<DIExpressionAttr>(unwrap(associated)),
270 cast<StringAttr>(unwrap(identifier)),
271 cast<DIDerivedTypeAttr>(unwrap(discriminator)),
272 llvm::map_to_vector(unwrapList(nElements, elements, elementsStorage),
273 llvm::CastTo<DINodeAttr>)));
274}
275
277 return wrap(DICompositeTypeAttr::name);
278}
279
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 extraData) {
285 std::optional<unsigned> addressSpace = std::nullopt;
286 if (dwarfAddressSpace >= 0)
287 addressSpace = (unsigned)dwarfAddressSpace;
288 return wrap(DIDerivedTypeAttr::get(
289 unwrap(ctx), tag, cast<StringAttr>(unwrap(name)),
290 cast<DIFileAttr>(unwrap(file)), line, cast<DIScopeAttr>(unwrap(scope)),
291 cast<DITypeAttr>(unwrap(baseType)), sizeInBits, alignInBits, offsetInBits,
292 addressSpace, DIFlags(flags), unwrap(extraData)));
293}
294
296 return wrap(DIDerivedTypeAttr::name);
297}
298
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) {
304 return wrap(DIStringTypeAttr::get(
305 unwrap(ctx), tag, cast<StringAttr>(unwrap(name)), sizeInBits, alignInBits,
306 cast<DIVariableAttr>(unwrap(stringLength)),
307 cast<DIExpressionAttr>(unwrap(stringLengthExp)),
308 cast<DIExpressionAttr>(unwrap(stringLocationExp)), encoding));
309}
310
312 return wrap(DIStringTypeAttr::name);
313}
314
315MlirAttribute
316mlirLLVMDIDerivedTypeAttrGetBaseType(MlirAttribute diDerivedType) {
317 return wrap(cast<DIDerivedTypeAttr>(unwrap(diDerivedType)).getBaseType());
318}
319
320MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx, MlirLLVMCConv cconv) {
321 return wrap(CConvAttr::get(unwrap(ctx), CConv(cconv)));
322}
323
324MlirStringRef mlirLLVMCConvAttrGetName(void) { return wrap(CConvAttr::name); }
325
326MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx, MlirLLVMComdat comdat) {
327 return wrap(ComdatAttr::get(unwrap(ctx), comdat::Comdat(comdat)));
328}
329
330MlirStringRef mlirLLVMComdatAttrGetName(void) { return wrap(ComdatAttr::name); }
331
332MlirAttribute mlirLLVMLinkageAttrGet(MlirContext ctx, MlirLLVMLinkage linkage) {
333 return wrap(LinkageAttr::get(unwrap(ctx), linkage::Linkage(linkage)));
334}
335
337 return wrap(LinkageAttr::name);
338}
339
340MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx, MlirAttribute name,
341 MlirAttribute directory) {
342 return wrap(DIFileAttr::get(unwrap(ctx), cast<StringAttr>(unwrap(name)),
343 cast<StringAttr>(unwrap(directory))));
344}
345
346MlirStringRef mlirLLVMDIFileAttrGetName(void) { return wrap(DIFileAttr::name); }
347
348MlirAttribute mlirLLVMDICompileUnitAttrGetRecSelf(MlirAttribute recId) {
349 return wrap(DICompileUnitAttr::getRecSelf(cast<DistinctAttr>(unwrap(recId))));
350}
351
353 MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,
354 unsigned int sourceLanguage, MlirAttribute file, MlirAttribute producer,
355 bool isOptimized, MlirLLVMDIEmissionKind emissionKind,
356 bool isDebugInfoForProfiling, MlirLLVMDINameTableKind nameTableKind,
357 MlirAttribute splitDebugFilename, intptr_t nImportedEntities,
358 MlirAttribute const *importedEntities) {
359 SmallVector<Attribute> importsStorage;
360 importsStorage.reserve(nImportedEntities);
361 return wrap(DICompileUnitAttr::get(
362 unwrap(ctx), cast<DistinctAttr>(unwrap(recId)), isRecSelf,
363 cast<DistinctAttr>(unwrap(id)), sourceLanguage,
364 cast<DIFileAttr>(unwrap(file)), cast<StringAttr>(unwrap(producer)),
365 isOptimized, DIEmissionKind(emissionKind), isDebugInfoForProfiling,
366 DINameTableKind(nameTableKind),
367 cast<StringAttr>(unwrap(splitDebugFilename)),
368 llvm::map_to_vector(
369 unwrapList(nImportedEntities, importedEntities, importsStorage),
370 llvm::CastTo<DINodeAttr>)));
371}
372
374 return wrap(DICompileUnitAttr::name);
375}
376
377MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, uint64_t value) {
378 return wrap(DIFlagsAttr::get(unwrap(ctx), DIFlags(value)));
379}
380
382 return wrap(DIFlagsAttr::name);
383}
384
385MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx,
386 MlirAttribute scope,
387 MlirAttribute file,
388 unsigned int line,
389 unsigned int column) {
390 return wrap(
391 DILexicalBlockAttr::get(unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
392 cast<DIFileAttr>(unwrap(file)), line, column));
393}
394
396 return wrap(DILexicalBlockAttr::name);
397}
398
399MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx,
400 MlirAttribute scope,
401 MlirAttribute file,
402 unsigned int discriminator) {
403 return wrap(DILexicalBlockFileAttr::get(
404 unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
405 cast<DIFileAttr>(unwrap(file)), discriminator));
406}
407
409 return wrap(DILexicalBlockFileAttr::name);
410}
411
413 MlirContext ctx, MlirAttribute scope, MlirAttribute name,
414 MlirAttribute diFile, unsigned int line, unsigned int arg,
415 unsigned int alignInBits, MlirAttribute diType, int64_t flags) {
416 return wrap(DILocalVariableAttr::get(
417 unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
418 cast<StringAttr>(unwrap(name)), cast<DIFileAttr>(unwrap(diFile)), line,
419 arg, alignInBits, cast<DITypeAttr>(unwrap(diType)), DIFlags(flags)));
420}
421
423 return wrap(DILocalVariableAttr::name);
424}
425
426MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx,
427 unsigned int callingConvention,
428 intptr_t nTypes,
429 MlirAttribute const *types) {
430 SmallVector<Attribute> attrStorage;
431 attrStorage.reserve(nTypes);
432
433 return wrap(DISubroutineTypeAttr::get(
434 unwrap(ctx), callingConvention,
435 llvm::map_to_vector(unwrapList(nTypes, types, attrStorage),
436 llvm::CastTo<DITypeAttr>)));
437}
438
440 return wrap(DISubroutineTypeAttr::name);
441}
442
443MlirAttribute mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId) {
444 return wrap(DISubprogramAttr::getRecSelf(cast<DistinctAttr>(unwrap(recId))));
445}
446
448 MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,
449 MlirAttribute compileUnit, MlirAttribute scope, MlirAttribute name,
450 MlirAttribute linkageName, MlirAttribute file, unsigned int line,
451 unsigned int scopeLine, uint64_t subprogramFlags, MlirAttribute type,
452 intptr_t nRetainedNodes, MlirAttribute const *retainedNodes,
453 intptr_t nAnnotations, MlirAttribute const *annotations) {
454 SmallVector<Attribute> nodesStorage;
455 nodesStorage.reserve(nRetainedNodes);
456
457 SmallVector<Attribute> annotationsStorage;
458 annotationsStorage.reserve(nAnnotations);
459
460 return wrap(DISubprogramAttr::get(
461 unwrap(ctx), cast<DistinctAttr>(unwrap(recId)), isRecSelf,
462 cast<DistinctAttr>(unwrap(id)),
463 cast<DICompileUnitAttr>(unwrap(compileUnit)),
464 cast<DIScopeAttr>(unwrap(scope)), cast<StringAttr>(unwrap(name)),
465 cast<StringAttr>(unwrap(linkageName)), cast<DIFileAttr>(unwrap(file)),
466 line, scopeLine, DISubprogramFlags(subprogramFlags),
467 cast<DISubroutineTypeAttr>(unwrap(type)),
468 llvm::map_to_vector(
469 unwrapList(nRetainedNodes, retainedNodes, nodesStorage),
470 llvm::CastTo<DINodeAttr>),
471 llvm::map_to_vector(
472 unwrapList(nAnnotations, annotations, annotationsStorage),
473 llvm::CastTo<DINodeAttr>)));
474}
475
477 return wrap(DISubprogramAttr::name);
478}
479
480MlirAttribute mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram) {
481 return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getScope());
482}
483
484unsigned int mlirLLVMDISubprogramAttrGetLine(MlirAttribute diSubprogram) {
485 return cast<DISubprogramAttr>(unwrap(diSubprogram)).getLine();
486}
487
488unsigned int mlirLLVMDISubprogramAttrGetScopeLine(MlirAttribute diSubprogram) {
489 return cast<DISubprogramAttr>(unwrap(diSubprogram)).getScopeLine();
490}
491
492MlirAttribute
493mlirLLVMDISubprogramAttrGetCompileUnit(MlirAttribute diSubprogram) {
494 return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getCompileUnit());
495}
496
497MlirAttribute mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram) {
498 return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getFile());
499}
500
501MlirAttribute mlirLLVMDISubprogramAttrGetType(MlirAttribute diSubprogram) {
502 return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getType());
503}
504
505MlirAttribute mlirLLVMDIModuleAttrGet(MlirContext ctx, MlirAttribute file,
506 MlirAttribute scope, MlirAttribute name,
507 MlirAttribute configMacros,
508 MlirAttribute includePath,
509 MlirAttribute apinotes, unsigned int line,
510 bool isDecl) {
511 return wrap(DIModuleAttr::get(
512 unwrap(ctx), cast<DIFileAttr>(unwrap(file)),
513 cast<DIScopeAttr>(unwrap(scope)), cast<StringAttr>(unwrap(name)),
514 cast<StringAttr>(unwrap(configMacros)),
515 cast<StringAttr>(unwrap(includePath)), cast<StringAttr>(unwrap(apinotes)),
516 line, isDecl));
517}
518
520 return wrap(DIModuleAttr::name);
521}
522
523MlirAttribute mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule) {
524 return wrap(cast<DIModuleAttr>(unwrap(diModule)).getScope());
525}
526
528 MlirContext ctx, unsigned int tag, MlirAttribute scope,
529 MlirAttribute entity, MlirAttribute file, unsigned int line,
530 MlirAttribute name, intptr_t nElements, MlirAttribute const *elements) {
531 SmallVector<Attribute> elementsStorage;
532 elementsStorage.reserve(nElements);
533 return wrap(DIImportedEntityAttr::get(
534 unwrap(ctx), tag, cast<DIScopeAttr>(unwrap(scope)),
535 cast<DINodeAttr>(unwrap(entity)), cast<DIFileAttr>(unwrap(file)), line,
536 cast<StringAttr>(unwrap(name)),
537 llvm::map_to_vector(unwrapList(nElements, elements, elementsStorage),
538 llvm::CastTo<DINodeAttr>)));
539}
540
542 return wrap(DIImportedEntityAttr::name);
543}
544
545MlirAttribute mlirLLVMDIAnnotationAttrGet(MlirContext ctx, MlirAttribute name,
546 MlirAttribute value) {
547 return wrap(DIAnnotationAttr::get(unwrap(ctx), cast<StringAttr>(unwrap(name)),
548 cast<StringAttr>(unwrap(value))));
549}
550
552 return wrap(DIAnnotationAttr::name);
553}
554
555//===----------------------------------------------------------------------===//
556// Metadata Attributes
557//===----------------------------------------------------------------------===//
558
559MlirAttribute mlirLLVMMDStringAttrGet(MlirContext ctx, MlirStringRef value) {
560 return wrap(MDStringAttr::get(unwrap(ctx),
561 StringAttr::get(unwrap(ctx), unwrap(value))));
562}
563
564bool mlirLLVMAttrIsAMDStringAttr(MlirAttribute attr) {
565 return isa<MDStringAttr>(unwrap(attr));
566}
567
569 return wrap(MDStringAttr::getTypeID());
570}
571
573 return wrap(cast<MDStringAttr>(unwrap(attr)).getValue().getValue());
574}
575
576MlirAttribute mlirLLVMMDConstantAttrGet(MlirContext ctx,
577 MlirAttribute valueAttr) {
578 return wrap(MDConstantAttr::get(unwrap(ctx), unwrap(valueAttr)));
579}
580
581bool mlirLLVMAttrIsAMDConstantAttr(MlirAttribute attr) {
582 return isa<MDConstantAttr>(unwrap(attr));
583}
584
586 return wrap(MDConstantAttr::getTypeID());
587}
588
589MlirAttribute mlirLLVMMDConstantAttrGetValue(MlirAttribute attr) {
590 return wrap((Attribute)cast<MDConstantAttr>(unwrap(attr)).getValue());
591}
592
593MlirAttribute mlirLLVMMDFuncAttrGet(MlirContext ctx, MlirAttribute name) {
594 return wrap(
595 MDFuncAttr::get(unwrap(ctx), cast<FlatSymbolRefAttr>(unwrap(name))));
596}
597
598bool mlirLLVMAttrIsAMDFuncAttr(MlirAttribute attr) {
599 return isa<MDFuncAttr>(unwrap(attr));
600}
601
603 return wrap(MDFuncAttr::getTypeID());
604}
605
606MlirAttribute mlirLLVMMDFuncAttrGetName(MlirAttribute attr) {
607 return wrap((Attribute)cast<MDFuncAttr>(unwrap(attr)).getName());
608}
609
610MlirAttribute mlirLLVMMDNodeAttrGet(MlirContext ctx, intptr_t nOperands,
611 MlirAttribute const *operands) {
612 SmallVector<Attribute> attrStorage;
613 attrStorage.reserve(nOperands);
614 return wrap(MDNodeAttr::get(unwrap(ctx),
615 unwrapList(nOperands, operands, attrStorage)));
616}
617
618bool mlirLLVMAttrIsAMDNodeAttr(MlirAttribute attr) {
619 return isa<MDNodeAttr>(unwrap(attr));
620}
621
623 return wrap(MDNodeAttr::getTypeID());
624}
625
627 return cast<MDNodeAttr>(unwrap(attr)).getOperands().size();
628}
629
630MlirAttribute mlirLLVMMDNodeAttrGetOperand(MlirAttribute attr, intptr_t index) {
631 return wrap(cast<MDNodeAttr>(unwrap(attr)).getOperands()[index]);
632}
static Type getElementType(Type type)
Determine the element type of type.
MlirStringRef mlirLLVMDIFlagsAttrGetName(void)
Definition LLVM.cpp:381
intptr_t mlirLLVMMDNodeAttrGetNumOperands(MlirAttribute attr)
Returns the number of operands in an LLVM MDNodeAttr.
Definition LLVM.cpp:626
MlirStringRef mlirLLVMDIModuleAttrGetName(void)
Definition LLVM.cpp:519
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, MlirAttribute identifier, MlirAttribute discriminator)
Creates a LLVM DICompositeType attribute.
Definition LLVM.cpp:250
MlirStringRef mlirLLVMDIAnnotationAttrGetName(void)
Definition LLVM.cpp:551
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:332
MlirAttribute mlirLLVMMDFuncAttrGetName(MlirAttribute attr)
Returns the symbol name of an LLVM MDFuncAttr.
Definition LLVM.cpp:606
MlirStringRef mlirLLVMDIImportedEntityAttrGetName(void)
Definition LLVM.cpp:541
MlirTypeID mlirLLVMMDConstantAttrGetTypeID(void)
Returns the TypeID of MDConstantAttr.
Definition LLVM.cpp:585
MlirAttribute mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram)
Gets the file from this DISubprogramAttr.
Definition LLVM.cpp:497
bool mlirLLVMAttrIsAMDConstantAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDConstantAttr.
Definition LLVM.cpp:581
MlirStringRef mlirLLVMDICompileUnitAttrGetName(void)
Definition LLVM.cpp:373
MlirStringRef mlirLLVMMDStringAttrGetValue(MlirAttribute attr)
Returns the string value of an LLVM MDStringAttr.
Definition LLVM.cpp:572
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:523
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:439
MlirAttribute mlirLLVMMDStringAttrGet(MlirContext ctx, MlirStringRef value)
Creates an LLVM MDStringAttr.
Definition LLVM.cpp:559
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:602
MlirStringRef mlirLLVMCConvAttrGetName(void)
Definition LLVM.cpp:324
MlirStringRef mlirLLVMDILexicalBlockAttrGetName(void)
Definition LLVM.cpp:395
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:311
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:618
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:352
MlirTypeID mlirLLVMMDStringAttrGetTypeID(void)
Returns the TypeID of MDStringAttr.
Definition LLVM.cpp:568
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:408
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:346
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:340
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:299
MlirAttribute mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram)
Gets the scope from this DISubprogramAttr.
Definition LLVM.cpp:480
MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx, MlirAttribute scope, MlirAttribute file, unsigned int line, unsigned int column)
Creates a LLVM DILexicalBlock attribute.
Definition LLVM.cpp:385
MlirAttribute mlirLLVMMDNodeAttrGet(MlirContext ctx, intptr_t nOperands, MlirAttribute const *operands)
Creates an LLVM MDNodeAttr.
Definition LLVM.cpp:610
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:348
bool mlirLLVMAttrIsAMDFuncAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDFuncAttr.
Definition LLVM.cpp:598
MlirAttribute mlirLLVMMDFuncAttrGet(MlirContext ctx, MlirAttribute name)
Creates an LLVM MDFuncAttr referencing a function symbol.
Definition LLVM.cpp:593
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:280
MlirStringRef mlirLLVMDINullTypeAttrGetName(void)
Definition LLVM.cpp:228
MlirStringRef mlirLLVMDIDerivedTypeAttrGetName(void)
Definition LLVM.cpp:295
MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx, MlirLLVMComdat comdat)
Creates a LLVM Comdat attribute.
Definition LLVM.cpp:326
MlirAttribute mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId)
Creates a self-referencing LLVM DISubprogramAttr attribute.
Definition LLVM.cpp:443
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:527
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:576
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:630
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:501
MlirTypeID mlirLLVMMDNodeAttrGetTypeID(void)
Returns the TypeID of MDNodeAttr.
Definition LLVM.cpp:622
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:493
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:505
MlirStringRef mlirLLVMDICompositeTypeAttrGetName(void)
Definition LLVM.cpp:276
bool mlirLLVMAttrIsAMDStringAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDStringAttr.
Definition LLVM.cpp:564
MlirStringRef mlirLLVMDIExpressionAttrGetName(void)
Definition LLVM.cpp:220
MlirStringRef mlirLLVMComdatAttrGetName(void)
Definition LLVM.cpp:330
MlirStringRef mlirLLVMDILocalVariableAttrGetName(void)
Definition LLVM.cpp:422
MlirStringRef mlirLLVMDISubprogramAttrGetName(void)
Definition LLVM.cpp:476
MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx, MlirLLVMCConv cconv)
Creates a LLVM CConv attribute.
Definition LLVM.cpp:320
MlirStringRef mlirLLVMLinkageAttrGetName(void)
Definition LLVM.cpp:336
MlirAttribute mlirLLVMDIAnnotationAttrGet(MlirContext ctx, MlirAttribute name, MlirAttribute value)
Creates a LLVM DIAnnotation attribute.
Definition LLVM.cpp:545
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:589
MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx, MlirAttribute scope, MlirAttribute file, unsigned int discriminator)
Creates a LLVM DILexicalBlockFile attribute.
Definition LLVM.cpp:399
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:447
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:377
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:426
MlirAttribute mlirLLVMDIDerivedTypeAttrGetBaseType(MlirAttribute diDerivedType)
Gets the base type from a LLVM DIDerivedType attribute.
Definition LLVM.cpp:316
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:484
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:412
MlirStringRef mlirLLVMVoidTypeGetName(void)
Definition LLVM.cpp:50
unsigned int mlirLLVMDISubprogramAttrGetScopeLine(MlirAttribute diSubprogram)
Gets the scope line from this DISubprogram.
Definition LLVM.cpp:488
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:357
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:348
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