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
346 MlirContext ctx, MlirAttribute id, unsigned int sourceLanguage,
347 MlirAttribute file, MlirAttribute producer, bool isOptimized,
348 MlirLLVMDIEmissionKind emissionKind, bool isDebugInfoForProfiling,
349 MlirLLVMDINameTableKind nameTableKind, MlirAttribute splitDebugFilename,
350 intptr_t nImportedEntities, MlirAttribute const *importedEntities) {
351 SmallVector<Attribute> importsStorage;
352 importsStorage.reserve(nImportedEntities);
353 return wrap(DICompileUnitAttr::get(
354 unwrap(ctx), cast<DistinctAttr>(unwrap(id)), sourceLanguage,
355 cast<DIFileAttr>(unwrap(file)), cast<StringAttr>(unwrap(producer)),
356 isOptimized, DIEmissionKind(emissionKind), isDebugInfoForProfiling,
357 DINameTableKind(nameTableKind),
358 cast<StringAttr>(unwrap(splitDebugFilename)),
359 llvm::map_to_vector(
360 unwrapList(nImportedEntities, importedEntities, importsStorage),
361 llvm::CastTo<DINodeAttr>)));
362}
363
365 return wrap(DICompileUnitAttr::name);
366}
367
368MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx, uint64_t value) {
369 return wrap(DIFlagsAttr::get(unwrap(ctx), DIFlags(value)));
370}
371
373 return wrap(DIFlagsAttr::name);
374}
375
376MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx,
377 MlirAttribute scope,
378 MlirAttribute file,
379 unsigned int line,
380 unsigned int column) {
381 return wrap(
382 DILexicalBlockAttr::get(unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
383 cast<DIFileAttr>(unwrap(file)), line, column));
384}
385
387 return wrap(DILexicalBlockAttr::name);
388}
389
390MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx,
391 MlirAttribute scope,
392 MlirAttribute file,
393 unsigned int discriminator) {
394 return wrap(DILexicalBlockFileAttr::get(
395 unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
396 cast<DIFileAttr>(unwrap(file)), discriminator));
397}
398
400 return wrap(DILexicalBlockFileAttr::name);
401}
402
404 MlirContext ctx, MlirAttribute scope, MlirAttribute name,
405 MlirAttribute diFile, unsigned int line, unsigned int arg,
406 unsigned int alignInBits, MlirAttribute diType, int64_t flags) {
407 return wrap(DILocalVariableAttr::get(
408 unwrap(ctx), cast<DIScopeAttr>(unwrap(scope)),
409 cast<StringAttr>(unwrap(name)), cast<DIFileAttr>(unwrap(diFile)), line,
410 arg, alignInBits, cast<DITypeAttr>(unwrap(diType)), DIFlags(flags)));
411}
412
414 return wrap(DILocalVariableAttr::name);
415}
416
417MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx,
418 unsigned int callingConvention,
419 intptr_t nTypes,
420 MlirAttribute const *types) {
421 SmallVector<Attribute> attrStorage;
422 attrStorage.reserve(nTypes);
423
424 return wrap(DISubroutineTypeAttr::get(
425 unwrap(ctx), callingConvention,
426 llvm::map_to_vector(unwrapList(nTypes, types, attrStorage),
427 llvm::CastTo<DITypeAttr>)));
428}
429
431 return wrap(DISubroutineTypeAttr::name);
432}
433
434MlirAttribute mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId) {
435 return wrap(DISubprogramAttr::getRecSelf(cast<DistinctAttr>(unwrap(recId))));
436}
437
439 MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,
440 MlirAttribute compileUnit, MlirAttribute scope, MlirAttribute name,
441 MlirAttribute linkageName, MlirAttribute file, unsigned int line,
442 unsigned int scopeLine, uint64_t subprogramFlags, MlirAttribute type,
443 intptr_t nRetainedNodes, MlirAttribute const *retainedNodes,
444 intptr_t nAnnotations, MlirAttribute const *annotations) {
445 SmallVector<Attribute> nodesStorage;
446 nodesStorage.reserve(nRetainedNodes);
447
448 SmallVector<Attribute> annotationsStorage;
449 annotationsStorage.reserve(nAnnotations);
450
451 return wrap(DISubprogramAttr::get(
452 unwrap(ctx), cast<DistinctAttr>(unwrap(recId)), isRecSelf,
453 cast<DistinctAttr>(unwrap(id)),
454 cast<DICompileUnitAttr>(unwrap(compileUnit)),
455 cast<DIScopeAttr>(unwrap(scope)), cast<StringAttr>(unwrap(name)),
456 cast<StringAttr>(unwrap(linkageName)), cast<DIFileAttr>(unwrap(file)),
457 line, scopeLine, DISubprogramFlags(subprogramFlags),
458 cast<DISubroutineTypeAttr>(unwrap(type)),
459 llvm::map_to_vector(
460 unwrapList(nRetainedNodes, retainedNodes, nodesStorage),
461 llvm::CastTo<DINodeAttr>),
462 llvm::map_to_vector(
463 unwrapList(nAnnotations, annotations, annotationsStorage),
464 llvm::CastTo<DINodeAttr>)));
465}
466
468 return wrap(DISubprogramAttr::name);
469}
470
471MlirAttribute mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram) {
472 return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getScope());
473}
474
475unsigned int mlirLLVMDISubprogramAttrGetLine(MlirAttribute diSubprogram) {
476 return cast<DISubprogramAttr>(unwrap(diSubprogram)).getLine();
477}
478
479unsigned int mlirLLVMDISubprogramAttrGetScopeLine(MlirAttribute diSubprogram) {
480 return cast<DISubprogramAttr>(unwrap(diSubprogram)).getScopeLine();
481}
482
483MlirAttribute
484mlirLLVMDISubprogramAttrGetCompileUnit(MlirAttribute diSubprogram) {
485 return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getCompileUnit());
486}
487
488MlirAttribute mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram) {
489 return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getFile());
490}
491
492MlirAttribute mlirLLVMDISubprogramAttrGetType(MlirAttribute diSubprogram) {
493 return wrap(cast<DISubprogramAttr>(unwrap(diSubprogram)).getType());
494}
495
496MlirAttribute mlirLLVMDIModuleAttrGet(MlirContext ctx, MlirAttribute file,
497 MlirAttribute scope, MlirAttribute name,
498 MlirAttribute configMacros,
499 MlirAttribute includePath,
500 MlirAttribute apinotes, unsigned int line,
501 bool isDecl) {
502 return wrap(DIModuleAttr::get(
503 unwrap(ctx), cast<DIFileAttr>(unwrap(file)),
504 cast<DIScopeAttr>(unwrap(scope)), cast<StringAttr>(unwrap(name)),
505 cast<StringAttr>(unwrap(configMacros)),
506 cast<StringAttr>(unwrap(includePath)), cast<StringAttr>(unwrap(apinotes)),
507 line, isDecl));
508}
509
511 return wrap(DIModuleAttr::name);
512}
513
514MlirAttribute mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule) {
515 return wrap(cast<DIModuleAttr>(unwrap(diModule)).getScope());
516}
517
519 MlirContext ctx, unsigned int tag, MlirAttribute scope,
520 MlirAttribute entity, MlirAttribute file, unsigned int line,
521 MlirAttribute name, intptr_t nElements, MlirAttribute const *elements) {
522 SmallVector<Attribute> elementsStorage;
523 elementsStorage.reserve(nElements);
524 return wrap(DIImportedEntityAttr::get(
525 unwrap(ctx), tag, cast<DIScopeAttr>(unwrap(scope)),
526 cast<DINodeAttr>(unwrap(entity)), cast<DIFileAttr>(unwrap(file)), line,
527 cast<StringAttr>(unwrap(name)),
528 llvm::map_to_vector(unwrapList(nElements, elements, elementsStorage),
529 llvm::CastTo<DINodeAttr>)));
530}
531
533 return wrap(DIImportedEntityAttr::name);
534}
535
536MlirAttribute mlirLLVMDIAnnotationAttrGet(MlirContext ctx, MlirAttribute name,
537 MlirAttribute value) {
538 return wrap(DIAnnotationAttr::get(unwrap(ctx), cast<StringAttr>(unwrap(name)),
539 cast<StringAttr>(unwrap(value))));
540}
541
543 return wrap(DIAnnotationAttr::name);
544}
545
546//===----------------------------------------------------------------------===//
547// Metadata Attributes
548//===----------------------------------------------------------------------===//
549
550MlirAttribute mlirLLVMMDStringAttrGet(MlirContext ctx, MlirStringRef value) {
551 return wrap(MDStringAttr::get(unwrap(ctx),
552 StringAttr::get(unwrap(ctx), unwrap(value))));
553}
554
555bool mlirLLVMAttrIsAMDStringAttr(MlirAttribute attr) {
556 return isa<MDStringAttr>(unwrap(attr));
557}
558
560 return wrap(MDStringAttr::getTypeID());
561}
562
564 return wrap(cast<MDStringAttr>(unwrap(attr)).getValue().getValue());
565}
566
567MlirAttribute mlirLLVMMDConstantAttrGet(MlirContext ctx,
568 MlirAttribute valueAttr) {
569 return wrap(MDConstantAttr::get(unwrap(ctx), unwrap(valueAttr)));
570}
571
572bool mlirLLVMAttrIsAMDConstantAttr(MlirAttribute attr) {
573 return isa<MDConstantAttr>(unwrap(attr));
574}
575
577 return wrap(MDConstantAttr::getTypeID());
578}
579
580MlirAttribute mlirLLVMMDConstantAttrGetValue(MlirAttribute attr) {
581 return wrap((Attribute)cast<MDConstantAttr>(unwrap(attr)).getValue());
582}
583
584MlirAttribute mlirLLVMMDFuncAttrGet(MlirContext ctx, MlirAttribute name) {
585 return wrap(
586 MDFuncAttr::get(unwrap(ctx), cast<FlatSymbolRefAttr>(unwrap(name))));
587}
588
589bool mlirLLVMAttrIsAMDFuncAttr(MlirAttribute attr) {
590 return isa<MDFuncAttr>(unwrap(attr));
591}
592
594 return wrap(MDFuncAttr::getTypeID());
595}
596
597MlirAttribute mlirLLVMMDFuncAttrGetName(MlirAttribute attr) {
598 return wrap((Attribute)cast<MDFuncAttr>(unwrap(attr)).getName());
599}
600
601MlirAttribute mlirLLVMMDNodeAttrGet(MlirContext ctx, intptr_t nOperands,
602 MlirAttribute const *operands) {
603 SmallVector<Attribute> attrStorage;
604 attrStorage.reserve(nOperands);
605 return wrap(MDNodeAttr::get(unwrap(ctx),
606 unwrapList(nOperands, operands, attrStorage)));
607}
608
609bool mlirLLVMAttrIsAMDNodeAttr(MlirAttribute attr) {
610 return isa<MDNodeAttr>(unwrap(attr));
611}
612
614 return wrap(MDNodeAttr::getTypeID());
615}
616
618 return cast<MDNodeAttr>(unwrap(attr)).getOperands().size();
619}
620
621MlirAttribute mlirLLVMMDNodeAttrGetOperand(MlirAttribute attr, intptr_t index) {
622 return wrap(cast<MDNodeAttr>(unwrap(attr)).getOperands()[index]);
623}
static Type getElementType(Type type)
Determine the element type of type.
MlirStringRef mlirLLVMDIFlagsAttrGetName(void)
Definition LLVM.cpp:372
intptr_t mlirLLVMMDNodeAttrGetNumOperands(MlirAttribute attr)
Returns the number of operands in an LLVM MDNodeAttr.
Definition LLVM.cpp:617
MlirStringRef mlirLLVMDIModuleAttrGetName(void)
Definition LLVM.cpp:510
MlirStringRef mlirLLVMDIAnnotationAttrGetName(void)
Definition LLVM.cpp:542
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:597
MlirStringRef mlirLLVMDIImportedEntityAttrGetName(void)
Definition LLVM.cpp:532
MlirTypeID mlirLLVMMDConstantAttrGetTypeID(void)
Returns the TypeID of MDConstantAttr.
Definition LLVM.cpp:576
MlirAttribute mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram)
Gets the file from this DISubprogramAttr.
Definition LLVM.cpp:488
bool mlirLLVMAttrIsAMDConstantAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDConstantAttr.
Definition LLVM.cpp:572
MlirStringRef mlirLLVMDICompileUnitAttrGetName(void)
Definition LLVM.cpp:364
MlirStringRef mlirLLVMMDStringAttrGetValue(MlirAttribute attr)
Returns the string value of an LLVM MDStringAttr.
Definition LLVM.cpp:563
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:514
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:430
MlirAttribute mlirLLVMMDStringAttrGet(MlirContext ctx, MlirStringRef value)
Creates an LLVM MDStringAttr.
Definition LLVM.cpp:550
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:593
MlirStringRef mlirLLVMCConvAttrGetName(void)
Definition LLVM.cpp:321
MlirStringRef mlirLLVMDILexicalBlockAttrGetName(void)
Definition LLVM.cpp:386
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:609
MlirTypeID mlirLLVMMDStringAttrGetTypeID(void)
Returns the TypeID of MDStringAttr.
Definition LLVM.cpp:559
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:399
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:471
MlirAttribute mlirLLVMDILexicalBlockAttrGet(MlirContext ctx, MlirAttribute scope, MlirAttribute file, unsigned int line, unsigned int column)
Creates a LLVM DILexicalBlock attribute.
Definition LLVM.cpp:376
MlirAttribute mlirLLVMMDNodeAttrGet(MlirContext ctx, intptr_t nOperands, MlirAttribute const *operands)
Creates an LLVM MDNodeAttr.
Definition LLVM.cpp:601
MlirAttribute mlirLLVMDIExpressionElemAttrGet(MlirContext ctx, unsigned int opcode, intptr_t nArguments, uint64_t const *arguments)
Creates a LLVM DIExpressionElem attribute.
Definition LLVM.cpp:197
bool mlirLLVMAttrIsAMDFuncAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDFuncAttr.
Definition LLVM.cpp:589
MlirAttribute mlirLLVMMDFuncAttrGet(MlirContext ctx, MlirAttribute name)
Creates an LLVM MDFuncAttr referencing a function symbol.
Definition LLVM.cpp:584
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:434
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:518
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:567
MlirAttribute mlirLLVMDICompileUnitAttrGet(MlirContext ctx, 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:345
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:621
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:492
MlirTypeID mlirLLVMMDNodeAttrGetTypeID(void)
Returns the TypeID of MDNodeAttr.
Definition LLVM.cpp:613
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:484
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:496
MlirStringRef mlirLLVMDICompositeTypeAttrGetName(void)
Definition LLVM.cpp:273
bool mlirLLVMAttrIsAMDStringAttr(MlirAttribute attr)
Returns true if the attribute is an LLVM MDStringAttr.
Definition LLVM.cpp:555
MlirStringRef mlirLLVMDIExpressionAttrGetName(void)
Definition LLVM.cpp:220
MlirStringRef mlirLLVMComdatAttrGetName(void)
Definition LLVM.cpp:327
MlirStringRef mlirLLVMDILocalVariableAttrGetName(void)
Definition LLVM.cpp:413
MlirStringRef mlirLLVMDISubprogramAttrGetName(void)
Definition LLVM.cpp:467
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:536
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:580
MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(MlirContext ctx, MlirAttribute scope, MlirAttribute file, unsigned int discriminator)
Creates a LLVM DILexicalBlockFile attribute.
Definition LLVM.cpp:390
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:438
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:368
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:417
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:475
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:403
MlirStringRef mlirLLVMVoidTypeGetName(void)
Definition LLVM.cpp:50
unsigned int mlirLLVMDISubprogramAttrGetScopeLine(MlirAttribute diSubprogram)
Gets the scope line from this DISubprogram.
Definition LLVM.cpp:479
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