[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / mlir / include / mlir-c / BuiltinAttributes.h
blob7c8c84e55b962fcc3f56b6b4349563985d73a870
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.
12 //===----------------------------------------------------------------------===//
14 #ifndef MLIR_C_BUILTINATTRIBUTES_H
15 #define MLIR_C_BUILTINATTRIBUTES_H
17 #include "mlir-c/AffineMap.h"
18 #include "mlir-c/IR.h"
19 #include "mlir-c/IntegerSet.h"
20 #include "mlir-c/Support.h"
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
26 /// Returns an empty attribute.
27 MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeGetNull(void);
29 //===----------------------------------------------------------------------===//
30 // Location attribute.
31 //===----------------------------------------------------------------------===//
33 MLIR_CAPI_EXPORTED bool mlirAttributeIsALocation(MlirAttribute attr);
35 //===----------------------------------------------------------------------===//
36 // Affine map attribute.
37 //===----------------------------------------------------------------------===//
39 /// Checks whether the given attribute is an affine map attribute.
40 MLIR_CAPI_EXPORTED bool mlirAttributeIsAAffineMap(MlirAttribute attr);
42 /// Creates an affine map attribute wrapping the given map. The attribute
43 /// belongs to the same context as the affine map.
44 MLIR_CAPI_EXPORTED MlirAttribute mlirAffineMapAttrGet(MlirAffineMap map);
46 /// Returns the affine map wrapped in the given affine map attribute.
47 MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapAttrGetValue(MlirAttribute attr);
49 /// Returns the typeID of an AffineMap attribute.
50 MLIR_CAPI_EXPORTED MlirTypeID mlirAffineMapAttrGetTypeID(void);
52 //===----------------------------------------------------------------------===//
53 // Array attribute.
54 //===----------------------------------------------------------------------===//
56 /// Checks whether the given attribute is an array attribute.
57 MLIR_CAPI_EXPORTED bool mlirAttributeIsAArray(MlirAttribute attr);
59 /// Creates an array element containing the given list of elements in the given
60 /// context.
61 MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGet(
62 MlirContext ctx, intptr_t numElements, MlirAttribute const *elements);
64 /// Returns the number of elements stored in the given array attribute.
65 MLIR_CAPI_EXPORTED intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr);
67 /// Returns pos-th element stored in the given array attribute.
68 MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGetElement(MlirAttribute attr,
69 intptr_t pos);
71 /// Returns the typeID of an Array attribute.
72 MLIR_CAPI_EXPORTED MlirTypeID mlirArrayAttrGetTypeID(void);
74 //===----------------------------------------------------------------------===//
75 // Dictionary attribute.
76 //===----------------------------------------------------------------------===//
78 /// Checks whether the given attribute is a dictionary attribute.
79 MLIR_CAPI_EXPORTED bool mlirAttributeIsADictionary(MlirAttribute attr);
81 /// Creates a dictionary attribute containing the given list of elements in the
82 /// provided context.
83 MLIR_CAPI_EXPORTED MlirAttribute mlirDictionaryAttrGet(
84 MlirContext ctx, intptr_t numElements, MlirNamedAttribute const *elements);
86 /// Returns the number of attributes contained in a dictionary attribute.
87 MLIR_CAPI_EXPORTED intptr_t
88 mlirDictionaryAttrGetNumElements(MlirAttribute attr);
90 /// Returns pos-th element of the given dictionary attribute.
91 MLIR_CAPI_EXPORTED MlirNamedAttribute
92 mlirDictionaryAttrGetElement(MlirAttribute attr, intptr_t pos);
94 /// Returns the dictionary attribute element with the given name or NULL if the
95 /// given name does not exist in the dictionary.
96 MLIR_CAPI_EXPORTED MlirAttribute
97 mlirDictionaryAttrGetElementByName(MlirAttribute attr, MlirStringRef name);
99 /// Returns the typeID of a Dictionary attribute.
100 MLIR_CAPI_EXPORTED MlirTypeID mlirDictionaryAttrGetTypeID(void);
102 //===----------------------------------------------------------------------===//
103 // Floating point attribute.
104 //===----------------------------------------------------------------------===//
106 // TODO: add support for APFloat and APInt to LLVM IR C API, then expose the
107 // relevant functions here.
109 /// Checks whether the given attribute is a floating point attribute.
110 MLIR_CAPI_EXPORTED bool mlirAttributeIsAFloat(MlirAttribute attr);
112 /// Creates a floating point attribute in the given context with the given
113 /// double value and double-precision FP semantics.
114 MLIR_CAPI_EXPORTED MlirAttribute mlirFloatAttrDoubleGet(MlirContext ctx,
115 MlirType type,
116 double value);
118 /// Same as "mlirFloatAttrDoubleGet", but if the type is not valid for a
119 /// construction of a FloatAttr, returns a null MlirAttribute.
120 MLIR_CAPI_EXPORTED MlirAttribute mlirFloatAttrDoubleGetChecked(MlirLocation loc,
121 MlirType type,
122 double value);
124 /// Returns the value stored in the given floating point attribute, interpreting
125 /// the value as double.
126 MLIR_CAPI_EXPORTED double mlirFloatAttrGetValueDouble(MlirAttribute attr);
128 /// Returns the typeID of a Float attribute.
129 MLIR_CAPI_EXPORTED MlirTypeID mlirFloatAttrGetTypeID(void);
131 //===----------------------------------------------------------------------===//
132 // Integer attribute.
133 //===----------------------------------------------------------------------===//
135 // TODO: add support for APFloat and APInt to LLVM IR C API, then expose the
136 // relevant functions here.
138 /// Checks whether the given attribute is an integer attribute.
139 MLIR_CAPI_EXPORTED bool mlirAttributeIsAInteger(MlirAttribute attr);
141 /// Creates an integer attribute of the given type with the given integer
142 /// value.
143 MLIR_CAPI_EXPORTED MlirAttribute mlirIntegerAttrGet(MlirType type,
144 int64_t value);
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.
148 MLIR_CAPI_EXPORTED int64_t mlirIntegerAttrGetValueInt(MlirAttribute attr);
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.
152 MLIR_CAPI_EXPORTED int64_t mlirIntegerAttrGetValueSInt(MlirAttribute attr);
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.
156 MLIR_CAPI_EXPORTED uint64_t mlirIntegerAttrGetValueUInt(MlirAttribute attr);
158 /// Returns the typeID of an Integer attribute.
159 MLIR_CAPI_EXPORTED MlirTypeID mlirIntegerAttrGetTypeID(void);
161 //===----------------------------------------------------------------------===//
162 // Bool attribute.
163 //===----------------------------------------------------------------------===//
165 /// Checks whether the given attribute is a bool attribute.
166 MLIR_CAPI_EXPORTED bool mlirAttributeIsABool(MlirAttribute attr);
168 /// Creates a bool attribute in the given context with the given value.
169 MLIR_CAPI_EXPORTED MlirAttribute mlirBoolAttrGet(MlirContext ctx, int value);
171 /// Returns the value stored in the given bool attribute.
172 MLIR_CAPI_EXPORTED bool mlirBoolAttrGetValue(MlirAttribute attr);
174 //===----------------------------------------------------------------------===//
175 // Integer set attribute.
176 //===----------------------------------------------------------------------===//
178 /// Checks whether the given attribute is an integer set attribute.
179 MLIR_CAPI_EXPORTED bool mlirAttributeIsAIntegerSet(MlirAttribute attr);
181 /// Creates an integer set attribute wrapping the given set. The attribute
182 /// belongs to the same context as the integer set.
183 MLIR_CAPI_EXPORTED MlirAttribute mlirIntegerSetAttrGet(MlirIntegerSet set);
185 /// Returns the integer set wrapped in the given integer set attribute.
186 MLIR_CAPI_EXPORTED MlirIntegerSet
187 mlirIntegerSetAttrGetValue(MlirAttribute attr);
189 /// Returns the typeID of an IntegerSet attribute.
190 MLIR_CAPI_EXPORTED MlirTypeID mlirIntegerSetAttrGetTypeID(void);
192 //===----------------------------------------------------------------------===//
193 // Opaque attribute.
194 //===----------------------------------------------------------------------===//
196 /// Checks whether the given attribute is an opaque attribute.
197 MLIR_CAPI_EXPORTED bool mlirAttributeIsAOpaque(MlirAttribute attr);
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).
202 MLIR_CAPI_EXPORTED MlirAttribute
203 mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace,
204 intptr_t dataLength, const char *data, MlirType type);
206 /// Returns the namespace of the dialect with which the given opaque attribute
207 /// is associated. The namespace string is owned by the context.
208 MLIR_CAPI_EXPORTED MlirStringRef
209 mlirOpaqueAttrGetDialectNamespace(MlirAttribute attr);
211 /// Returns the raw data as a string reference. The data remains live as long as
212 /// the context in which the attribute lives.
213 MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueAttrGetData(MlirAttribute attr);
215 /// Returns the typeID of an Opaque attribute.
216 MLIR_CAPI_EXPORTED MlirTypeID mlirOpaqueAttrGetTypeID(void);
218 //===----------------------------------------------------------------------===//
219 // String attribute.
220 //===----------------------------------------------------------------------===//
222 /// Checks whether the given attribute is a string attribute.
223 MLIR_CAPI_EXPORTED bool mlirAttributeIsAString(MlirAttribute attr);
225 /// Creates a string attribute in the given context containing the given string.
227 MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrGet(MlirContext ctx,
228 MlirStringRef str);
230 /// Creates a string attribute in the given context containing the given string.
231 /// Additionally, the attribute has the given type.
232 MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrTypedGet(MlirType type,
233 MlirStringRef str);
235 /// Returns the attribute values as a string reference. The data remains live as
236 /// long as the context in which the attribute lives.
237 MLIR_CAPI_EXPORTED MlirStringRef mlirStringAttrGetValue(MlirAttribute attr);
239 /// Returns the typeID of a String attribute.
240 MLIR_CAPI_EXPORTED MlirTypeID mlirStringAttrGetTypeID(void);
242 //===----------------------------------------------------------------------===//
243 // SymbolRef attribute.
244 //===----------------------------------------------------------------------===//
246 /// Checks whether the given attribute is a symbol reference attribute.
247 MLIR_CAPI_EXPORTED bool mlirAttributeIsASymbolRef(MlirAttribute attr);
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.
252 MLIR_CAPI_EXPORTED MlirAttribute
253 mlirSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol,
254 intptr_t numReferences, MlirAttribute const *references);
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.
258 MLIR_CAPI_EXPORTED MlirStringRef
259 mlirSymbolRefAttrGetRootReference(MlirAttribute attr);
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.
263 MLIR_CAPI_EXPORTED MlirStringRef
264 mlirSymbolRefAttrGetLeafReference(MlirAttribute attr);
266 /// Returns the number of references nested in the given symbol reference
267 /// attribute.
268 MLIR_CAPI_EXPORTED intptr_t
269 mlirSymbolRefAttrGetNumNestedReferences(MlirAttribute attr);
271 /// Returns pos-th reference nested in the given symbol reference attribute.
272 MLIR_CAPI_EXPORTED MlirAttribute
273 mlirSymbolRefAttrGetNestedReference(MlirAttribute attr, intptr_t pos);
275 /// Returns the typeID of an SymbolRef attribute.
276 MLIR_CAPI_EXPORTED MlirTypeID mlirSymbolRefAttrGetTypeID(void);
278 /// Creates a DisctinctAttr with the referenced attribute.
279 MLIR_CAPI_EXPORTED MlirAttribute
280 mlirDisctinctAttrCreate(MlirAttribute referencedAttr);
282 //===----------------------------------------------------------------------===//
283 // Flat SymbolRef attribute.
284 //===----------------------------------------------------------------------===//
286 /// Checks whether the given attribute is a flat symbol reference attribute.
287 MLIR_CAPI_EXPORTED bool mlirAttributeIsAFlatSymbolRef(MlirAttribute attr);
289 /// Creates a flat symbol reference attribute in the given context referencing a
290 /// symbol identified by the given string.
291 MLIR_CAPI_EXPORTED MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx,
292 MlirStringRef symbol);
294 /// Returns the referenced symbol as a string reference. The data remains live
295 /// as long as the context in which the attribute lives.
296 MLIR_CAPI_EXPORTED MlirStringRef
297 mlirFlatSymbolRefAttrGetValue(MlirAttribute attr);
299 //===----------------------------------------------------------------------===//
300 // Type attribute.
301 //===----------------------------------------------------------------------===//
303 /// Checks whether the given attribute is a type attribute.
304 MLIR_CAPI_EXPORTED bool mlirAttributeIsAType(MlirAttribute attr);
306 /// Creates a type attribute wrapping the given type in the same context as the
307 /// type.
308 MLIR_CAPI_EXPORTED MlirAttribute mlirTypeAttrGet(MlirType type);
310 /// Returns the type stored in the given type attribute.
311 MLIR_CAPI_EXPORTED MlirType mlirTypeAttrGetValue(MlirAttribute attr);
313 /// Returns the typeID of a Type attribute.
314 MLIR_CAPI_EXPORTED MlirTypeID mlirTypeAttrGetTypeID(void);
316 //===----------------------------------------------------------------------===//
317 // Unit attribute.
318 //===----------------------------------------------------------------------===//
320 /// Checks whether the given attribute is a unit attribute.
321 MLIR_CAPI_EXPORTED bool mlirAttributeIsAUnit(MlirAttribute attr);
323 /// Creates a unit attribute in the given context.
324 MLIR_CAPI_EXPORTED MlirAttribute mlirUnitAttrGet(MlirContext ctx);
326 /// Returns the typeID of a Unit attribute.
327 MLIR_CAPI_EXPORTED MlirTypeID mlirUnitAttrGetTypeID(void);
329 //===----------------------------------------------------------------------===//
330 // Elements attributes.
331 //===----------------------------------------------------------------------===//
333 /// Checks whether the given attribute is an elements attribute.
334 MLIR_CAPI_EXPORTED bool mlirAttributeIsAElements(MlirAttribute attr);
336 /// Returns the element at the given rank-dimensional index.
337 MLIR_CAPI_EXPORTED MlirAttribute mlirElementsAttrGetValue(MlirAttribute attr,
338 intptr_t rank,
339 uint64_t *idxs);
341 /// Checks whether the given rank-dimensional index is valid in the given
342 /// elements attribute.
343 MLIR_CAPI_EXPORTED bool
344 mlirElementsAttrIsValidIndex(MlirAttribute attr, intptr_t rank, uint64_t *idxs);
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.
349 MLIR_CAPI_EXPORTED int64_t mlirElementsAttrGetNumElements(MlirAttribute attr);
351 //===----------------------------------------------------------------------===//
352 // Dense array attribute.
353 //===----------------------------------------------------------------------===//
355 MLIR_CAPI_EXPORTED MlirTypeID mlirDenseArrayAttrGetTypeID(void);
357 /// Checks whether the given attribute is a dense array attribute.
358 MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseBoolArray(MlirAttribute attr);
359 MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseI8Array(MlirAttribute attr);
360 MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseI16Array(MlirAttribute attr);
361 MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseI32Array(MlirAttribute attr);
362 MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseI64Array(MlirAttribute attr);
363 MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseF32Array(MlirAttribute attr);
364 MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseF64Array(MlirAttribute attr);
366 /// Create a dense array attribute with the given elements.
367 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseBoolArrayGet(MlirContext ctx,
368 intptr_t size,
369 int const *values);
370 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseI8ArrayGet(MlirContext ctx,
371 intptr_t size,
372 int8_t const *values);
373 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseI16ArrayGet(MlirContext ctx,
374 intptr_t size,
375 int16_t const *values);
376 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseI32ArrayGet(MlirContext ctx,
377 intptr_t size,
378 int32_t const *values);
379 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseI64ArrayGet(MlirContext ctx,
380 intptr_t size,
381 int64_t const *values);
382 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseF32ArrayGet(MlirContext ctx,
383 intptr_t size,
384 float const *values);
385 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseF64ArrayGet(MlirContext ctx,
386 intptr_t size,
387 double const *values);
389 /// Get the size of a dense array.
390 MLIR_CAPI_EXPORTED intptr_t mlirDenseArrayGetNumElements(MlirAttribute attr);
392 /// Get an element of a dense array.
393 MLIR_CAPI_EXPORTED bool mlirDenseBoolArrayGetElement(MlirAttribute attr,
394 intptr_t pos);
395 MLIR_CAPI_EXPORTED int8_t mlirDenseI8ArrayGetElement(MlirAttribute attr,
396 intptr_t pos);
397 MLIR_CAPI_EXPORTED int16_t mlirDenseI16ArrayGetElement(MlirAttribute attr,
398 intptr_t pos);
399 MLIR_CAPI_EXPORTED int32_t mlirDenseI32ArrayGetElement(MlirAttribute attr,
400 intptr_t pos);
401 MLIR_CAPI_EXPORTED int64_t mlirDenseI64ArrayGetElement(MlirAttribute attr,
402 intptr_t pos);
403 MLIR_CAPI_EXPORTED float mlirDenseF32ArrayGetElement(MlirAttribute attr,
404 intptr_t pos);
405 MLIR_CAPI_EXPORTED double mlirDenseF64ArrayGetElement(MlirAttribute attr,
406 intptr_t pos);
408 //===----------------------------------------------------------------------===//
409 // Dense elements attribute.
410 //===----------------------------------------------------------------------===//
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.
416 /// Checks whether the given attribute is a dense elements attribute.
417 MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseElements(MlirAttribute attr);
418 MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseIntElements(MlirAttribute attr);
419 MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseFPElements(MlirAttribute attr);
421 /// Returns the typeID of an DenseIntOrFPElements attribute.
422 MLIR_CAPI_EXPORTED MlirTypeID mlirDenseIntOrFPElementsAttrGetTypeID(void);
424 /// Creates a dense elements attribute with the given Shaped type and elements
425 /// in the same context as the type.
426 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrGet(
427 MlirType shapedType, intptr_t numElements, MlirAttribute const *elements);
429 /// Creates a dense elements attribute with the given Shaped type and elements
430 /// populated from a packed, row-major opaque buffer of contents.
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.
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.
443 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrRawBufferGet(
444 MlirType shapedType, size_t rawBufferSize, const void *rawBuffer);
446 /// Creates a dense elements attribute with the given Shaped type containing a
447 /// single replicated element (splat).
448 MLIR_CAPI_EXPORTED MlirAttribute
449 mlirDenseElementsAttrSplatGet(MlirType shapedType, MlirAttribute element);
450 MLIR_CAPI_EXPORTED MlirAttribute
451 mlirDenseElementsAttrBoolSplatGet(MlirType shapedType, bool element);
452 MLIR_CAPI_EXPORTED MlirAttribute
453 mlirDenseElementsAttrUInt8SplatGet(MlirType shapedType, uint8_t element);
454 MLIR_CAPI_EXPORTED MlirAttribute
455 mlirDenseElementsAttrInt8SplatGet(MlirType shapedType, int8_t element);
456 MLIR_CAPI_EXPORTED MlirAttribute
457 mlirDenseElementsAttrUInt32SplatGet(MlirType shapedType, uint32_t element);
458 MLIR_CAPI_EXPORTED MlirAttribute
459 mlirDenseElementsAttrInt32SplatGet(MlirType shapedType, int32_t element);
460 MLIR_CAPI_EXPORTED MlirAttribute
461 mlirDenseElementsAttrUInt64SplatGet(MlirType shapedType, uint64_t element);
462 MLIR_CAPI_EXPORTED MlirAttribute
463 mlirDenseElementsAttrInt64SplatGet(MlirType shapedType, int64_t element);
464 MLIR_CAPI_EXPORTED MlirAttribute
465 mlirDenseElementsAttrFloatSplatGet(MlirType shapedType, float element);
466 MLIR_CAPI_EXPORTED MlirAttribute
467 mlirDenseElementsAttrDoubleSplatGet(MlirType shapedType, double element);
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.
472 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrBoolGet(
473 MlirType shapedType, intptr_t numElements, const int *elements);
474 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt8Get(
475 MlirType shapedType, intptr_t numElements, const uint8_t *elements);
476 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt8Get(
477 MlirType shapedType, intptr_t numElements, const int8_t *elements);
478 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt16Get(
479 MlirType shapedType, intptr_t numElements, const uint16_t *elements);
480 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt16Get(
481 MlirType shapedType, intptr_t numElements, const int16_t *elements);
482 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt32Get(
483 MlirType shapedType, intptr_t numElements, const uint32_t *elements);
484 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt32Get(
485 MlirType shapedType, intptr_t numElements, const int32_t *elements);
486 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt64Get(
487 MlirType shapedType, intptr_t numElements, const uint64_t *elements);
488 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt64Get(
489 MlirType shapedType, intptr_t numElements, const int64_t *elements);
490 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrFloatGet(
491 MlirType shapedType, intptr_t numElements, const float *elements);
492 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrDoubleGet(
493 MlirType shapedType, intptr_t numElements, const double *elements);
494 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrBFloat16Get(
495 MlirType shapedType, intptr_t numElements, const uint16_t *elements);
496 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrFloat16Get(
497 MlirType shapedType, intptr_t numElements, const uint16_t *elements);
499 /// Creates a dense elements attribute with the given shaped type from string
500 /// elements.
501 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrStringGet(
502 MlirType shapedType, intptr_t numElements, MlirStringRef *strs);
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.
507 MLIR_CAPI_EXPORTED MlirAttribute
508 mlirDenseElementsAttrReshapeGet(MlirAttribute attr, MlirType shapedType);
510 /// Checks whether the given dense elements attribute contains a single
511 /// replicated value (splat).
512 MLIR_CAPI_EXPORTED bool mlirDenseElementsAttrIsSplat(MlirAttribute attr);
514 /// Returns the single replicated value (splat) of a specific type contained by
515 /// the given dense elements attribute.
516 MLIR_CAPI_EXPORTED MlirAttribute
517 mlirDenseElementsAttrGetSplatValue(MlirAttribute attr);
518 MLIR_CAPI_EXPORTED int
519 mlirDenseElementsAttrGetBoolSplatValue(MlirAttribute attr);
520 MLIR_CAPI_EXPORTED int8_t
521 mlirDenseElementsAttrGetInt8SplatValue(MlirAttribute attr);
522 MLIR_CAPI_EXPORTED uint8_t
523 mlirDenseElementsAttrGetUInt8SplatValue(MlirAttribute attr);
524 MLIR_CAPI_EXPORTED int32_t
525 mlirDenseElementsAttrGetInt32SplatValue(MlirAttribute attr);
526 MLIR_CAPI_EXPORTED uint32_t
527 mlirDenseElementsAttrGetUInt32SplatValue(MlirAttribute attr);
528 MLIR_CAPI_EXPORTED int64_t
529 mlirDenseElementsAttrGetInt64SplatValue(MlirAttribute attr);
530 MLIR_CAPI_EXPORTED uint64_t
531 mlirDenseElementsAttrGetUInt64SplatValue(MlirAttribute attr);
532 MLIR_CAPI_EXPORTED float
533 mlirDenseElementsAttrGetFloatSplatValue(MlirAttribute attr);
534 MLIR_CAPI_EXPORTED double
535 mlirDenseElementsAttrGetDoubleSplatValue(MlirAttribute attr);
536 MLIR_CAPI_EXPORTED MlirStringRef
537 mlirDenseElementsAttrGetStringSplatValue(MlirAttribute attr);
539 /// Returns the pos-th value (flat contiguous indexing) of a specific type
540 /// contained by the given dense elements attribute.
541 MLIR_CAPI_EXPORTED bool mlirDenseElementsAttrGetBoolValue(MlirAttribute attr,
542 intptr_t pos);
543 MLIR_CAPI_EXPORTED int8_t mlirDenseElementsAttrGetInt8Value(MlirAttribute attr,
544 intptr_t pos);
545 MLIR_CAPI_EXPORTED uint8_t
546 mlirDenseElementsAttrGetUInt8Value(MlirAttribute attr, intptr_t pos);
547 MLIR_CAPI_EXPORTED int16_t
548 mlirDenseElementsAttrGetInt16Value(MlirAttribute attr, intptr_t pos);
549 MLIR_CAPI_EXPORTED uint16_t
550 mlirDenseElementsAttrGetUInt16Value(MlirAttribute attr, intptr_t pos);
551 MLIR_CAPI_EXPORTED int32_t
552 mlirDenseElementsAttrGetInt32Value(MlirAttribute attr, intptr_t pos);
553 MLIR_CAPI_EXPORTED uint32_t
554 mlirDenseElementsAttrGetUInt32Value(MlirAttribute attr, intptr_t pos);
555 MLIR_CAPI_EXPORTED int64_t
556 mlirDenseElementsAttrGetInt64Value(MlirAttribute attr, intptr_t pos);
557 MLIR_CAPI_EXPORTED uint64_t
558 mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos);
559 MLIR_CAPI_EXPORTED float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr,
560 intptr_t pos);
561 MLIR_CAPI_EXPORTED double
562 mlirDenseElementsAttrGetDoubleValue(MlirAttribute attr, intptr_t pos);
563 MLIR_CAPI_EXPORTED MlirStringRef
564 mlirDenseElementsAttrGetStringValue(MlirAttribute attr, intptr_t pos);
566 /// Returns the raw data of the given dense elements attribute.
567 MLIR_CAPI_EXPORTED const void *
568 mlirDenseElementsAttrGetRawData(MlirAttribute attr);
570 //===----------------------------------------------------------------------===//
571 // Resource blob attributes.
572 //===----------------------------------------------------------------------===//
574 MLIR_CAPI_EXPORTED bool
575 mlirAttributeIsADenseResourceElements(MlirAttribute attr);
577 /// Unlike the typed accessors below, constructs the attribute with a raw
578 /// data buffer and no type/alignment checking. Use a more strongly typed
579 /// accessor if possible. If dataIsMutable is false, then an immutable
580 /// AsmResourceBlob will be created and that passed data contents will be
581 /// treated as const.
582 /// If the deleter is non NULL, then it will be called when the data buffer
583 /// can no longer be accessed (passing userData to it).
584 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseResourceElementsAttrGet(
585 MlirType shapedType, MlirStringRef name, void *data, size_t dataLength,
586 size_t dataAlignment, bool dataIsMutable,
587 void (*deleter)(void *userData, const void *data, size_t size,
588 size_t align),
589 void *userData);
591 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseBoolResourceElementsAttrGet(
592 MlirType shapedType, MlirStringRef name, intptr_t numElements,
593 const int *elements);
594 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseUInt8ResourceElementsAttrGet(
595 MlirType shapedType, MlirStringRef name, intptr_t numElements,
596 const uint8_t *elements);
597 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseInt8ResourceElementsAttrGet(
598 MlirType shapedType, MlirStringRef name, intptr_t numElements,
599 const int8_t *elements);
600 MLIR_CAPI_EXPORTED MlirAttribute
601 mlirUnmanagedDenseUInt16ResourceElementsAttrGet(MlirType shapedType,
602 MlirStringRef name,
603 intptr_t numElements,
604 const uint16_t *elements);
605 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseInt16ResourceElementsAttrGet(
606 MlirType shapedType, MlirStringRef name, intptr_t numElements,
607 const int16_t *elements);
608 MLIR_CAPI_EXPORTED MlirAttribute
609 mlirUnmanagedDenseUInt32ResourceElementsAttrGet(MlirType shapedType,
610 MlirStringRef name,
611 intptr_t numElements,
612 const uint32_t *elements);
613 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseInt32ResourceElementsAttrGet(
614 MlirType shapedType, MlirStringRef name, intptr_t numElements,
615 const int32_t *elements);
616 MLIR_CAPI_EXPORTED MlirAttribute
617 mlirUnmanagedDenseUInt64ResourceElementsAttrGet(MlirType shapedType,
618 MlirStringRef name,
619 intptr_t numElements,
620 const uint64_t *elements);
621 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseInt64ResourceElementsAttrGet(
622 MlirType shapedType, MlirStringRef name, intptr_t numElements,
623 const int64_t *elements);
624 MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseFloatResourceElementsAttrGet(
625 MlirType shapedType, MlirStringRef name, intptr_t numElements,
626 const float *elements);
627 MLIR_CAPI_EXPORTED MlirAttribute
628 mlirUnmanagedDenseDoubleResourceElementsAttrGet(MlirType shapedType,
629 MlirStringRef name,
630 intptr_t numElements,
631 const double *elements);
633 /// Returns the pos-th value (flat contiguous indexing) of a specific type
634 /// contained by the given dense resource elements attribute.
635 MLIR_CAPI_EXPORTED bool
636 mlirDenseBoolResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
637 MLIR_CAPI_EXPORTED int8_t
638 mlirDenseInt8ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
639 MLIR_CAPI_EXPORTED uint8_t
640 mlirDenseUInt8ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
641 MLIR_CAPI_EXPORTED int16_t
642 mlirDenseInt16ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
643 MLIR_CAPI_EXPORTED uint16_t
644 mlirDenseUInt16ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
645 MLIR_CAPI_EXPORTED int32_t
646 mlirDenseInt32ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
647 MLIR_CAPI_EXPORTED uint32_t
648 mlirDenseUInt32ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
649 MLIR_CAPI_EXPORTED int64_t
650 mlirDenseInt64ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
651 MLIR_CAPI_EXPORTED uint64_t
652 mlirDenseUInt64ResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
653 MLIR_CAPI_EXPORTED float
654 mlirDenseFloatResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
655 MLIR_CAPI_EXPORTED double
656 mlirDenseDoubleResourceElementsAttrGetValue(MlirAttribute attr, intptr_t pos);
658 //===----------------------------------------------------------------------===//
659 // Sparse elements attribute.
660 //===----------------------------------------------------------------------===//
662 /// Checks whether the given attribute is a sparse elements attribute.
663 MLIR_CAPI_EXPORTED bool mlirAttributeIsASparseElements(MlirAttribute attr);
665 /// Creates a sparse elements attribute of the given shape from a list of
666 /// indices and a list of associated values. Both lists are expected to be dense
667 /// elements attributes with the same number of elements. The list of indices is
668 /// expected to contain 64-bit integers. The attribute is created in the same
669 /// context as the type.
670 MLIR_CAPI_EXPORTED MlirAttribute mlirSparseElementsAttribute(
671 MlirType shapedType, MlirAttribute denseIndices, MlirAttribute denseValues);
673 /// Returns the dense elements attribute containing 64-bit integer indices of
674 /// non-null elements in the given sparse elements attribute.
675 MLIR_CAPI_EXPORTED MlirAttribute
676 mlirSparseElementsAttrGetIndices(MlirAttribute attr);
678 /// Returns the dense elements attribute containing the non-null elements in the
679 /// given sparse elements attribute.
680 MLIR_CAPI_EXPORTED MlirAttribute
681 mlirSparseElementsAttrGetValues(MlirAttribute attr);
683 /// Returns the typeID of a SparseElements attribute.
684 MLIR_CAPI_EXPORTED MlirTypeID mlirSparseElementsAttrGetTypeID(void);
686 //===----------------------------------------------------------------------===//
687 // Strided layout attribute.
688 //===----------------------------------------------------------------------===//
690 // Checks wheather the given attribute is a strided layout attribute.
691 MLIR_CAPI_EXPORTED bool mlirAttributeIsAStridedLayout(MlirAttribute attr);
693 // Creates a strided layout attribute from given strides and offset.
694 MLIR_CAPI_EXPORTED MlirAttribute
695 mlirStridedLayoutAttrGet(MlirContext ctx, int64_t offset, intptr_t numStrides,
696 const int64_t *strides);
698 // Returns the offset in the given strided layout layout attribute.
699 MLIR_CAPI_EXPORTED int64_t mlirStridedLayoutAttrGetOffset(MlirAttribute attr);
701 // Returns the number of strides in the given strided layout attribute.
702 MLIR_CAPI_EXPORTED intptr_t
703 mlirStridedLayoutAttrGetNumStrides(MlirAttribute attr);
705 // Returns the pos-th stride stored in the given strided layout attribute.
706 MLIR_CAPI_EXPORTED int64_t mlirStridedLayoutAttrGetStride(MlirAttribute attr,
707 intptr_t pos);
709 /// Returns the typeID of a StridedLayout attribute.
710 MLIR_CAPI_EXPORTED MlirTypeID mlirStridedLayoutAttrGetTypeID(void);
712 #ifdef __cplusplus
714 #endif
716 #endif // MLIR_C_BUILTINATTRIBUTES_H