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
26/// Returns `true` if the type is an LLVM dialect pointer type.
27MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMPointerType(MlirType type);
28
29/// Returns address space of llvm.ptr
30MLIR_CAPI_EXPORTED unsigned
31mlirLLVMPointerTypeGetAddressSpace(MlirType pointerType);
32
33/// Creates an llmv.void type.
34MLIR_CAPI_EXPORTED MlirType mlirLLVMVoidTypeGet(MlirContext ctx);
35
36/// Creates an llvm.array type.
37MLIR_CAPI_EXPORTED MlirType mlirLLVMArrayTypeGet(MlirType elementType,
38 unsigned numElements);
39
40/// Returns the element type of the llvm.array type.
41MLIR_CAPI_EXPORTED MlirType mlirLLVMArrayTypeGetElementType(MlirType type);
42
43/// Creates an llvm.func type.
44MLIR_CAPI_EXPORTED MlirType
45mlirLLVMFunctionTypeGet(MlirType resultType, intptr_t nArgumentTypes,
46 MlirType const *argumentTypes, bool isVarArg);
47
48/// Returns the number of input types.
49MLIR_CAPI_EXPORTED intptr_t mlirLLVMFunctionTypeGetNumInputs(MlirType type);
50
51/// Returns the pos-th input type.
52MLIR_CAPI_EXPORTED MlirType mlirLLVMFunctionTypeGetInput(MlirType type,
53 intptr_t pos);
54
55/// Returns the return type of the function type.
56MLIR_CAPI_EXPORTED MlirType mlirLLVMFunctionTypeGetReturnType(MlirType type);
57
58/// Returns `true` if the type is an LLVM dialect struct type.
59MLIR_CAPI_EXPORTED bool mlirTypeIsALLVMStructType(MlirType type);
60
61/// Returns `true` if the type is a literal (unnamed) LLVM struct type.
62MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsLiteral(MlirType type);
63
64/// Returns the number of fields in the struct. Asserts if the struct is opaque
65/// or not yet initialized.
66MLIR_CAPI_EXPORTED intptr_t mlirLLVMStructTypeGetNumElementTypes(MlirType type);
67
68/// Returns the `positions`-th field of the struct. Asserts if the struct is
69/// opaque, not yet initialized or if the position is out of range.
70MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeGetElementType(MlirType type,
71 intptr_t position);
72
73/// Returns `true` if the struct is packed.
74MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsPacked(MlirType type);
75
76/// Returns the identifier of the identified struct. Asserts that the struct is
77/// identified, i.e., not literal.
78MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMStructTypeGetIdentifier(MlirType type);
79
80/// Returns `true` is the struct is explicitly opaque (will not have a body) or
81/// uninitialized (will eventually have a body).
82MLIR_CAPI_EXPORTED bool mlirLLVMStructTypeIsOpaque(MlirType type);
83
84/// Creates an LLVM literal (unnamed) struct type. This may assert if the fields
85/// have types not compatible with the LLVM dialect. For a graceful failure, use
86/// the checked version.
87MLIR_CAPI_EXPORTED MlirType
88mlirLLVMStructTypeLiteralGet(MlirContext ctx, intptr_t nFieldTypes,
89 MlirType const *fieldTypes, bool isPacked);
90
91/// Creates an LLVM literal (unnamed) struct type if possible. Emits a
92/// diagnostic at the given location and returns null otherwise.
93MLIR_CAPI_EXPORTED MlirType
94mlirLLVMStructTypeLiteralGetChecked(MlirLocation loc, intptr_t nFieldTypes,
95 MlirType const *fieldTypes, bool isPacked);
96
97/// Creates an LLVM identified struct type with no body. If a struct type with
98/// this name already exists in the context, returns that type. Use
99/// mlirLLVMStructTypeIdentifiedNewGet to create a fresh struct type,
100/// potentially renaming it. The body should be set separatelty by calling
101/// mlirLLVMStructTypeSetBody, if it isn't set already.
102MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeIdentifiedGet(MlirContext ctx,
103 MlirStringRef name);
104
105/// Creates an LLVM identified struct type with no body and a name starting with
106/// the given prefix. If a struct with the exact name as the given prefix
107/// already exists, appends an unspecified suffix to the name so that the name
108/// is unique in context.
109MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeIdentifiedNewGet(
110 MlirContext ctx, MlirStringRef name, intptr_t nFieldTypes,
111 MlirType const *fieldTypes, bool isPacked);
112
113MLIR_CAPI_EXPORTED MlirType mlirLLVMStructTypeOpaqueGet(MlirContext ctx,
114 MlirStringRef name);
115
116/// Sets the body of the identified struct if it hasn't been set yet. Returns
117/// whether the operation was successful.
118MLIR_CAPI_EXPORTED MlirLogicalResult
119mlirLLVMStructTypeSetBody(MlirType structType, intptr_t nFieldTypes,
120 MlirType const *fieldTypes, bool isPacked);
121
122enum MlirLLVMCConv {
123 MlirLLVMCConvC = 0,
124 MlirLLVMCConvFast = 8,
125 MlirLLVMCConvCold = 9,
126 MlirLLVMCConvGHC = 10,
127 MlirLLVMCConvHiPE = 11,
128 MlirLLVMCConvAnyReg = 13,
129 MlirLLVMCConvPreserveMost = 14,
130 MlirLLVMCConvPreserveAll = 15,
131 MlirLLVMCConvSwift = 16,
132 MlirLLVMCConvCXX_FAST_TLS = 17,
133 MlirLLVMCConvTail = 18,
134 MlirLLVMCConvCFGuard_Check = 19,
135 MlirLLVMCConvSwiftTail = 20,
136 MlirLLVMCConvX86_StdCall = 64,
137 MlirLLVMCConvX86_FastCall = 65,
138 MlirLLVMCConvARM_APCS = 66,
139 MlirLLVMCConvARM_AAPCS = 67,
140 MlirLLVMCConvARM_AAPCS_VFP = 68,
141 MlirLLVMCConvMSP430_INTR = 69,
142 MlirLLVMCConvX86_ThisCall = 70,
143 MlirLLVMCConvPTX_Kernel = 71,
144 MlirLLVMCConvPTX_Device = 72,
145 MlirLLVMCConvSPIR_FUNC = 75,
146 MlirLLVMCConvSPIR_KERNEL = 76,
147 MlirLLVMCConvIntel_OCL_BI = 77,
148 MlirLLVMCConvX86_64_SysV = 78,
149 MlirLLVMCConvWin64 = 79,
150 MlirLLVMCConvX86_VectorCall = 80,
151 MlirLLVMCConvDUMMY_HHVM = 81,
152 MlirLLVMCConvDUMMY_HHVM_C = 82,
153 MlirLLVMCConvX86_INTR = 83,
154 MlirLLVMCConvAVR_INTR = 84,
155 MlirLLVMCConvAVR_BUILTIN = 86,
156 MlirLLVMCConvAMDGPU_VS = 87,
157 MlirLLVMCConvAMDGPU_GS = 88,
158 MlirLLVMCConvAMDGPU_CS = 90,
159 MlirLLVMCConvAMDGPU_KERNEL = 91,
160 MlirLLVMCConvX86_RegCall = 92,
161 MlirLLVMCConvAMDGPU_HS = 93,
162 MlirLLVMCConvMSP430_BUILTIN = 94,
163 MlirLLVMCConvAMDGPU_LS = 95,
164 MlirLLVMCConvAMDGPU_ES = 96,
165 MlirLLVMCConvAArch64_VectorCall = 97,
166 MlirLLVMCConvAArch64_SVE_VectorCall = 98,
167 MlirLLVMCConvWASM_EmscriptenInvoke = 99,
168 MlirLLVMCConvAMDGPU_Gfx = 100,
169 MlirLLVMCConvM68k_INTR = 101,
170};
171typedef enum MlirLLVMCConv MlirLLVMCConv;
172
173/// Creates a LLVM CConv attribute.
174MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMCConvAttrGet(MlirContext ctx,
175 MlirLLVMCConv cconv);
176
177enum MlirLLVMComdat {
178 MlirLLVMComdatAny = 0,
179 MlirLLVMComdatExactMatch = 1,
180 MlirLLVMComdatLargest = 2,
181 MlirLLVMComdatNoDeduplicate = 3,
182 MlirLLVMComdatSameSize = 4,
183};
184typedef enum MlirLLVMComdat MlirLLVMComdat;
185
186/// Creates a LLVM Comdat attribute.
187MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMComdatAttrGet(MlirContext ctx,
188 MlirLLVMComdat comdat);
189
190enum MlirLLVMLinkage {
191 MlirLLVMLinkageExternal = 0,
192 MlirLLVMLinkageAvailableExternally = 1,
193 MlirLLVMLinkageLinkonce = 2,
194 MlirLLVMLinkageLinkonceODR = 3,
195 MlirLLVMLinkageWeak = 4,
196 MlirLLVMLinkageWeakODR = 5,
197 MlirLLVMLinkageAppending = 6,
198 MlirLLVMLinkageInternal = 7,
199 MlirLLVMLinkagePrivate = 8,
200 MlirLLVMLinkageExternWeak = 9,
201 MlirLLVMLinkageCommon = 10,
202};
203typedef enum MlirLLVMLinkage MlirLLVMLinkage;
204
205/// Creates a LLVM Linkage attribute.
206MLIR_CAPI_EXPORTED MlirAttribute
207mlirLLVMLinkageAttrGet(MlirContext ctx, MlirLLVMLinkage linkage);
208
209/// Creates a LLVM DINullType attribute.
210MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDINullTypeAttrGet(MlirContext ctx);
211
212/// Creates a LLVM DIExpressionElem attribute.
213MLIR_CAPI_EXPORTED MlirAttribute
214mlirLLVMDIExpressionElemAttrGet(MlirContext ctx, unsigned int opcode,
215 intptr_t nArguments, uint64_t const *arguments);
216
217/// Creates a LLVM DIExpression attribute.
218MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIExpressionAttrGet(
219 MlirContext ctx, intptr_t nOperations, MlirAttribute const *operations);
220
221enum MlirLLVMTypeEncoding {
222 MlirLLVMTypeEncodingAddress = 0x1,
223 MlirLLVMTypeEncodingBoolean = 0x2,
224 MlirLLVMTypeEncodingComplexFloat = 0x31,
225 MlirLLVMTypeEncodingFloatT = 0x4,
226 MlirLLVMTypeEncodingSigned = 0x5,
227 MlirLLVMTypeEncodingSignedChar = 0x6,
228 MlirLLVMTypeEncodingUnsigned = 0x7,
229 MlirLLVMTypeEncodingUnsignedChar = 0x08,
230 MlirLLVMTypeEncodingImaginaryFloat = 0x09,
231 MlirLLVMTypeEncodingPackedDecimal = 0x0a,
232 MlirLLVMTypeEncodingNumericString = 0x0b,
233 MlirLLVMTypeEncodingEdited = 0x0c,
234 MlirLLVMTypeEncodingSignedFixed = 0x0d,
235 MlirLLVMTypeEncodingUnsignedFixed = 0x0e,
236 MlirLLVMTypeEncodingDecimalFloat = 0x0f,
237 MlirLLVMTypeEncodingUTF = 0x10,
238 MlirLLVMTypeEncodingUCS = 0x11,
239 MlirLLVMTypeEncodingASCII = 0x12,
240 MlirLLVMTypeEncodingLoUser = 0x80,
241 MlirLLVMTypeEncodingHiUser = 0xff,
242};
243typedef enum MlirLLVMTypeEncoding MlirLLVMTypeEncoding;
244
245/// Creates a LLVM DIBasicType attribute.
246MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIBasicTypeAttrGet(
247 MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits,
248 MlirLLVMTypeEncoding encoding);
249
250/// Creates a self-referencing LLVM DICompositeType attribute.
251MLIR_CAPI_EXPORTED MlirAttribute
252mlirLLVMDICompositeTypeAttrGetRecSelf(MlirAttribute recId);
253
254/// Creates a LLVM DICompositeType attribute.
255MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompositeTypeAttrGet(
256 MlirContext ctx, MlirAttribute recId, bool isRecSelf, unsigned int tag,
257 MlirAttribute name, MlirAttribute file, uint32_t line, MlirAttribute scope,
258 MlirAttribute baseType, int64_t flags, uint64_t sizeInBits,
259 uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements,
260 MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,
261 MlirAttribute associated);
262
263/// Creates a LLVM DIDerivedType attribute. Note that `dwarfAddressSpace` is an
264/// optional field, where `MLIR_CAPI_DWARF_ADDRESS_SPACE_NULL` indicates null
265/// and non-negative values indicate a value present.
266MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIDerivedTypeAttrGet(
267 MlirContext ctx, unsigned int tag, MlirAttribute name,
268 MlirAttribute baseType, uint64_t sizeInBits, uint32_t alignInBits,
269 uint64_t offsetInBits, int64_t dwarfAddressSpace, MlirAttribute extraData);
270
271MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIStringTypeAttrGet(
272 MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits,
273 uint32_t alignInBits, MlirAttribute stringLength,
274 MlirAttribute stringLengthExp, MlirAttribute stringLocationExp,
275 MlirLLVMTypeEncoding encoding);
276
277/// Constant to represent std::nullopt for dwarfAddressSpace to omit the field.
278#define MLIR_CAPI_DWARF_ADDRESS_SPACE_NULL -1
279
280/// Gets the base type from a LLVM DIDerivedType attribute.
281MLIR_CAPI_EXPORTED MlirAttribute
282mlirLLVMDIDerivedTypeAttrGetBaseType(MlirAttribute diDerivedType);
283
284/// Creates a LLVM DIFileAttr attribute.
285MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIFileAttrGet(MlirContext ctx,
286 MlirAttribute name,
287 MlirAttribute directory);
288
289enum MlirLLVMDIEmissionKind {
290 MlirLLVMDIEmissionKindNone = 0,
291 MlirLLVMDIEmissionKindFull = 1,
292 MlirLLVMDIEmissionKindLineTablesOnly = 2,
293 MlirLLVMDIEmissionKindDebugDirectivesOnly = 3,
294};
295typedef enum MlirLLVMDIEmissionKind MlirLLVMDIEmissionKind;
296
297enum MlirLLVMDINameTableKind {
298 MlirLLVMDINameTableKindDefault = 0,
299 MlirLLVMDINameTableKindGNU = 1,
300 MlirLLVMDINameTableKindNone = 2,
301 MlirLLVMDINameTableKindApple = 3,
302};
303typedef enum MlirLLVMDINameTableKind MlirLLVMDINameTableKind;
304
305/// Creates a LLVM DICompileUnit attribute.
306MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompileUnitAttrGet(
307 MlirContext ctx, MlirAttribute id, unsigned int sourceLanguage,
308 MlirAttribute file, MlirAttribute producer, bool isOptimized,
309 MlirLLVMDIEmissionKind emissionKind, MlirLLVMDINameTableKind nameTableKind);
310
311/// Creates a LLVM DIFlags attribute.
312MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIFlagsAttrGet(MlirContext ctx,
313 uint64_t value);
314
315/// Creates a LLVM DILexicalBlock attribute.
316MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILexicalBlockAttrGet(
317 MlirContext ctx, MlirAttribute scope, MlirAttribute file, unsigned int line,
318 unsigned int column);
319
320/// Creates a LLVM DILexicalBlockFile attribute.
321MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILexicalBlockFileAttrGet(
322 MlirContext ctx, MlirAttribute scope, MlirAttribute file,
323 unsigned int discriminator);
324
325/// Creates a LLVM DILocalVariableAttr attribute.
326MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILocalVariableAttrGet(
327 MlirContext ctx, MlirAttribute scope, MlirAttribute name,
328 MlirAttribute diFile, unsigned int line, unsigned int arg,
329 unsigned int alignInBits, MlirAttribute diType, int64_t flags);
330
331/// Creates a self-referencing LLVM DISubprogramAttr attribute.
332MLIR_CAPI_EXPORTED MlirAttribute
333mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId);
334
335/// Creates a LLVM DISubprogramAttr attribute.
336MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDISubprogramAttrGet(
337 MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,
338 MlirAttribute compileUnit, MlirAttribute scope, MlirAttribute name,
339 MlirAttribute linkageName, MlirAttribute file, unsigned int line,
340 unsigned int scopeLine, uint64_t subprogramFlags, MlirAttribute type,
341 intptr_t nRetainedNodes, MlirAttribute const *retainedNodes,
342 intptr_t nAnnotations, MlirAttribute const *annotations);
343
344/// Creates a LLVM DIAnnotation attribute.
345MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIAnnotationAttrGet(
346 MlirContext ctx, MlirAttribute name, MlirAttribute value);
347
348/// Gets the scope from this DISubprogramAttr.
349MLIR_CAPI_EXPORTED MlirAttribute
350mlirLLVMDISubprogramAttrGetScope(MlirAttribute diSubprogram);
351
352/// Gets the line from this DISubprogramAttr.
353MLIR_CAPI_EXPORTED unsigned int
354mlirLLVMDISubprogramAttrGetLine(MlirAttribute diSubprogram);
355
356/// Gets the scope line from this DISubprogram.
357MLIR_CAPI_EXPORTED unsigned int
358mlirLLVMDISubprogramAttrGetScopeLine(MlirAttribute diSubprogram);
359
360/// Gets the compile unit from this DISubprogram.
361MLIR_CAPI_EXPORTED MlirAttribute
362mlirLLVMDISubprogramAttrGetCompileUnit(MlirAttribute diSubprogram);
363
364/// Gets the file from this DISubprogramAttr.
365MLIR_CAPI_EXPORTED MlirAttribute
366mlirLLVMDISubprogramAttrGetFile(MlirAttribute diSubprogram);
367
368/// Gets the type from this DISubprogramAttr.
369MLIR_CAPI_EXPORTED MlirAttribute
370mlirLLVMDISubprogramAttrGetType(MlirAttribute diSubprogram);
371
372/// Creates a LLVM DISubroutineTypeAttr attribute.
373MLIR_CAPI_EXPORTED MlirAttribute
374mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx, unsigned int callingConvention,
375 intptr_t nTypes, MlirAttribute const *types);
376
377/// Creates a LLVM DIModuleAttr attribute.
378MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIModuleAttrGet(
379 MlirContext ctx, MlirAttribute file, MlirAttribute scope,
380 MlirAttribute name, MlirAttribute configMacros, MlirAttribute includePath,
381 MlirAttribute apinotes, unsigned int line, bool isDecl);
382
383/// Creates a LLVM DIImportedEntityAttr attribute.
384MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIImportedEntityAttrGet(
385 MlirContext ctx, unsigned int tag, MlirAttribute scope,
386 MlirAttribute entity, MlirAttribute file, unsigned int line,
387 MlirAttribute name, intptr_t nElements, MlirAttribute const *elements);
388
389/// Gets the scope of this DIModuleAttr.
390MLIR_CAPI_EXPORTED MlirAttribute
391mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule);
392
393#ifdef __cplusplus
394}
395#endif
396
397#endif // MLIR_C_DIALECT_LLVM_H
398

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of mlir/include/mlir-c/Dialect/LLVM.h