1//===-- mlir-c/BuiltinAttributes.h - C API for Builtin Attributes -*- 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// This header declares the C interface to MLIR Builtin attributes.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_C_BUILTINATTRIBUTES_H
15#define MLIR_C_BUILTINATTRIBUTES_H
16
17#include "mlir-c/AffineMap.h"
18#include "mlir-c/IR.h"
19#include "mlir-c/Support.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/// Returns an empty attribute.
26MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeGetNull(void);
27
28//===----------------------------------------------------------------------===//
29// Location attribute.
30//===----------------------------------------------------------------------===//
31
32MLIR_CAPI_EXPORTED bool mlirAttributeIsALocation(MlirAttribute attr);
33
34//===----------------------------------------------------------------------===//
35// Affine map attribute.
36//===----------------------------------------------------------------------===//
37
38/// Checks whether the given attribute is an affine map attribute.
39MLIR_CAPI_EXPORTED bool mlirAttributeIsAAffineMap(MlirAttribute attr);
40
41/// Creates an affine map attribute wrapping the given map. The attribute
42/// belongs to the same context as the affine map.
43MLIR_CAPI_EXPORTED MlirAttribute mlirAffineMapAttrGet(MlirAffineMap map);
44
45/// Returns the affine map wrapped in the given affine map attribute.
46MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapAttrGetValue(MlirAttribute attr);
47
48/// Returns the typeID of an AffineMap attribute.
49MLIR_CAPI_EXPORTED MlirTypeID mlirAffineMapAttrGetTypeID(void);
50
51//===----------------------------------------------------------------------===//
52// Array attribute.
53//===----------------------------------------------------------------------===//
54
55/// Checks whether the given attribute is an array attribute.
56MLIR_CAPI_EXPORTED bool mlirAttributeIsAArray(MlirAttribute attr);
57
58/// Creates an array element containing the given list of elements in the given
59/// context.
60MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGet(
61 MlirContext ctx, intptr_t numElements, MlirAttribute const *elements);
62
63/// Returns the number of elements stored in the given array attribute.
64MLIR_CAPI_EXPORTED intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr);
65
66/// Returns pos-th element stored in the given array attribute.
67MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGetElement(MlirAttribute attr,
68 intptr_t pos);
69
70/// Returns the typeID of an Array attribute.
71MLIR_CAPI_EXPORTED MlirTypeID mlirArrayAttrGetTypeID(void);
72
73//===----------------------------------------------------------------------===//
74// Dictionary attribute.
75//===----------------------------------------------------------------------===//
76
77/// Checks whether the given attribute is a dictionary attribute.
78MLIR_CAPI_EXPORTED bool mlirAttributeIsADictionary(MlirAttribute attr);
79
80/// Creates a dictionary attribute containing the given list of elements in the
81/// provided context.
82MLIR_CAPI_EXPORTED MlirAttribute mlirDictionaryAttrGet(
83 MlirContext ctx, intptr_t numElements, MlirNamedAttribute const *elements);
84
85/// Returns the number of attributes contained in a dictionary attribute.
86MLIR_CAPI_EXPORTED intptr_t
87mlirDictionaryAttrGetNumElements(MlirAttribute attr);
88
89/// Returns pos-th element of the given dictionary attribute.
90MLIR_CAPI_EXPORTED MlirNamedAttribute
91mlirDictionaryAttrGetElement(MlirAttribute attr, intptr_t pos);
92
93/// Returns the dictionary attribute element with the given name or NULL if the
94/// given name does not exist in the dictionary.
95MLIR_CAPI_EXPORTED MlirAttribute
96mlirDictionaryAttrGetElementByName(MlirAttribute attr, MlirStringRef name);
97
98/// Returns the typeID of a Dictionary attribute.
99MLIR_CAPI_EXPORTED MlirTypeID mlirDictionaryAttrGetTypeID(void);
100
101//===----------------------------------------------------------------------===//
102// Floating point attribute.
103//===----------------------------------------------------------------------===//
104
105// TODO: add support for APFloat and APInt to LLVM IR C API, then expose the
106// relevant functions here.
107
108/// Checks whether the given attribute is a floating point attribute.
109MLIR_CAPI_EXPORTED bool mlirAttributeIsAFloat(MlirAttribute attr);
110
111/// Creates a floating point attribute in the given context with the given
112/// double value and double-precision FP semantics.
113MLIR_CAPI_EXPORTED MlirAttribute mlirFloatAttrDoubleGet(MlirContext ctx,
114 MlirType type,
115 double value);
116
117/// Same as "mlirFloatAttrDoubleGet", but if the type is not valid for a
118/// construction of a FloatAttr, returns a null MlirAttribute.
119MLIR_CAPI_EXPORTED MlirAttribute mlirFloatAttrDoubleGetChecked(MlirLocation loc,
120 MlirType type,
121 double value);
122
123/// Returns the value stored in the given floating point attribute, interpreting
124/// the value as double.
125MLIR_CAPI_EXPORTED double mlirFloatAttrGetValueDouble(MlirAttribute attr);
126
127/// Returns the typeID of a Float attribute.
128MLIR_CAPI_EXPORTED MlirTypeID mlirFloatAttrGetTypeID(void);
129
130//===----------------------------------------------------------------------===//
131// Integer attribute.
132//===----------------------------------------------------------------------===//
133
134// TODO: add support for APFloat and APInt to LLVM IR C API, then expose the
135// relevant functions here.
136
137/// Checks whether the given attribute is an integer attribute.
138MLIR_CAPI_EXPORTED bool mlirAttributeIsAInteger(MlirAttribute attr);
139
140/// Creates an integer attribute of the given type with the given integer
141/// value.
142MLIR_CAPI_EXPORTED MlirAttribute mlirIntegerAttrGet(MlirType type,
143 int64_t value);
144
145/// Returns the value stored in the given integer attribute, assuming the value
146/// is of signless type and fits into a signed 64-bit integer.
147MLIR_CAPI_EXPORTED int64_t mlirIntegerAttrGetValueInt(MlirAttribute attr);
148
149/// Returns the value stored in the given integer attribute, assuming the value
150/// is of signed type and fits into a signed 64-bit integer.
151MLIR_CAPI_EXPORTED int64_t mlirIntegerAttrGetValueSInt(MlirAttribute attr);
152
153/// Returns the value stored in the given integer attribute, assuming the value
154/// is of unsigned type and fits into an unsigned 64-bit integer.
155MLIR_CAPI_EXPORTED uint64_t mlirIntegerAttrGetValueUInt(MlirAttribute attr);
156
157/// Returns the typeID of an Integer attribute.
158MLIR_CAPI_EXPORTED MlirTypeID mlirIntegerAttrGetTypeID(void);
159
160//===----------------------------------------------------------------------===//
161// Bool attribute.
162//===----------------------------------------------------------------------===//
163
164/// Checks whether the given attribute is a bool attribute.
165MLIR_CAPI_EXPORTED bool mlirAttributeIsABool(MlirAttribute attr);
166
167/// Creates a bool attribute in the given context with the given value.
168MLIR_CAPI_EXPORTED MlirAttribute mlirBoolAttrGet(MlirContext ctx, int value);
169
170/// Returns the value stored in the given bool attribute.
171MLIR_CAPI_EXPORTED bool mlirBoolAttrGetValue(MlirAttribute attr);
172
173//===----------------------------------------------------------------------===//
174// Integer set attribute.
175//===----------------------------------------------------------------------===//
176
177/// Checks whether the given attribute is an integer set attribute.
178MLIR_CAPI_EXPORTED bool mlirAttributeIsAIntegerSet(MlirAttribute attr);
179
180/// Returns the typeID of an IntegerSet attribute.
181MLIR_CAPI_EXPORTED MlirTypeID mlirIntegerSetAttrGetTypeID(void);
182
183//===----------------------------------------------------------------------===//
184// Opaque attribute.
185//===----------------------------------------------------------------------===//
186
187/// Checks whether the given attribute is an opaque attribute.
188MLIR_CAPI_EXPORTED bool mlirAttributeIsAOpaque(MlirAttribute attr);
189
190/// Creates an opaque attribute in the given context associated with the dialect
191/// identified by its namespace. The attribute contains opaque byte data of the
192/// specified length (data need not be null-terminated).
193MLIR_CAPI_EXPORTED MlirAttribute
194mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace,
195 intptr_t dataLength, const char *data, MlirType type);
196
197/// Returns the namespace of the dialect with which the given opaque attribute
198/// is associated. The namespace string is owned by the context.
199MLIR_CAPI_EXPORTED MlirStringRef
200mlirOpaqueAttrGetDialectNamespace(MlirAttribute attr);
201
202/// Returns the raw data as a string reference. The data remains live as long as
203/// the context in which the attribute lives.
204MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueAttrGetData(MlirAttribute attr);
205
206/// Returns the typeID of an Opaque attribute.
207MLIR_CAPI_EXPORTED MlirTypeID mlirOpaqueAttrGetTypeID(void);
208
209//===----------------------------------------------------------------------===//
210// String attribute.
211//===----------------------------------------------------------------------===//
212
213/// Checks whether the given attribute is a string attribute.
214MLIR_CAPI_EXPORTED bool mlirAttributeIsAString(MlirAttribute attr);
215
216/// Creates a string attribute in the given context containing the given string.
217
218MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrGet(MlirContext ctx,
219 MlirStringRef str);
220
221/// Creates a string attribute in the given context containing the given string.
222/// Additionally, the attribute has the given type.
223MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrTypedGet(MlirType type,
224 MlirStringRef str);
225
226/// Returns the attribute values as a string reference. The data remains live as
227/// long as the context in which the attribute lives.
228MLIR_CAPI_EXPORTED MlirStringRef mlirStringAttrGetValue(MlirAttribute attr);
229
230/// Returns the typeID of a String attribute.
231MLIR_CAPI_EXPORTED MlirTypeID mlirStringAttrGetTypeID(void);
232
233//===----------------------------------------------------------------------===//
234// SymbolRef attribute.
235//===----------------------------------------------------------------------===//
236
237/// Checks whether the given attribute is a symbol reference attribute.
238MLIR_CAPI_EXPORTED bool mlirAttributeIsASymbolRef(MlirAttribute attr);
239
240/// Creates a symbol reference attribute in the given context referencing a
241/// symbol identified by the given string inside a list of nested references.
242/// Each of the references in the list must not be nested.
243MLIR_CAPI_EXPORTED MlirAttribute
244mlirSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol,
245 intptr_t numReferences, MlirAttribute const *references);
246
247/// Returns the string reference to the root referenced symbol. The data remains
248/// live as long as the context in which the attribute lives.
249MLIR_CAPI_EXPORTED MlirStringRef
250mlirSymbolRefAttrGetRootReference(MlirAttribute attr);
251
252/// Returns the string reference to the leaf referenced symbol. The data remains
253/// live as long as the context in which the attribute lives.
254MLIR_CAPI_EXPORTED MlirStringRef
255mlirSymbolRefAttrGetLeafReference(MlirAttribute attr);
256
257/// Returns the number of references nested in the given symbol reference
258/// attribute.
259MLIR_CAPI_EXPORTED intptr_t
260mlirSymbolRefAttrGetNumNestedReferences(MlirAttribute attr);
261
262/// Returns pos-th reference nested in the given symbol reference attribute.
263MLIR_CAPI_EXPORTED MlirAttribute
264mlirSymbolRefAttrGetNestedReference(MlirAttribute attr, intptr_t pos);
265
266/// Returns the typeID of an SymbolRef attribute.
267MLIR_CAPI_EXPORTED MlirTypeID mlirSymbolRefAttrGetTypeID(void);
268
269//===----------------------------------------------------------------------===//
270// Flat SymbolRef attribute.
271//===----------------------------------------------------------------------===//
272
273/// Checks whether the given attribute is a flat symbol reference attribute.
274MLIR_CAPI_EXPORTED bool mlirAttributeIsAFlatSymbolRef(MlirAttribute attr);
275
276/// Creates a flat symbol reference attribute in the given context referencing a
277/// symbol identified by the given string.
278MLIR_CAPI_EXPORTED MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx,
279 MlirStringRef symbol);
280
281/// Returns the referenced symbol as a string reference. The data remains live
282/// as long as the context in which the attribute lives.
283MLIR_CAPI_EXPORTED MlirStringRef
284mlirFlatSymbolRefAttrGetValue(MlirAttribute attr);
285
286//===----------------------------------------------------------------------===//
287// Type attribute.
288//===----------------------------------------------------------------------===//
289
290/// Checks whether the given attribute is a type attribute.
291MLIR_CAPI_EXPORTED bool mlirAttributeIsAType(MlirAttribute attr);
292
293/// Creates a type attribute wrapping the given type in the same context as the
294/// type.
295MLIR_CAPI_EXPORTED MlirAttribute mlirTypeAttrGet(MlirType type);
296
297/// Returns the type stored in the given type attribute.
298MLIR_CAPI_EXPORTED MlirType mlirTypeAttrGetValue(MlirAttribute attr);
299
300/// Returns the typeID of a Type attribute.
301MLIR_CAPI_EXPORTED MlirTypeID mlirTypeAttrGetTypeID(void);
302
303//===----------------------------------------------------------------------===//
304// Unit attribute.
305//===----------------------------------------------------------------------===//
306
307/// Checks whether the given attribute is a unit attribute.
308MLIR_CAPI_EXPORTED bool mlirAttributeIsAUnit(MlirAttribute attr);
309
310/// Creates a unit attribute in the given context.
311MLIR_CAPI_EXPORTED MlirAttribute mlirUnitAttrGet(MlirContext ctx);
312
313/// Returns the typeID of a Unit attribute.
314MLIR_CAPI_EXPORTED MlirTypeID mlirUnitAttrGetTypeID(void);
315
316//===----------------------------------------------------------------------===//
317// Elements attributes.
318//===----------------------------------------------------------------------===//
319
320/// Checks whether the given attribute is an elements attribute.
321MLIR_CAPI_EXPORTED bool mlirAttributeIsAElements(MlirAttribute attr);
322
323/// Returns the element at the given rank-dimensional index.
324MLIR_CAPI_EXPORTED MlirAttribute mlirElementsAttrGetValue(MlirAttribute attr,
325 intptr_t rank,
326 uint64_t *idxs);
327
328/// Checks whether the given rank-dimensional index is valid in the given
329/// elements attribute.
330MLIR_CAPI_EXPORTED bool
331mlirElementsAttrIsValidIndex(MlirAttribute attr, intptr_t rank, uint64_t *idxs);
332
333/// Gets the total number of elements in the given elements attribute. In order
334/// to iterate over the attribute, obtain its type, which must be a statically
335/// shaped type and use its sizes to build a multi-dimensional index.
336MLIR_CAPI_EXPORTED int64_t mlirElementsAttrGetNumElements(MlirAttribute attr);
337
338//===----------------------------------------------------------------------===//
339// Dense array attribute.
340//===----------------------------------------------------------------------===//
341
342MLIR_CAPI_EXPORTED MlirTypeID mlirDenseArrayAttrGetTypeID(void);
343
344/// Checks whether the given attribute is a dense array attribute.
345MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseBoolArray(MlirAttribute attr);
346MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseI8Array(MlirAttribute attr);
347MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseI16Array(MlirAttribute attr);
348MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseI32Array(MlirAttribute attr);
349MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseI64Array(MlirAttribute attr);
350MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseF32Array(MlirAttribute attr);
351MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseF64Array(MlirAttribute attr);
352
353/// Create a dense array attribute with the given elements.
354MLIR_CAPI_EXPORTED MlirAttribute mlirDenseBoolArrayGet(MlirContext ctx,
355 intptr_t size,
356 int const *values);
357MLIR_CAPI_EXPORTED MlirAttribute mlirDenseI8ArrayGet(MlirContext ctx,
358 intptr_t size,
359 int8_t const *values);
360MLIR_CAPI_EXPORTED MlirAttribute mlirDenseI16ArrayGet(MlirContext ctx,
361 intptr_t size,
362 int16_t const *values);
363MLIR_CAPI_EXPORTED MlirAttribute mlirDenseI32ArrayGet(MlirContext ctx,
364 intptr_t size,
365 int32_t const *values);
366MLIR_CAPI_EXPORTED MlirAttribute mlirDenseI64ArrayGet(MlirContext ctx,
367 intptr_t size,
368 int64_t const *values);
369MLIR_CAPI_EXPORTED MlirAttribute mlirDenseF32ArrayGet(MlirContext ctx,
370 intptr_t size,
371 float const *values);
372MLIR_CAPI_EXPORTED MlirAttribute mlirDenseF64ArrayGet(MlirContext ctx,
373 intptr_t size,
374 double const *values);
375
376/// Get the size of a dense array.
377MLIR_CAPI_EXPORTED intptr_t mlirDenseArrayGetNumElements(MlirAttribute attr);
378
379/// Get an element of a dense array.
380MLIR_CAPI_EXPORTED bool mlirDenseBoolArrayGetElement(MlirAttribute attr,
381 intptr_t pos);
382MLIR_CAPI_EXPORTED int8_t mlirDenseI8ArrayGetElement(MlirAttribute attr,
383 intptr_t pos);
384MLIR_CAPI_EXPORTED int16_t mlirDenseI16ArrayGetElement(MlirAttribute attr,
385 intptr_t pos);
386MLIR_CAPI_EXPORTED int32_t mlirDenseI32ArrayGetElement(MlirAttribute attr,
387 intptr_t pos);
388MLIR_CAPI_EXPORTED int64_t mlirDenseI64ArrayGetElement(MlirAttribute attr,
389 intptr_t pos);
390MLIR_CAPI_EXPORTED float mlirDenseF32ArrayGetElement(MlirAttribute attr,
391 intptr_t pos);
392MLIR_CAPI_EXPORTED double mlirDenseF64ArrayGetElement(MlirAttribute attr,
393 intptr_t pos);
394
395//===----------------------------------------------------------------------===//
396// Dense elements attribute.
397//===----------------------------------------------------------------------===//
398
399// TODO: decide on the interface and add support for complex elements.
400// TODO: add support for APFloat and APInt to LLVM IR C API, then expose the
401// relevant functions here.
402
403/// Checks whether the given attribute is a dense elements attribute.
404MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseElements(MlirAttribute attr);
405MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseIntElements(MlirAttribute attr);
406MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseFPElements(MlirAttribute attr);
407
408/// Returns the typeID of an DenseIntOrFPElements attribute.
409MLIR_CAPI_EXPORTED MlirTypeID mlirDenseIntOrFPElementsAttrGetTypeID(void);
410
411/// Creates a dense elements attribute with the given Shaped type and elements
412/// in the same context as the type.
413MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrGet(
414 MlirType shapedType, intptr_t numElements, MlirAttribute const *elements);
415
416/// Creates a dense elements attribute with the given Shaped type and elements
417/// populated from a packed, row-major opaque buffer of contents.
418///
419/// The format of the raw buffer is a densely packed array of values that
420/// can be bitcast to the storage format of the element type specified.
421/// Types that are not byte aligned will be:
422/// - For bitwidth > 1: Rounded up to the next byte.
423/// - For bitwidth = 1: Packed into 8bit bytes with bits corresponding to
424/// the linear order of the shape type from MSB to LSB, padded to on the
425/// right.
426///
427/// A raw buffer of a single element (or for 1-bit, a byte of value 0 or 255)
428/// will be interpreted as a splat. User code should be prepared for additional,
429/// conformant patterns to be identified as splats in the future.
430MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrRawBufferGet(
431 MlirType shapedType, size_t rawBufferSize, const void *rawBuffer);
432
433/// Creates a dense elements attribute with the given Shaped type containing a
434/// single replicated element (splat).
435MLIR_CAPI_EXPORTED MlirAttribute
436mlirDenseElementsAttrSplatGet(MlirType shapedType, MlirAttribute element);
437MLIR_CAPI_EXPORTED MlirAttribute
438mlirDenseElementsAttrBoolSplatGet(MlirType shapedType, bool element);
439MLIR_CAPI_EXPORTED MlirAttribute
440mlirDenseElementsAttrUInt8SplatGet(MlirType shapedType, uint8_t element);
441MLIR_CAPI_EXPORTED MlirAttribute
442mlirDenseElementsAttrInt8SplatGet(MlirType shapedType, int8_t element);
443MLIR_CAPI_EXPORTED MlirAttribute
444mlirDenseElementsAttrUInt32SplatGet(MlirType shapedType, uint32_t element);
445MLIR_CAPI_EXPORTED MlirAttribute
446mlirDenseElementsAttrInt32SplatGet(MlirType shapedType, int32_t element);
447MLIR_CAPI_EXPORTED MlirAttribute
448mlirDenseElementsAttrUInt64SplatGet(MlirType shapedType, uint64_t element);
449MLIR_CAPI_EXPORTED MlirAttribute
450mlirDenseElementsAttrInt64SplatGet(MlirType shapedType, int64_t element);
451MLIR_CAPI_EXPORTED MlirAttribute
452mlirDenseElementsAttrFloatSplatGet(MlirType shapedType, float element);
453MLIR_CAPI_EXPORTED MlirAttribute
454mlirDenseElementsAttrDoubleSplatGet(MlirType shapedType, double element);
455
456/// Creates a dense elements attribute with the given shaped type from elements
457/// of a specific type. Expects the element type of the shaped type to match the
458/// data element type.
459MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrBoolGet(
460 MlirType shapedType, intptr_t numElements, const int *elements);
461MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt8Get(
462 MlirType shapedType, intptr_t numElements, const uint8_t *elements);
463MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt8Get(
464 MlirType shapedType, intptr_t numElements, const int8_t *elements);
465MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt16Get(
466 MlirType shapedType, intptr_t numElements, const uint16_t *elements);
467MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt16Get(
468 MlirType shapedType, intptr_t numElements, const int16_t *elements);
469MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt32Get(
470 MlirType shapedType, intptr_t numElements, const uint32_t *elements);
471MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt32Get(
472 MlirType shapedType, intptr_t numElements, const int32_t *elements);
473MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt64Get(
474 MlirType shapedType, intptr_t numElements, const uint64_t *elements);
475MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt64Get(
476 MlirType shapedType, intptr_t numElements, const int64_t *elements);
477MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrFloatGet(
478 MlirType shapedType, intptr_t numElements, const float *elements);
479MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrDoubleGet(
480 MlirType shapedType, intptr_t numElements, const double *elements);
481MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrBFloat16Get(
482 MlirType shapedType, intptr_t numElements, const uint16_t *elements);
483MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrFloat16Get(
484 MlirType shapedType, intptr_t numElements, const uint16_t *elements);
485
486/// Creates a dense elements attribute with the given shaped type from string
487/// elements.
488MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrStringGet(
489 MlirType shapedType, intptr_t numElements, MlirStringRef *strs);
490
491/// Creates a dense elements attribute that has the same data as the given dense
492/// elements attribute and a different shaped type. The new type must have the
493/// same total number of elements.
494MLIR_CAPI_EXPORTED MlirAttribute
495mlirDenseElementsAttrReshapeGet(MlirAttribute attr, MlirType shapedType);
496
497/// Checks whether the given dense elements attribute contains a single
498/// replicated value (splat).
499MLIR_CAPI_EXPORTED bool mlirDenseElementsAttrIsSplat(MlirAttribute attr);
500
501/// Returns the single replicated value (splat) of a specific type contained by
502/// the given dense elements attribute.
503MLIR_CAPI_EXPORTED MlirAttribute
504mlirDenseElementsAttrGetSplatValue(MlirAttribute attr);
505MLIR_CAPI_EXPORTED int
506mlirDenseElementsAttrGetBoolSplatValue(MlirAttribute attr);
507MLIR_CAPI_EXPORTED int8_t
508mlirDenseElementsAttrGetInt8SplatValue(MlirAttribute attr);
509MLIR_CAPI_EXPORTED uint8_t
510mlirDenseElementsAttrGetUInt8SplatValue(MlirAttribute attr);
511MLIR_CAPI_EXPORTED int32_t
512mlirDenseElementsAttrGetInt32SplatValue(MlirAttribute attr);
513MLIR_CAPI_EXPORTED uint32_t
514mlirDenseElementsAttrGetUInt32SplatValue(MlirAttribute attr);
515MLIR_CAPI_EXPORTED int64_t
516mlirDenseElementsAttrGetInt64SplatValue(MlirAttribute attr);
517MLIR_CAPI_EXPORTED uint64_t
518mlirDenseElementsAttrGetUInt64SplatValue(MlirAttribute attr);
519MLIR_CAPI_EXPORTED float
520mlirDenseElementsAttrGetFloatSplatValue(MlirAttribute attr);
521MLIR_CAPI_EXPORTED double
522mlirDenseElementsAttrGetDoubleSplatValue(MlirAttribute attr);
523MLIR_CAPI_EXPORTED MlirStringRef
524mlirDenseElementsAttrGetStringSplatValue(MlirAttribute attr);
525
526/// Returns the pos-th value (flat contiguous indexing) of a specific type
527/// contained by the given dense elements attribute.
528MLIR_CAPI_EXPORTED bool mlirDenseElementsAttrGetBoolValue(MlirAttribute attr,
529 intptr_t pos);
530MLIR_CAPI_EXPORTED int8_t mlirDenseElementsAttrGetInt8Value(MlirAttribute attr,
531 intptr_t pos);
532MLIR_CAPI_EXPORTED uint8_t
533mlirDenseElementsAttrGetUInt8Value(MlirAttribute attr, intptr_t pos);
534MLIR_CAPI_EXPORTED int16_t
535mlirDenseElementsAttrGetInt16Value(MlirAttribute attr, intptr_t pos);
536MLIR_CAPI_EXPORTED uint16_t
537mlirDenseElementsAttrGetUInt16Value(MlirAttribute attr, intptr_t pos);
538MLIR_CAPI_EXPORTED int32_t
539mlirDenseElementsAttrGetInt32Value(MlirAttribute attr, intptr_t pos);
540MLIR_CAPI_EXPORTED uint32_t
541mlirDenseElementsAttrGetUInt32Value(MlirAttribute attr, intptr_t pos);
542MLIR_CAPI_EXPORTED int64_t
543mlirDenseElementsAttrGetInt64Value(MlirAttribute attr, intptr_t pos);
544MLIR_CAPI_EXPORTED uint64_t
545mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos);
546MLIR_CAPI_EXPORTED float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr,
547 intptr_t pos);
548MLIR_CAPI_EXPORTED double
549mlirDenseElementsAttrGetDoubleValue(MlirAttribute attr, intptr_t pos);
550MLIR_CAPI_EXPORTED MlirStringRef
551mlirDenseElementsAttrGetStringValue(MlirAttribute attr, intptr_t pos);
552
553/// Returns the raw data of the given dense elements attribute.
554MLIR_CAPI_EXPORTED const void *
555mlirDenseElementsAttrGetRawData(MlirAttribute attr);
556
557//===----------------------------------------------------------------------===//
558// Resource blob attributes.
559//===----------------------------------------------------------------------===//
560
561MLIR_CAPI_EXPORTED bool
562mlirAttributeIsADenseResourceElements(MlirAttribute attr);
563
564/// Unlike the typed accessors below, constructs the attribute with a raw
565/// data buffer and no type/alignment checking. Use a more strongly typed
566/// accessor if possible. If dataIsMutable is false, then an immutable
567/// AsmResourceBlob will be created and that passed data contents will be
568/// treated as const.
569/// If the deleter is non NULL, then it will be called when the data buffer
570/// can no longer be accessed (passing userData to it).
571MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseResourceElementsAttrGet(
572 MlirType shapedType, MlirStringRef name, void *data, size_t dataLength,
573 size_t dataAlignment, bool dataIsMutable,
574 void (*deleter)(void *userData, const void *data, size_t size,
575 size_t align),
576 void *userData);
577
578MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseBoolResourceElementsAttrGet(
579 MlirType shapedType, MlirStringRef name, intptr_t numElements,
580 const int *elements);
581MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseUInt8ResourceElementsAttrGet(
582 MlirType shapedType, MlirStringRef name, intptr_t numElements,
583 const uint8_t *elements);
584MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseInt8ResourceElementsAttrGet(
585 MlirType shapedType, MlirStringRef name, intptr_t numElements,
586 const int8_t *elements);
587MLIR_CAPI_EXPORTED MlirAttribute
588mlirUnmanagedDenseUInt16ResourceElementsAttrGet(MlirType shapedType,
589 MlirStringRef name,
590 intptr_t numElements,
591 const uint16_t *elements);
592MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseInt16ResourceElementsAttrGet(
593 MlirType shapedType, MlirStringRef name, intptr_t numElements,
594 const int16_t *elements);
595MLIR_CAPI_EXPORTED MlirAttribute
596mlirUnmanagedDenseUInt32ResourceElementsAttrGet(MlirType shapedType,
597 MlirStringRef name,
598 intptr_t numElements,
599 const uint32_t *elements);
600MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseInt32ResourceElementsAttrGet(
601 MlirType shapedType, MlirStringRef name, intptr_t numElements,
602 const int32_t *elements);
603MLIR_CAPI_EXPORTED MlirAttribute
604mlirUnmanagedDenseUInt64ResourceElementsAttrGet(MlirType shapedType,
605 MlirStringRef name,
606 intptr_t numElements,
607 const uint64_t *elements);
608MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseInt64ResourceElementsAttrGet(
609 MlirType shapedType, MlirStringRef name, intptr_t numElements,
610 const int64_t *elements);
611MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseFloatResourceElementsAttrGet(
612 MlirType shapedType, MlirStringRef name, intptr_t numElements,
613 const float *elements);
614MLIR_CAPI_EXPORTED MlirAttribute
615mlirUnmanagedDenseDoubleResourceElementsAttrGet(MlirType shapedType,
616 MlirStringRef name,
617 intptr_t numElements,
618 const double *elements);
619
620/// Returns the pos-th value (flat contiguous indexing) of a specific type
621/// contained by the given dense resource elements attribute.
622MLIR_CAPI_EXPORTED bool
623mlirDenseBoolResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
624MLIR_CAPI_EXPORTED int8_t
625mlirDenseInt8ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
626MLIR_CAPI_EXPORTED uint8_t
627mlirDenseUInt8ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
628MLIR_CAPI_EXPORTED int16_t
629mlirDenseInt16ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
630MLIR_CAPI_EXPORTED uint16_t
631mlirDenseUInt16ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
632MLIR_CAPI_EXPORTED int32_t
633mlirDenseInt32ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
634MLIR_CAPI_EXPORTED uint32_t
635mlirDenseUInt32ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
636MLIR_CAPI_EXPORTED int64_t
637mlirDenseInt64ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
638MLIR_CAPI_EXPORTED uint64_t
639mlirDenseUInt64ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
640MLIR_CAPI_EXPORTED float
641mlirDenseFloatResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
642MLIR_CAPI_EXPORTED double
643mlirDenseDoubleResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
644
645//===----------------------------------------------------------------------===//
646// Sparse elements attribute.
647//===----------------------------------------------------------------------===//
648
649/// Checks whether the given attribute is a sparse elements attribute.
650MLIR_CAPI_EXPORTED bool mlirAttributeIsASparseElements(MlirAttribute attr);
651
652/// Creates a sparse elements attribute of the given shape from a list of
653/// indices and a list of associated values. Both lists are expected to be dense
654/// elements attributes with the same number of elements. The list of indices is
655/// expected to contain 64-bit integers. The attribute is created in the same
656/// context as the type.
657MLIR_CAPI_EXPORTED MlirAttribute mlirSparseElementsAttribute(
658 MlirType shapedType, MlirAttribute denseIndices, MlirAttribute denseValues);
659
660/// Returns the dense elements attribute containing 64-bit integer indices of
661/// non-null elements in the given sparse elements attribute.
662MLIR_CAPI_EXPORTED MlirAttribute
663mlirSparseElementsAttrGetIndices(MlirAttribute attr);
664
665/// Returns the dense elements attribute containing the non-null elements in the
666/// given sparse elements attribute.
667MLIR_CAPI_EXPORTED MlirAttribute
668mlirSparseElementsAttrGetValues(MlirAttribute attr);
669
670/// Returns the typeID of a SparseElements attribute.
671MLIR_CAPI_EXPORTED MlirTypeID mlirSparseElementsAttrGetTypeID(void);
672
673//===----------------------------------------------------------------------===//
674// Strided layout attribute.
675//===----------------------------------------------------------------------===//
676
677// Checks wheather the given attribute is a strided layout attribute.
678MLIR_CAPI_EXPORTED bool mlirAttributeIsAStridedLayout(MlirAttribute attr);
679
680// Creates a strided layout attribute from given strides and offset.
681MLIR_CAPI_EXPORTED MlirAttribute
682mlirStridedLayoutAttrGet(MlirContext ctx, int64_t offset, intptr_t numStrides,
683 const int64_t *strides);
684
685// Returns the offset in the given strided layout layout attribute.
686MLIR_CAPI_EXPORTED int64_t mlirStridedLayoutAttrGetOffset(MlirAttribute attr);
687
688// Returns the number of strides in the given strided layout attribute.
689MLIR_CAPI_EXPORTED intptr_t
690mlirStridedLayoutAttrGetNumStrides(MlirAttribute attr);
691
692// Returns the pos-th stride stored in the given strided layout attribute.
693MLIR_CAPI_EXPORTED int64_t mlirStridedLayoutAttrGetStride(MlirAttribute attr,
694 intptr_t pos);
695
696/// Returns the typeID of a StridedLayout attribute.
697MLIR_CAPI_EXPORTED MlirTypeID mlirStridedLayoutAttrGetTypeID(void);
698
699#ifdef __cplusplus
700}
701#endif
702
703#endif // MLIR_C_BUILTINATTRIBUTES_H
704

source code of mlir/include/mlir-c/BuiltinAttributes.h