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

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