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