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