1//===-- mlir-c/Dialect/LLVM.h - C API for LLVM --------------------*- C -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM
4// Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef MLIR_C_DIALECT_LLVM_H
11#define MLIR_C_DIALECT_LLVM_H
12
13#include "mlir-c/IR.h"
14#include "mlir-c/Support.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(LLVM, llvm);
21
22/// Creates an llvm.ptr type.
23MLIR_CAPI_EXPORTED MlirType mlirLLVMPointerTypeGet(MlirContext ctx,
24 unsigned addressSpace);
25
26MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMPointerTypeGetName(void);
27
28MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMPointerTypeGetTypeID(void);
29
30/// Returns `true` if the type is an LLVM dialect pointer type.
31MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMPointerType(MlirType type);
32
33/// Returns address space of llvm.ptr
34MLIR_CAPI_EXPORTED unsigned
35mlirLLVMPointerTypeGetAddressSpace(MlirType pointerType);
36
37/// Creates an llmv.void type.
38MLIR_CAPI_EXPORTED MlirType mlirLLVMVoidTypeGet(MlirContext ctx);
39
40MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMVoidTypeGetName(void);
41
42/// Returns `true` if the type is an LLVM dialect array type.
43MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMArrayType(MlirType type);
44
45MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMArrayTypeGetTypeID(void);
46
47/// Creates an llvm.array type.
48MLIR_CAPI_EXPORTED MlirType mlirLLVMArrayTypeGet(MlirType elementType,
49 unsigned numElements);
50
51MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMArrayTypeGetName(void);
52
53/// Returns the element type of the llvm.array type.
54MLIR_CAPI_EXPORTED MlirType mlirLLVMArrayTypeGetElementType(MlirType type);
55
56/// Returns the number of elements in the llvm.array type.
57MLIR_CAPI_EXPORTED unsigned mlirLLVMArrayTypeGetNumElements(MlirType type);
58
59/// Creates an llvm.func type.
60MLIR_CAPI_EXPORTED MlirType
61mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes,
62 MlirType const *argumentTypes, bool isVarArg);
63
64MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMFunctionTypeGetName(void);
65
66/// Returns `true` if the type is an LLVM dialect function type.
67MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMFunctionType(MlirType type);
68
69/// Returns the TypeID of an LLVM function type.
70MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMFunctionTypeGetTypeID(void);
71
72/// Returns the number of input types.
73MLIR_CAPI_EXPORTED intptr_t mlirLLVMFunctionTypeGetNumInputs(MlirType type);
74
75/// Returns the pos-th input type.
76MLIR_CAPI_EXPORTED MlirType mlirLLVMFunctionTypeGetInput(MlirType type,
77 intptr_t pos);
78
79/// Returns `true` if the function type is variadic.
80MLIR_CAPI_EXPORTED bool mlirLLVMFunctionTypeIsVarArg(MlirType type);
81
82/// Returns the return type of the function type.
83MLIR_CAPI_EXPORTED MlirType mlirLLVMFunctionTypeGetReturnType(MlirType type);
84
85/// Returns `true` if the type is an LLVM dialect struct type.
86MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMStructType(MlirType type);
87
88MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMStructTypeGetTypeID(void);
89
90MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMStructTypeGetName(void);
91
92/// Returns `true` if the type is a literal (unnamed) LLVM struct type.
93MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsLiteral(MlirType type);
94
95/// Returns the number of fields in the struct. Asserts if the struct is opaque
96/// or not yet initialized.
97MLIR_CAPI_EXPORTED intptr_t mlirLLVMStructTypeGetNumElementTypes(MlirType type);
98
99/// Returns the `positions`-th field of the struct. Asserts if the struct is
100/// opaque, not yet initialized or if the position is out of range.
101MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeGetElementType(MlirType type,
102 intptr_t position);
103
104/// Returns `true` if the struct is packed.
105MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsPacked(MlirType type);
106
107/// Returns the identifier of the identified struct. Asserts that the struct is
108/// identified, i.e., not literal.
109MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMStructTypeGetIdentifier(MlirType type);
110
111/// Returns `true` is the struct is explicitly opaque (will not have a body) or
112/// uninitialized (will eventually have a body).
113MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsOpaque(MlirType type);
114
115/// Creates an LLVM literal (unnamed) struct type. This may assert if the fields
116/// have types not compatible with the LLVM dialect. For a graceful failure, use
117/// the checked version.
118MLIR_CAPI_EXPORTED MlirType
119mlirLLVMStructTypeLiteralGet(MlirContext ctx, intptr_t nFieldTypes,
120 MlirType const *fieldTypes, bool isPacked);
121
122/// Creates an LLVM literal (unnamed) struct type if possible. Emits a
123/// diagnostic at the given location and returns null otherwise.
124MLIR_CAPI_EXPORTED MlirType
125mlirLLVMStructTypeLiteralGetChecked(MlirLocation loc, intptr_t nFieldTypes,
126 MlirType const *fieldTypes, bool isPacked);
127
128/// Creates an LLVM identified struct type with no body. If a struct type with
129/// this name already exists in the context, returns that type. Use
130/// mlirLLVMStructTypeIdentifiedNewGet to create a fresh struct type,
131/// potentially renaming it. The body should be set separatelty by calling
132/// mlirLLVMStructTypeSetBody, if it isn't set already.
133MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeIdentifiedGet(MlirContext ctx,
134 MlirStringRef name);
135
136/// Creates an LLVM identified struct type with no body and a name starting with
137/// the given prefix. If a struct with the exact name as the given prefix
138/// already exists, appends an unspecified suffix to the name so that the name
139/// is unique in context.
140MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeIdentifiedNewGet(
141 MlirContext ctx, MlirStringRef name, intptr_t nFieldTypes,
142 MlirType const *fieldTypes, bool isPacked);
143
144MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeOpaqueGet(MlirContext ctx,
145 MlirStringRef name);
146
147/// Sets the body of the identified struct if it hasn't been set yet. Returns
148/// whether the operation was successful.
149MLIR_CAPI_EXPORTED MlirLogicalResult
150mlirLLVMStructTypeSetBody(MlirType structType, intptr_t nFieldTypes,
151 MlirType const *fieldTypes, bool isPacked);
152
153enum MlirLLVMCConv {
154 MlirLLVMCConvC = 0,
155 MlirLLVMCConvFast = 8,
156 MlirLLVMCConvCold = 9,
157 MlirLLVMCConvGHC = 10,
158 MlirLLVMCConvHiPE = 11,
159 MlirLLVMCConvAnyReg = 13,
160 MlirLLVMCConvPreserveMost = 14,
161 MlirLLVMCConvPreserveAll = 15,
162 MlirLLVMCConvSwift = 16,
163 MlirLLVMCConvCXX_FAST_TLS = 17,
164 MlirLLVMCConvTail = 18,
165 MlirLLVMCConvCFGuard_Check = 19,
166 MlirLLVMCConvSwiftTail = 20,
167 MlirLLVMCConvPreserveNone = 21,
168 MlirLLVMCConvX86_StdCall = 64,
169 MlirLLVMCConvX86_FastCall = 65,
170 MlirLLVMCConvARM_APCS = 66,
171 MlirLLVMCConvARM_AAPCS = 67,
172 MlirLLVMCConvARM_AAPCS_VFP = 68,
173 MlirLLVMCConvMSP430_INTR = 69,
174 MlirLLVMCConvX86_ThisCall = 70,
175 MlirLLVMCConvPTX_Kernel = 71,
176 MlirLLVMCConvPTX_Device = 72,
177 MlirLLVMCConvSPIR_FUNC = 75,
178 MlirLLVMCConvSPIR_KERNEL = 76,
179 MlirLLVMCConvIntel_OCL_BI = 77,
180 MlirLLVMCConvX86_64_SysV = 78,
181 MlirLLVMCConvWin64 = 79,
182 MlirLLVMCConvX86_VectorCall = 80,
183 MlirLLVMCConvDUMMY_HHVM = 81,
184 MlirLLVMCConvDUMMY_HHVM_C = 82,
185 MlirLLVMCConvX86_INTR = 83,
186 MlirLLVMCConvAVR_INTR = 84,
187 MlirLLVMCConvAVR_BUILTIN = 86,
188 MlirLLVMCConvAMDGPU_VS = 87,
189 MlirLLVMCConvAMDGPU_GS = 88,
190 MlirLLVMCConvAMDGPU_CS = 90,
191 MlirLLVMCConvAMDGPU_KERNEL = 91,
192 MlirLLVMCConvX86_RegCall = 92,
193 MlirLLVMCConvAMDGPU_HS = 93,
194 MlirLLVMCConvMSP430_BUILTIN = 94,
195 MlirLLVMCConvAMDGPU_LS = 95,
196 MlirLLVMCConvAMDGPU_ES = 96,
197 MlirLLVMCConvAArch64_VectorCall = 97,
198 MlirLLVMCConvAArch64_SVE_VectorCall = 98,
199 MlirLLVMCConvWASM_EmscriptenInvoke = 99,
200 MlirLLVMCConvAMDGPU_Gfx = 100,
201 MlirLLVMCConvM68k_INTR = 101,
202};
203
204typedef enum MlirLLVMCConv MlirLLVMCConv;
205
206/// Creates a LLVM CConv attribute.
207MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx,
208 MlirLLVMCConv cconv);
209
210MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMCConvAttrGetName(void);
211
212enum MlirLLVMComdat {
213 MlirLLVMComdatAny = 0,
214 MlirLLVMComdatExactMatch = 1,
215 MlirLLVMComdatLargest = 2,
216 MlirLLVMComdatNoDeduplicate = 3,
217 MlirLLVMComdatSameSize = 4,
218};
219
220typedef enum MlirLLVMComdat MlirLLVMComdat;
221
222/// Creates a LLVM Comdat attribute.
223MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx,
224 MlirLLVMComdat comdat);
225
226MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMComdatAttrGetName(void);
227
228enum MlirLLVMLinkage {
229 MlirLLVMLinkageExternal = 0,
230 MlirLLVMLinkageAvailableExternally = 1,
231 MlirLLVMLinkageLinkonce = 2,
232 MlirLLVMLinkageLinkonceODR = 3,
233 MlirLLVMLinkageWeak = 4,
234 MlirLLVMLinkageWeakODR = 5,
235 MlirLLVMLinkageAppending = 6,
236 MlirLLVMLinkageInternal = 7,
237 MlirLLVMLinkagePrivate = 8,
238 MlirLLVMLinkageExternWeak = 9,
239 MlirLLVMLinkageCommon = 10,
240};
241
242typedef enum MlirLLVMLinkage MlirLLVMLinkage;
243
244/// Creates a LLVM Linkage attribute.
245MLIR_CAPI_EXPORTED MlirAttribute
246mlirLLVMLinkageAttrGet(MlirContext ctx, MlirLLVMLinkage linkage);
247
248MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMLinkageAttrGetName(void);
249
250/// Creates a LLVM DINullType attribute.
251MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx);
252
253MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDINullTypeAttrGetName(void);
254
255/// Creates a LLVM DIExpressionElem attribute.
256MLIR_CAPI_EXPORTED MlirAttribute
257mlirLLVMDIExpressionElemAttrGet(MlirContext ctx, unsigned int opcode,
258 intptr_t nArguments, uint64_t const *arguments);
259
260MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIExpressionElemAttrGetName(void);
261
262/// Creates a LLVM DIExpression attribute.
263MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIExpressionAttrGet(
264 MlirContext ctx, intptr_t nOperations, MlirAttribute const *operations);
265
266MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIExpressionAttrGetName(void);
267
268enum MlirLLVMTypeEncoding {
269 MlirLLVMTypeEncodingAddress = 0x1,
270 MlirLLVMTypeEncodingBoolean = 0x2,
271 MlirLLVMTypeEncodingComplexFloat = 0x31,
272 MlirLLVMTypeEncodingFloatT = 0x4,
273 MlirLLVMTypeEncodingSigned = 0x5,
274 MlirLLVMTypeEncodingSignedChar = 0x6,
275 MlirLLVMTypeEncodingUnsigned = 0x7,
276 MlirLLVMTypeEncodingUnsignedChar = 0x08,
277 MlirLLVMTypeEncodingImaginaryFloat = 0x09,
278 MlirLLVMTypeEncodingPackedDecimal = 0x0a,
279 MlirLLVMTypeEncodingNumericString = 0x0b,
280 MlirLLVMTypeEncodingEdited = 0x0c,
281 MlirLLVMTypeEncodingSignedFixed = 0x0d,
282 MlirLLVMTypeEncodingUnsignedFixed = 0x0e,
283 MlirLLVMTypeEncodingDecimalFloat = 0x0f,
284 MlirLLVMTypeEncodingUTF = 0x10,
285 MlirLLVMTypeEncodingUCS = 0x11,
286 MlirLLVMTypeEncodingASCII = 0x12,
287 MlirLLVMTypeEncodingLoUser = 0x80,
288 MlirLLVMTypeEncodingHiUser = 0xff,
289};
290
291typedef enum MlirLLVMTypeEncoding MlirLLVMTypeEncoding;
292
293/// Creates a LLVM DIBasicType attribute.
294MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIBasicTypeAttrGet(
295 MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits,
296 MlirLLVMTypeEncoding encoding);
297
298MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIBasicTypeAttrGetName(void);
299
300/// Creates a self-referencing LLVM DICompositeType attribute.
301MLIR_CAPI_EXPORTED MlirAttribute
302mlirLLVMDICompositeTypeAttrGetRecSelf(MlirAttribute recId);
303
304/// Creates a LLVM DICompositeType attribute.
305MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompositeTypeAttrGet(
306 MlirContext ctx, MlirAttribute recId, bool isRecSelf, unsigned int tag,
307 MlirAttribute name, MlirAttribute file, uint32_t line, MlirAttribute scope,
308 MlirAttribute baseType, int64_t flags, uint64_t sizeInBits,
309 uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements,
310 MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,
311 MlirAttribute associated, MlirAttribute identifier,
312 MlirAttribute discriminator);
313
314MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDICompositeTypeAttrGetName(void);
315
316/// Creates a LLVM DIDerivedType attribute. Note that `dwarfAddressSpace` is an
317/// optional field, where `MLIR_CAPI_DWARF_ADDRESS_SPACE_NULL` indicates null
318/// and non-negative values indicate a value present.
319MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIDerivedTypeAttrGet(
320 MlirContext ctx, unsigned int tag, MlirAttribute name, MlirAttribute file,
321 uint32_t line, MlirAttribute scope, MlirAttribute baseType,
322 uint64_t sizeInBits, uint32_t alignInBits, uint64_t offsetInBits,
323 int64_t dwarfAddressSpace, int64_t flags, MlirAttribute extraData);
324
325MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIDerivedTypeAttrGetName(void);
326
327MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIStringTypeAttrGet(
328 MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits,
329 uint32_t alignInBits, MlirAttribute stringLength,
330 MlirAttribute stringLengthExp, MlirAttribute stringLocationExp,
331 MlirLLVMTypeEncoding encoding, MlirAttribute charType);
332
333MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIStringTypeAttrGetName(void);
334
335/// Constant to represent std::nullopt for dwarfAddressSpace to omit the field.
336#define MLIR_CAPI_DWARF_ADDRESS_SPACE_NULL -1
337
338/// Gets the base type from a LLVM DIDerivedType attribute.
339MLIR_CAPI_EXPORTED MlirAttribute
340mlirLLVMDIDerivedTypeAttrGetBaseType(MlirAttribute diDerivedType);
341
342/// Creates a LLVM DIFileAttr attribute.
343MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx,
344 MlirAttribute name,
345 MlirAttribute directory);
346
347MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIFileAttrGetName(void);
348
349enum MlirLLVMDIEmissionKind {
350 MlirLLVMDIEmissionKindNone = 0,
351 MlirLLVMDIEmissionKindFull = 1,
352 MlirLLVMDIEmissionKindLineTablesOnly = 2,
353 MlirLLVMDIEmissionKindDebugDirectivesOnly = 3,
354};
355
356typedef enum MlirLLVMDIEmissionKind MlirLLVMDIEmissionKind;
357
358enum MlirLLVMDINameTableKind {
359 MlirLLVMDINameTableKindDefault = 0,
360 MlirLLVMDINameTableKindGNU = 1,
361 MlirLLVMDINameTableKindNone = 2,
362 MlirLLVMDINameTableKindApple = 3,
363};
364
365typedef enum MlirLLVMDINameTableKind MlirLLVMDINameTableKind;
366
367/// Creates a self-referencing LLVM DICompileUnitAttr attribute.
368MLIR_CAPI_EXPORTED MlirAttribute
369mlirLLVMDICompileUnitAttrGetRecSelf(MlirAttribute recId);
370
371/// Creates a LLVM DICompileUnit attribute.
372MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompileUnitAttrGet(
373 MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,
374 unsigned int sourceLanguage, MlirAttribute file, MlirAttribute producer,
375 bool isOptimized, MlirLLVMDIEmissionKind emissionKind,
376 bool isDebugInfoForProfiling, MlirLLVMDINameTableKind nameTableKind,
377 MlirAttribute splitDebugFilename, intptr_t nImportedEntities,
378 MlirAttribute const *importedEntities);
379
380/// Creates a LLVM DICompileUnit attribute with a source language dialect.
381MLIR_CAPI_EXPORTED MlirAttribute
382mlirLLVMDICompileUnitAttrGetWithSourceLanguageDialect(
383 MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,
384 unsigned int sourceLanguage, unsigned int sourceLanguageDialect,
385 MlirAttribute file, MlirAttribute producer, bool isOptimized,
386 MlirLLVMDIEmissionKind emissionKind, bool isDebugInfoForProfiling,
387 MlirLLVMDINameTableKind nameTableKind, MlirAttribute splitDebugFilename,
388 intptr_t nImportedEntities, MlirAttribute const *importedEntities);
389
390/// Creates an LLVM DICompileUnit attribute with a DWARF v6 source language
391/// name, version, and optional source language dialect.
392MLIR_CAPI_EXPORTED MlirAttribute
393mlirLLVMDICompileUnitAttrGetWithSourceLanguageName(
394 MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,
395 unsigned int sourceLanguageName, uint32_t sourceLanguageVersion,
396 unsigned int sourceLanguageDialect, MlirAttribute file,
397 MlirAttribute producer, bool isOptimized,
398 MlirLLVMDIEmissionKind emissionKind, bool isDebugInfoForProfiling,
399 MlirLLVMDINameTableKind nameTableKind, MlirAttribute splitDebugFilename,
400 intptr_t nImportedEntities, MlirAttribute const *importedEntities);
401
402MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDICompileUnitAttrGetName(void);
403
404/// Creates a LLVM DIFlags attribute.
405MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx,
406 uint64_t value);
407
408MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIFlagsAttrGetName(void);
409
410/// Creates a LLVM DILexicalBlock attribute.
411MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILexicalBlockAttrGet(
412 MlirContext ctx, MlirAttribute scope, MlirAttribute file, unsigned int line,
413 unsigned int column);
414
415MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDILexicalBlockAttrGetName(void);
416
417/// Creates a LLVM DILexicalBlockFile attribute.
418MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(
419 MlirContext ctx, MlirAttribute scope, MlirAttribute file,
420 unsigned int discriminator);
421
422MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDILexicalBlockFileAttrGetName(void);
423
424/// Creates a LLVM DILocalVariableAttr attribute.
425MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILocalVariableAttrGet(
426 MlirContext ctx, MlirAttribute scope, MlirAttribute name,
427 MlirAttribute diFile, unsigned int line, unsigned int arg,
428 unsigned int alignInBits, MlirAttribute diType, int64_t flags);
429
430MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDILocalVariableAttrGetName(void);
431
432/// Creates a self-referencing LLVM DISubprogramAttr attribute.
433MLIR_CAPI_EXPORTED MlirAttribute
434mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId);
435
436/// Creates a LLVM DISubprogramAttr attribute.
437MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDISubprogramAttrGet(
438 MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,
439 MlirAttribute compileUnit, MlirAttribute scope, MlirAttribute name,
440 MlirAttribute linkageName, MlirAttribute file, unsigned int line,
441 unsigned int scopeLine, uint64_t subprogramFlags, MlirAttribute type,
442 intptr_t nRetainedNodes, MlirAttribute const *retainedNodes,
443 intptr_t nAnnotations, MlirAttribute const *annotations);
444
445MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDISubprogramAttrGetName(void);
446
447/// Creates a LLVM DIAnnotation attribute.
448MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIAnnotationAttrGet(
449 MlirContext ctx, MlirAttribute name, MlirAttribute value);
450
451MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIAnnotationAttrGetName(void);
452
453/// Gets the scope from this DISubprogramAttr.
454MLIR_CAPI_EXPORTED MlirAttribute
455mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram);
456
457/// Gets the line from this DISubprogramAttr.
458MLIR_CAPI_EXPORTED unsigned int
459mlirLLVMDISubprogramAttrGetLine(MlirAttribute diSubprogram);
460
461/// Gets the scope line from this DISubprogram.
462MLIR_CAPI_EXPORTED unsigned int
463mlirLLVMDISubprogramAttrGetScopeLine(MlirAttribute diSubprogram);
464
465/// Gets the compile unit from this DISubprogram.
466MLIR_CAPI_EXPORTED MlirAttribute
467mlirLLVMDISubprogramAttrGetCompileUnit(MlirAttribute diSubprogram);
468
469/// Gets the file from this DISubprogramAttr.
470MLIR_CAPI_EXPORTED MlirAttribute
471mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram);
472
473/// Gets the type from this DISubprogramAttr.
474MLIR_CAPI_EXPORTED MlirAttribute
475mlirLLVMDISubprogramAttrGetType(MlirAttribute diSubprogram);
476
477/// Creates a LLVM DISubroutineTypeAttr attribute.
478MLIR_CAPI_EXPORTED MlirAttribute
479mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx, unsigned int callingConvention,
480 intptr_t nTypes, MlirAttribute const *types);
481
482MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDISubroutineTypeAttrGetName(void);
483
484/// Creates a LLVM DIModuleAttr attribute.
485MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIModuleAttrGet(
486 MlirContext ctx, MlirAttribute file, MlirAttribute scope,
487 MlirAttribute name, MlirAttribute configMacros, MlirAttribute includePath,
488 MlirAttribute apinotes, unsigned int line, bool isDecl);
489
490MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIModuleAttrGetName(void);
491
492/// Creates a LLVM DIImportedEntityAttr attribute.
493MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIImportedEntityAttrGet(
494 MlirContext ctx, unsigned int tag, MlirAttribute scope,
495 MlirAttribute entity, MlirAttribute file, unsigned int line,
496 MlirAttribute name, intptr_t nElements, MlirAttribute const *elements);
497
498MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIImportedEntityAttrGetName(void);
499
500/// Gets the scope of this DIModuleAttr.
501MLIR_CAPI_EXPORTED MlirAttribute
502mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule);
503
504//===----------------------------------------------------------------------===//
505// Metadata Attributes
506//===----------------------------------------------------------------------===//
507
508/// Creates an LLVM MDStringAttr.
509MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMMDStringAttrGet(MlirContext ctx,
510 MlirStringRef value);
511
512/// Returns `true` if the attribute is an LLVM MDStringAttr.
513MLIR_CAPI_EXPORTED bool mlirLLVMAttrIsAMDStringAttr(MlirAttribute attr);
514
515/// Returns the TypeID of MDStringAttr.
516MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMMDStringAttrGetTypeID(void);
517
518/// Returns the string value of an LLVM MDStringAttr.
519MLIR_CAPI_EXPORTED MlirStringRef
520mlirLLVMMDStringAttrGetValue(MlirAttribute attr);
521
522/// Creates an LLVM MDConstantAttr wrapping an attribute.
523MLIR_CAPI_EXPORTED MlirAttribute
524mlirLLVMMDConstantAttrGet(MlirContext ctx, MlirAttribute valueAttr);
525
526/// Returns `true` if the attribute is an LLVM MDConstantAttr.
527MLIR_CAPI_EXPORTED bool mlirLLVMAttrIsAMDConstantAttr(MlirAttribute attr);
528
529/// Returns the TypeID of MDConstantAttr.
530MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMMDConstantAttrGetTypeID(void);
531
532/// Returns the attribute value of an LLVM MDConstantAttr.
533MLIR_CAPI_EXPORTED MlirAttribute
534mlirLLVMMDConstantAttrGetValue(MlirAttribute attr);
535
536/// Creates an LLVM MDGlobalValueAttr referencing a symbol-backed global value.
537MLIR_CAPI_EXPORTED MlirAttribute
538mlirLLVMMDGlobalValueAttrGet(MlirContext ctx, MlirAttribute name);
539
540/// Returns `true` if the attribute is an LLVM MDGlobalValueAttr.
541MLIR_CAPI_EXPORTED bool mlirLLVMAttrIsAMDGlobalValueAttr(MlirAttribute attr);
542
543/// Returns the TypeID of MDGlobalValueAttr.
544MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMMDGlobalValueAttrGetTypeID(void);
545
546/// Returns the symbol name of an LLVM MDGlobalValueAttr.
547MLIR_CAPI_EXPORTED MlirAttribute
548mlirLLVMMDGlobalValueAttrGetName(MlirAttribute attr);
549
550/// Creates an LLVM MDNodeAttr.
551MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMMDNodeAttrGet(
552 MlirContext ctx, intptr_t nOperands, MlirAttribute const *operands);
553
554/// Returns `true` if the attribute is an LLVM MDNodeAttr.
555MLIR_CAPI_EXPORTED bool mlirLLVMAttrIsAMDNodeAttr(MlirAttribute attr);
556
557/// Returns the TypeID of MDNodeAttr.
558MLIR_CAPI_EXPORTED MlirTypeID mlirLLVMMDNodeAttrGetTypeID(void);
559
560/// Returns the number of operands in an LLVM MDNodeAttr.
561MLIR_CAPI_EXPORTED intptr_t
562mlirLLVMMDNodeAttrGetNumOperands(MlirAttribute attr);
563
564/// Returns the operand at the given index of an LLVM MDNodeAttr.
565MLIR_CAPI_EXPORTED MlirAttribute
566mlirLLVMMDNodeAttrGetOperand(MlirAttribute attr, intptr_t index);
567
568#ifdef __cplusplus
569}
570#endif
571
572#include "mlir/Dialect/LLVMIR/Transforms/Passes.capi.h.inc"
573
574#endif // MLIR_C_DIALECT_LLVM_H
575