1//===-- mlir-c/BuiltinTypes.h - C API for MLIR Builtin types ------*- 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_BUILTINTYPES_H
11#define MLIR_C_BUILTINTYPES_H
12
13#include "mlir-c/AffineMap.h"
14#include "mlir-c/IR.h"
15#include <stdint.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21//===----------------------------------------------------------------------===//
22// Integer types.
23//===----------------------------------------------------------------------===//
24
25/// Returns the typeID of an Integer type.
26MLIR_CAPI_EXPORTED MlirTypeID mlirIntegerTypeGetTypeID(void);
27
28/// Checks whether the given type is an integer type.
29MLIR_CAPI_EXPORTED bool mlirTypeIsAInteger(MlirType type);
30
31/// Creates a signless integer type of the given bitwidth in the context. The
32/// type is owned by the context.
33MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeGet(MlirContext ctx,
34 unsigned bitwidth);
35
36MLIR_CAPI_EXPORTED MlirStringRef mlirIntegerTypeGetName(void);
37
38/// Creates a signed integer type of the given bitwidth in the context. The type
39/// is owned by the context.
40MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeSignedGet(MlirContext ctx,
41 unsigned bitwidth);
42
43/// Creates an unsigned integer type of the given bitwidth in the context. The
44/// type is owned by the context.
45MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeUnsignedGet(MlirContext ctx,
46 unsigned bitwidth);
47
48/// Returns the bitwidth of an integer type.
49MLIR_CAPI_EXPORTED unsigned mlirIntegerTypeGetWidth(MlirType type);
50
51/// Checks whether the given integer type is signless.
52MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsSignless(MlirType type);
53
54/// Checks whether the given integer type is signed.
55MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsSigned(MlirType type);
56
57/// Checks whether the given integer type is unsigned.
58MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsUnsigned(MlirType type);
59
60//===----------------------------------------------------------------------===//
61// Index type.
62//===----------------------------------------------------------------------===//
63
64/// Returns the typeID of an Index type.
65MLIR_CAPI_EXPORTED MlirTypeID mlirIndexTypeGetTypeID(void);
66
67/// Checks whether the given type is an index type.
68MLIR_CAPI_EXPORTED bool mlirTypeIsAIndex(MlirType type);
69
70/// Creates an index type in the given context. The type is owned by the
71/// context.
72MLIR_CAPI_EXPORTED MlirType mlirIndexTypeGet(MlirContext ctx);
73
74MLIR_CAPI_EXPORTED MlirStringRef mlirIndexTypeGetName(void);
75
76//===----------------------------------------------------------------------===//
77// Floating-point types.
78//===----------------------------------------------------------------------===//
79
80/// Checks whether the given type is a floating-point type.
81MLIR_CAPI_EXPORTED bool mlirTypeIsAFloat(MlirType type);
82
83/// Returns the bitwidth of a floating-point type.
84MLIR_CAPI_EXPORTED unsigned mlirFloatTypeGetWidth(MlirType type);
85
86/// Returns the typeID of an Float4E2M1FN type.
87MLIR_CAPI_EXPORTED MlirTypeID mlirFloat4E2M1FNTypeGetTypeID(void);
88
89/// Checks whether the given type is an f4E2M1FN type.
90MLIR_CAPI_EXPORTED bool mlirTypeIsAFloat4E2M1FN(MlirType type);
91
92/// Creates an f4E2M1FN type in the given context. The type is owned by the
93/// context.
94MLIR_CAPI_EXPORTED MlirType mlirFloat4E2M1FNTypeGet(MlirContext ctx);
95
96MLIR_CAPI_EXPORTED MlirStringRef mlirFloat4E2M1FNTypeGetName(void);
97
98/// Returns the typeID of an Float6E2M3FN type.
99MLIR_CAPI_EXPORTED MlirTypeID mlirFloat6E2M3FNTypeGetTypeID(void);
100
101/// Checks whether the given type is an f6E2M3FN type.
102MLIR_CAPI_EXPORTED bool mlirTypeIsAFloat6E2M3FN(MlirType type);
103
104/// Creates an f6E2M3FN type in the given context. The type is owned by the
105/// context.
106MLIR_CAPI_EXPORTED MlirType mlirFloat6E2M3FNTypeGet(MlirContext ctx);
107
108MLIR_CAPI_EXPORTED MlirStringRef mlirFloat6E2M3FNTypeGetName(void);
109
110/// Returns the typeID of an Float6E3M2FN type.
111MLIR_CAPI_EXPORTED MlirTypeID mlirFloat6E3M2FNTypeGetTypeID(void);
112
113/// Checks whether the given type is an f6E3M2FN type.
114MLIR_CAPI_EXPORTED bool mlirTypeIsAFloat6E3M2FN(MlirType type);
115
116/// Creates an f6E3M2FN type in the given context. The type is owned by the
117/// context.
118MLIR_CAPI_EXPORTED MlirType mlirFloat6E3M2FNTypeGet(MlirContext ctx);
119
120MLIR_CAPI_EXPORTED MlirStringRef mlirFloat6E3M2FNTypeGetName(void);
121
122/// Returns the typeID of an Float8E5M2 type.
123MLIR_CAPI_EXPORTED MlirTypeID mlirFloat8E5M2TypeGetTypeID(void);
124
125/// Checks whether the given type is an f8E5M2 type.
126MLIR_CAPI_EXPORTED bool mlirTypeIsAFloat8E5M2(MlirType type);
127
128/// Creates an f8E5M2 type in the given context. The type is owned by the
129/// context.
130MLIR_CAPI_EXPORTED MlirType mlirFloat8E5M2TypeGet(MlirContext ctx);
131
132MLIR_CAPI_EXPORTED MlirStringRef mlirFloat8E5M2TypeGetName(void);
133
134/// Returns the typeID of an Float8E4M3 type.
135MLIR_CAPI_EXPORTED MlirTypeID mlirFloat8E4M3TypeGetTypeID(void);
136
137/// Checks whether the given type is an f8E4M3 type.
138MLIR_CAPI_EXPORTED bool mlirTypeIsAFloat8E4M3(MlirType type);
139
140/// Creates an f8E4M3 type in the given context. The type is owned by the
141/// context.
142MLIR_CAPI_EXPORTED MlirType mlirFloat8E4M3TypeGet(MlirContext ctx);
143
144MLIR_CAPI_EXPORTED MlirStringRef mlirFloat8E4M3TypeGetName(void);
145
146/// Returns the typeID of an Float8E4M3FN type.
147MLIR_CAPI_EXPORTED MlirTypeID mlirFloat8E4M3FNTypeGetTypeID(void);
148
149/// Checks whether the given type is an f8E4M3FN type.
150MLIR_CAPI_EXPORTED bool mlirTypeIsAFloat8E4M3FN(MlirType type);
151
152/// Creates an f8E4M3FN type in the given context. The type is owned by the
153/// context.
154MLIR_CAPI_EXPORTED MlirType mlirFloat8E4M3FNTypeGet(MlirContext ctx);
155
156MLIR_CAPI_EXPORTED MlirStringRef mlirFloat8E4M3FNTypeGetName(void);
157
158/// Returns the typeID of an Float8E5M2FNUZ type.
159MLIR_CAPI_EXPORTED MlirTypeID mlirFloat8E5M2FNUZTypeGetTypeID(void);
160
161/// Checks whether the given type is an f8E5M2FNUZ type.
162MLIR_CAPI_EXPORTED bool mlirTypeIsAFloat8E5M2FNUZ(MlirType type);
163
164/// Creates an f8E5M2FNUZ type in the given context. The type is owned by the
165/// context.
166MLIR_CAPI_EXPORTED MlirType mlirFloat8E5M2FNUZTypeGet(MlirContext ctx);
167
168MLIR_CAPI_EXPORTED MlirStringRef mlirFloat8E5M2FNUZTypeGetName(void);
169
170/// Returns the typeID of an Float8E4M3FNUZ type.
171MLIR_CAPI_EXPORTED MlirTypeID mlirFloat8E4M3FNUZTypeGetTypeID(void);
172
173/// Checks whether the given type is an f8E4M3FNUZ type.
174MLIR_CAPI_EXPORTED bool mlirTypeIsAFloat8E4M3FNUZ(MlirType type);
175
176/// Creates an f8E4M3FNUZ type in the given context. The type is owned by the
177/// context.
178MLIR_CAPI_EXPORTED MlirType mlirFloat8E4M3FNUZTypeGet(MlirContext ctx);
179
180MLIR_CAPI_EXPORTED MlirStringRef mlirFloat8E4M3FNUZTypeGetName(void);
181
182/// Returns the typeID of an Float8E4M3B11FNUZ type.
183MLIR_CAPI_EXPORTED MlirTypeID mlirFloat8E4M3B11FNUZTypeGetTypeID(void);
184
185/// Checks whether the given type is an f8E4M3B11FNUZ type.
186MLIR_CAPI_EXPORTED bool mlirTypeIsAFloat8E4M3B11FNUZ(MlirType type);
187
188/// Creates an f8E4M3B11FNUZ type in the given context. The type is owned by the
189/// context.
190MLIR_CAPI_EXPORTED MlirType mlirFloat8E4M3B11FNUZTypeGet(MlirContext ctx);
191
192MLIR_CAPI_EXPORTED MlirStringRef mlirFloat8E4M3B11FNUZTypeGetName(void);
193
194/// Returns the typeID of an Float8E3M4 type.
195MLIR_CAPI_EXPORTED MlirTypeID mlirFloat8E3M4TypeGetTypeID(void);
196
197/// Checks whether the given type is an f8E3M4 type.
198MLIR_CAPI_EXPORTED bool mlirTypeIsAFloat8E3M4(MlirType type);
199
200/// Creates an f8E3M4 type in the given context. The type is owned by the
201/// context.
202MLIR_CAPI_EXPORTED MlirType mlirFloat8E3M4TypeGet(MlirContext ctx);
203
204MLIR_CAPI_EXPORTED MlirStringRef mlirFloat8E3M4TypeGetName(void);
205
206/// Returns the typeID of an Float8E8M0FNU type.
207MLIR_CAPI_EXPORTED MlirTypeID mlirFloat8E8M0FNUTypeGetTypeID(void);
208
209/// Checks whether the given type is an f8E8M0FNU type.
210MLIR_CAPI_EXPORTED bool mlirTypeIsAFloat8E8M0FNU(MlirType type);
211
212/// Creates an f8E8M0FNU type in the given context. The type is owned by the
213/// context.
214MLIR_CAPI_EXPORTED MlirType mlirFloat8E8M0FNUTypeGet(MlirContext ctx);
215
216MLIR_CAPI_EXPORTED MlirStringRef mlirFloat8E8M0FNUTypeGetName(void);
217
218/// Returns the typeID of a Float8E5M3FNU type.
219MLIR_CAPI_EXPORTED MlirTypeID mlirFloat8E5M3FNUTypeGetTypeID(void);
220
221/// Checks whether the given type is an f8E5M3FNU type.
222MLIR_CAPI_EXPORTED bool mlirTypeIsAFloat8E5M3FNU(MlirType type);
223
224/// Creates an f8E5M3FNU type in the given context. The type is owned by the
225/// context.
226MLIR_CAPI_EXPORTED MlirType mlirFloat8E5M3FNUTypeGet(MlirContext ctx);
227
228MLIR_CAPI_EXPORTED MlirStringRef mlirFloat8E5M3FNUTypeGetName(void);
229
230/// Returns the typeID of an BFloat16 type.
231MLIR_CAPI_EXPORTED MlirTypeID mlirBFloat16TypeGetTypeID(void);
232
233/// Checks whether the given type is a bf16 type.
234MLIR_CAPI_EXPORTED bool mlirTypeIsABF16(MlirType type);
235
236/// Creates a bf16 type in the given context. The type is owned by the
237/// context.
238MLIR_CAPI_EXPORTED MlirType mlirBF16TypeGet(MlirContext ctx);
239
240MLIR_CAPI_EXPORTED MlirStringRef mlirBF16TypeGetName(void);
241
242/// Returns the typeID of an Float16 type.
243MLIR_CAPI_EXPORTED MlirTypeID mlirFloat16TypeGetTypeID(void);
244
245/// Checks whether the given type is an f16 type.
246MLIR_CAPI_EXPORTED bool mlirTypeIsAF16(MlirType type);
247
248/// Creates an f16 type in the given context. The type is owned by the
249/// context.
250MLIR_CAPI_EXPORTED MlirType mlirF16TypeGet(MlirContext ctx);
251
252MLIR_CAPI_EXPORTED MlirStringRef mlirF16TypeGetName(void);
253
254/// Returns the typeID of an Float32 type.
255MLIR_CAPI_EXPORTED MlirTypeID mlirFloat32TypeGetTypeID(void);
256
257/// Checks whether the given type is an f32 type.
258MLIR_CAPI_EXPORTED bool mlirTypeIsAF32(MlirType type);
259
260/// Creates an f32 type in the given context. The type is owned by the
261/// context.
262MLIR_CAPI_EXPORTED MlirType mlirF32TypeGet(MlirContext ctx);
263
264MLIR_CAPI_EXPORTED MlirStringRef mlirF32TypeGetName(void);
265
266/// Returns the typeID of an Float64 type.
267MLIR_CAPI_EXPORTED MlirTypeID mlirFloat64TypeGetTypeID(void);
268
269/// Checks whether the given type is an f64 type.
270MLIR_CAPI_EXPORTED bool mlirTypeIsAF64(MlirType type);
271
272/// Creates a f64 type in the given context. The type is owned by the
273/// context.
274MLIR_CAPI_EXPORTED MlirType mlirF64TypeGet(MlirContext ctx);
275
276MLIR_CAPI_EXPORTED MlirStringRef mlirF64TypeGetName(void);
277
278/// Returns the typeID of a TF32 type.
279MLIR_CAPI_EXPORTED MlirTypeID mlirFloatTF32TypeGetTypeID(void);
280
281/// Checks whether the given type is an TF32 type.
282MLIR_CAPI_EXPORTED bool mlirTypeIsATF32(MlirType type);
283
284/// Creates a TF32 type in the given context. The type is owned by the
285/// context.
286MLIR_CAPI_EXPORTED MlirType mlirTF32TypeGet(MlirContext ctx);
287
288MLIR_CAPI_EXPORTED MlirStringRef mlirTF32TypeGetName(void);
289
290//===----------------------------------------------------------------------===//
291// None type.
292//===----------------------------------------------------------------------===//
293
294/// Returns the typeID of an None type.
295MLIR_CAPI_EXPORTED MlirTypeID mlirNoneTypeGetTypeID(void);
296
297/// Checks whether the given type is a None type.
298MLIR_CAPI_EXPORTED bool mlirTypeIsANone(MlirType type);
299
300/// Creates a None type in the given context. The type is owned by the
301/// context.
302MLIR_CAPI_EXPORTED MlirType mlirNoneTypeGet(MlirContext ctx);
303
304MLIR_CAPI_EXPORTED MlirStringRef mlirNoneTypeGetName(void);
305
306//===----------------------------------------------------------------------===//
307// Complex type.
308//===----------------------------------------------------------------------===//
309
310/// Returns the typeID of an Complex type.
311MLIR_CAPI_EXPORTED MlirTypeID mlirComplexTypeGetTypeID(void);
312
313/// Checks whether the given type is a Complex type.
314MLIR_CAPI_EXPORTED bool mlirTypeIsAComplex(MlirType type);
315
316/// Creates a complex type with the given element type in the same context as
317/// the element type. The type is owned by the context.
318MLIR_CAPI_EXPORTED MlirType mlirComplexTypeGet(MlirType elementType);
319
320MLIR_CAPI_EXPORTED MlirStringRef mlirComplexTypeGetName(void);
321
322/// Returns the element type of the given complex type.
323MLIR_CAPI_EXPORTED MlirType mlirComplexTypeGetElementType(MlirType type);
324
325//===----------------------------------------------------------------------===//
326// Shaped type.
327//===----------------------------------------------------------------------===//
328
329/// Checks whether the given type is a Shaped type.
330MLIR_CAPI_EXPORTED bool mlirTypeIsAShaped(MlirType type);
331
332/// Returns the element type of the shaped type.
333MLIR_CAPI_EXPORTED MlirType mlirShapedTypeGetElementType(MlirType type);
334
335/// Checks whether the given shaped type is ranked.
336MLIR_CAPI_EXPORTED bool mlirShapedTypeHasRank(MlirType type);
337
338/// Returns the rank of the given ranked shaped type.
339MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetRank(MlirType type);
340
341/// Checks whether the given shaped type has a static shape.
342MLIR_CAPI_EXPORTED bool mlirShapedTypeHasStaticShape(MlirType type);
343
344/// Checks whether the dim-th dimension of the given shaped type is dynamic.
345MLIR_CAPI_EXPORTED bool mlirShapedTypeIsDynamicDim(MlirType type, intptr_t dim);
346
347/// Checks whether the dim-th dimension of the given shaped type is static.
348MLIR_CAPI_EXPORTED bool mlirShapedTypeIsStaticDim(MlirType type, intptr_t dim);
349
350/// Returns the dim-th dimension of the given ranked shaped type.
351MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetDimSize(MlirType type,
352 intptr_t dim);
353
354/// Checks whether the given value is used as a placeholder for dynamic sizes
355/// in shaped types.
356MLIR_CAPI_EXPORTED bool mlirShapedTypeIsDynamicSize(int64_t size);
357
358/// Checks whether the given shaped type dimension value is statically-sized.
359MLIR_CAPI_EXPORTED bool mlirShapedTypeIsStaticSize(int64_t size);
360
361/// Returns the value indicating a dynamic size in a shaped type. Prefer
362/// mlirShapedTypeIsDynamicSize and mlirShapedTypeIsStaticSize to direct
363/// comparisons with this value.
364MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetDynamicSize(void);
365
366/// Checks whether the given value is used as a placeholder for dynamic strides
367/// and offsets in shaped types.
368MLIR_CAPI_EXPORTED bool mlirShapedTypeIsDynamicStrideOrOffset(int64_t val);
369
370/// Checks whether the given dimension value of a stride or an offset is
371/// statically-sized.
372MLIR_CAPI_EXPORTED bool mlirShapedTypeIsStaticStrideOrOffset(int64_t val);
373
374/// Returns the value indicating a dynamic stride or offset in a shaped type.
375/// Prefer mlirShapedTypeIsDynamicStrideOrOffset and
376/// mlirShapedTypeIsStaticStrideOrOffset to direct comparisons with this value.
377MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetDynamicStrideOrOffset(void);
378
379//===----------------------------------------------------------------------===//
380// Vector type.
381//===----------------------------------------------------------------------===//
382
383/// Returns the typeID of an Vector type.
384MLIR_CAPI_EXPORTED MlirTypeID mlirVectorTypeGetTypeID(void);
385
386/// Checks whether the given type is a Vector type.
387MLIR_CAPI_EXPORTED bool mlirTypeIsAVector(MlirType type);
388
389/// Creates a vector type of the shape identified by its rank and dimensions,
390/// with the given element type in the same context as the element type. The
391/// type is owned by the context.
392MLIR_CAPI_EXPORTED MlirType mlirVectorTypeGet(intptr_t rank,
393 const int64_t *shape,
394 MlirType elementType);
395
396MLIR_CAPI_EXPORTED MlirStringRef mlirVectorTypeGetName(void);
397
398/// Same as "mlirVectorTypeGet" but returns a nullptr wrapping MlirType on
399/// illegal arguments, emitting appropriate diagnostics.
400MLIR_CAPI_EXPORTED MlirType mlirVectorTypeGetChecked(MlirLocation loc,
401 intptr_t rank,
402 const int64_t *shape,
403 MlirType elementType);
404
405/// Creates a scalable vector type with the shape identified by its rank and
406/// dimensions. A subset of dimensions may be marked as scalable via the
407/// corresponding flag list, which is expected to have as many entries as the
408/// rank of the vector. The vector is created in the same context as the element
409/// type.
410MLIR_CAPI_EXPORTED MlirType mlirVectorTypeGetScalable(intptr_t rank,
411 const int64_t *shape,
412 const bool *scalable,
413 MlirType elementType);
414
415/// Same as "mlirVectorTypeGetScalable" but returns a nullptr wrapping MlirType
416/// on illegal arguments, emitting appropriate diagnostics.
417MLIR_CAPI_EXPORTED
418MlirType mlirVectorTypeGetScalableChecked(MlirLocation loc, intptr_t rank,
419 const int64_t *shape,
420 const bool *scalable,
421 MlirType elementType);
422
423/// Checks whether the given vector type is scalable, i.e., has at least one
424/// scalable dimension.
425MLIR_CAPI_EXPORTED bool mlirVectorTypeIsScalable(MlirType type);
426
427/// Checks whether the "dim"-th dimension of the given vector is scalable.
428MLIR_CAPI_EXPORTED bool mlirVectorTypeIsDimScalable(MlirType type,
429 intptr_t dim);
430
431//===----------------------------------------------------------------------===//
432// Ranked / Unranked Tensor type.
433//===----------------------------------------------------------------------===//
434
435/// Checks whether the given type is a Tensor type.
436MLIR_CAPI_EXPORTED bool mlirTypeIsATensor(MlirType type);
437
438/// Returns the typeID of an RankedTensor type.
439MLIR_CAPI_EXPORTED MlirTypeID mlirRankedTensorTypeGetTypeID(void);
440
441/// Checks whether the given type is a ranked tensor type.
442MLIR_CAPI_EXPORTED bool mlirTypeIsARankedTensor(MlirType type);
443
444/// Returns the typeID of an UnrankedTensor type.
445MLIR_CAPI_EXPORTED MlirTypeID mlirUnrankedTensorTypeGetTypeID(void);
446
447/// Checks whether the given type is an unranked tensor type.
448MLIR_CAPI_EXPORTED bool mlirTypeIsAUnrankedTensor(MlirType type);
449
450/// Creates a tensor type of a fixed rank with the given shape, element type,
451/// and optional encoding in the same context as the element type. The type is
452/// owned by the context. Tensor types without any specific encoding field
453/// should assign mlirAttributeGetNull() to this parameter.
454MLIR_CAPI_EXPORTED MlirType mlirRankedTensorTypeGet(intptr_t rank,
455 const int64_t *shape,
456 MlirType elementType,
457 MlirAttribute encoding);
458
459MLIR_CAPI_EXPORTED MlirStringRef mlirRankedTensorTypeGetName(void);
460
461/// Same as "mlirRankedTensorTypeGet" but returns a nullptr wrapping MlirType on
462/// illegal arguments, emitting appropriate diagnostics.
463MLIR_CAPI_EXPORTED MlirType mlirRankedTensorTypeGetChecked(
464 MlirLocation loc, intptr_t rank, const int64_t *shape, MlirType elementType,
465 MlirAttribute encoding);
466
467/// Gets the 'encoding' attribute from the ranked tensor type, returning a null
468/// attribute if none.
469MLIR_CAPI_EXPORTED MlirAttribute mlirRankedTensorTypeGetEncoding(MlirType type);
470
471/// Creates an unranked tensor type with the given element type in the same
472/// context as the element type. The type is owned by the context.
473MLIR_CAPI_EXPORTED MlirType mlirUnrankedTensorTypeGet(MlirType elementType);
474
475MLIR_CAPI_EXPORTED MlirStringRef mlirUnrankedTensorTypeGetName(void);
476
477/// Same as "mlirUnrankedTensorTypeGet" but returns a nullptr wrapping MlirType
478/// on illegal arguments, emitting appropriate diagnostics.
479MLIR_CAPI_EXPORTED MlirType
480mlirUnrankedTensorTypeGetChecked(MlirLocation loc, MlirType elementType);
481
482//===----------------------------------------------------------------------===//
483// Ranked / Unranked MemRef type.
484//===----------------------------------------------------------------------===//
485
486/// Returns the typeID of an MemRef type.
487MLIR_CAPI_EXPORTED MlirTypeID mlirMemRefTypeGetTypeID(void);
488
489/// Checks whether the given type is a MemRef type.
490MLIR_CAPI_EXPORTED bool mlirTypeIsAMemRef(MlirType type);
491
492/// Returns the typeID of an UnrankedMemRef type.
493MLIR_CAPI_EXPORTED MlirTypeID mlirUnrankedMemRefTypeGetTypeID(void);
494
495/// Checks whether the given type is an UnrankedMemRef type.
496MLIR_CAPI_EXPORTED bool mlirTypeIsAUnrankedMemRef(MlirType type);
497
498/// Creates a MemRef type with the given rank and shape, a potentially empty
499/// list of affine layout maps, the given memory space and element type, in the
500/// same context as element type. The type is owned by the context.
501MLIR_CAPI_EXPORTED MlirType mlirMemRefTypeGet(MlirType elementType,
502 intptr_t rank,
503 const int64_t *shape,
504 MlirAttribute layout,
505 MlirAttribute memorySpace);
506
507MLIR_CAPI_EXPORTED MlirStringRef mlirMemRefTypeGetName(void);
508
509/// Same as "mlirMemRefTypeGet" but returns a nullptr-wrapping MlirType o
510/// illegal arguments, emitting appropriate diagnostics.
511MLIR_CAPI_EXPORTED MlirType mlirMemRefTypeGetChecked(
512 MlirLocation loc, MlirType elementType, intptr_t rank, const int64_t *shape,
513 MlirAttribute layout, MlirAttribute memorySpace);
514
515/// Creates a MemRef type with the given rank, shape, memory space and element
516/// type in the same context as the element type. The type has no affine maps,
517/// i.e. represents a default row-major contiguous memref. The type is owned by
518/// the context.
519MLIR_CAPI_EXPORTED MlirType
520mlirMemRefTypeContiguousGet(MlirType elementType, intptr_t rank,
521 const int64_t *shape, MlirAttribute memorySpace);
522
523/// Same as "mlirMemRefTypeContiguousGet" but returns a nullptr wrapping
524/// MlirType on illegal arguments, emitting appropriate diagnostics.
525MLIR_CAPI_EXPORTED MlirType mlirMemRefTypeContiguousGetChecked(
526 MlirLocation loc, MlirType elementType, intptr_t rank, const int64_t *shape,
527 MlirAttribute memorySpace);
528
529/// Creates an Unranked MemRef type with the given element type and in the given
530/// memory space. The type is owned by the context of element type.
531MLIR_CAPI_EXPORTED MlirType
532mlirUnrankedMemRefTypeGet(MlirType elementType, MlirAttribute memorySpace);
533
534MLIR_CAPI_EXPORTED MlirStringRef mlirUnrankedMemRefTypeGetName(void);
535
536/// Same as "mlirUnrankedMemRefTypeGet" but returns a nullptr wrapping
537/// MlirType on illegal arguments, emitting appropriate diagnostics.
538MLIR_CAPI_EXPORTED MlirType mlirUnrankedMemRefTypeGetChecked(
539 MlirLocation loc, MlirType elementType, MlirAttribute memorySpace);
540
541/// Returns the layout of the given MemRef type.
542MLIR_CAPI_EXPORTED MlirAttribute mlirMemRefTypeGetLayout(MlirType type);
543
544/// Returns the affine map of the given MemRef type.
545MLIR_CAPI_EXPORTED MlirAffineMap mlirMemRefTypeGetAffineMap(MlirType type);
546
547/// Returns the memory space of the given MemRef type.
548MLIR_CAPI_EXPORTED MlirAttribute mlirMemRefTypeGetMemorySpace(MlirType type);
549
550/// Returns the strides of the MemRef if the layout map is in strided form.
551/// Both strides and offset are out params. strides must point to pre-allocated
552/// memory of length equal to the rank of the memref.
553MLIR_CAPI_EXPORTED MlirLogicalResult mlirMemRefTypeGetStridesAndOffset(
554 MlirType type, int64_t *strides, int64_t *offset);
555
556/// Returns the memory spcae of the given Unranked MemRef type.
557MLIR_CAPI_EXPORTED MlirAttribute
558mlirUnrankedMemrefGetMemorySpace(MlirType type);
559
560//===----------------------------------------------------------------------===//
561// Tuple type.
562//===----------------------------------------------------------------------===//
563
564/// Returns the typeID of an Tuple type.
565MLIR_CAPI_EXPORTED MlirTypeID mlirTupleTypeGetTypeID(void);
566
567/// Checks whether the given type is a tuple type.
568MLIR_CAPI_EXPORTED bool mlirTypeIsATuple(MlirType type);
569
570/// Creates a tuple type that consists of the given list of elemental types. The
571/// type is owned by the context.
572MLIR_CAPI_EXPORTED MlirType mlirTupleTypeGet(MlirContext ctx,
573 intptr_t numElements,
574 MlirType const *elements);
575
576MLIR_CAPI_EXPORTED MlirStringRef mlirTupleTypeGetName(void);
577
578/// Returns the number of types contained in a tuple.
579MLIR_CAPI_EXPORTED intptr_t mlirTupleTypeGetNumTypes(MlirType type);
580
581/// Returns the pos-th type in the tuple type.
582MLIR_CAPI_EXPORTED MlirType mlirTupleTypeGetType(MlirType type, intptr_t pos);
583
584//===----------------------------------------------------------------------===//
585// Function type.
586//===----------------------------------------------------------------------===//
587
588/// Returns the typeID of an Function type.
589MLIR_CAPI_EXPORTED MlirTypeID mlirFunctionTypeGetTypeID(void);
590
591/// Checks whether the given type is a function type.
592MLIR_CAPI_EXPORTED bool mlirTypeIsAFunction(MlirType type);
593
594/// Creates a function type, mapping a list of input types to result types.
595MLIR_CAPI_EXPORTED MlirType mlirFunctionTypeGet(MlirContext ctx,
596 intptr_t numInputs,
597 MlirType const *inputs,
598 intptr_t numResults,
599 MlirType const *results);
600
601MLIR_CAPI_EXPORTED MlirStringRef mlirFunctionTypeGetName(void);
602
603/// Returns the number of input types.
604MLIR_CAPI_EXPORTED intptr_t mlirFunctionTypeGetNumInputs(MlirType type);
605
606/// Returns the number of result types.
607MLIR_CAPI_EXPORTED intptr_t mlirFunctionTypeGetNumResults(MlirType type);
608
609/// Returns the pos-th input type.
610MLIR_CAPI_EXPORTED MlirType mlirFunctionTypeGetInput(MlirType type,
611 intptr_t pos);
612
613/// Returns the pos-th result type.
614MLIR_CAPI_EXPORTED MlirType mlirFunctionTypeGetResult(MlirType type,
615 intptr_t pos);
616
617//===----------------------------------------------------------------------===//
618// Opaque type.
619//===----------------------------------------------------------------------===//
620
621/// Returns the typeID of an Opaque type.
622MLIR_CAPI_EXPORTED MlirTypeID mlirOpaqueTypeGetTypeID(void);
623
624/// Checks whether the given type is an opaque type.
625MLIR_CAPI_EXPORTED bool mlirTypeIsAOpaque(MlirType type);
626
627/// Creates an opaque type in the given context associated with the dialect
628/// identified by its namespace. The type contains opaque byte data of the
629/// specified length (data need not be null-terminated).
630MLIR_CAPI_EXPORTED MlirType mlirOpaqueTypeGet(MlirContext ctx,
631 MlirStringRef dialectNamespace,
632 MlirStringRef typeData);
633
634MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueTypeGetName(void);
635
636/// Returns the namespace of the dialect with which the given opaque type
637/// is associated. The namespace string is owned by the context.
638MLIR_CAPI_EXPORTED MlirStringRef
639mlirOpaqueTypeGetDialectNamespace(MlirType type);
640
641/// Returns the raw data as a string reference. The data remains live as long as
642/// the context in which the type lives.
643MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueTypeGetData(MlirType type);
644
645#ifdef __cplusplus
646}
647#endif
648
649#endif // MLIR_C_BUILTINTYPES_H
650