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

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

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