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(); 27 28 //===----------------------------------------------------------------------===// 29 // Affine map attribute. 30 //===----------------------------------------------------------------------===// 31 32 /// Checks whether the given attribute is an affine map attribute. 33 MLIR_CAPI_EXPORTED bool mlirAttributeIsAAffineMap(MlirAttribute attr); 34 35 /// Creates an affine map attribute wrapping the given map. The attribute 36 /// belongs to the same context as the affine map. 37 MLIR_CAPI_EXPORTED MlirAttribute mlirAffineMapAttrGet(MlirAffineMap map); 38 39 /// Returns the affine map wrapped in the given affine map attribute. 40 MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapAttrGetValue(MlirAttribute attr); 41 42 //===----------------------------------------------------------------------===// 43 // Array attribute. 44 //===----------------------------------------------------------------------===// 45 46 /// Checks whether the given attribute is an array attribute. 47 MLIR_CAPI_EXPORTED bool mlirAttributeIsAArray(MlirAttribute attr); 48 49 /// Creates an array element containing the given list of elements in the given 50 /// context. 51 MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGet( 52 MlirContext ctx, intptr_t numElements, MlirAttribute const *elements); 53 54 /// Returns the number of elements stored in the given array attribute. 55 MLIR_CAPI_EXPORTED intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr); 56 57 /// Returns pos-th element stored in the given array attribute. 58 MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGetElement(MlirAttribute attr, 59 intptr_t pos); 60 61 //===----------------------------------------------------------------------===// 62 // Dictionary attribute. 63 //===----------------------------------------------------------------------===// 64 65 /// Checks whether the given attribute is a dictionary attribute. 66 MLIR_CAPI_EXPORTED bool mlirAttributeIsADictionary(MlirAttribute attr); 67 68 /// Creates a dictionary attribute containing the given list of elements in the 69 /// provided context. 70 MLIR_CAPI_EXPORTED MlirAttribute mlirDictionaryAttrGet( 71 MlirContext ctx, intptr_t numElements, MlirNamedAttribute const *elements); 72 73 /// Returns the number of attributes contained in a dictionary attribute. 74 MLIR_CAPI_EXPORTED intptr_t 75 mlirDictionaryAttrGetNumElements(MlirAttribute attr); 76 77 /// Returns pos-th element of the given dictionary attribute. 78 MLIR_CAPI_EXPORTED MlirNamedAttribute 79 mlirDictionaryAttrGetElement(MlirAttribute attr, intptr_t pos); 80 81 /// Returns the dictionary attribute element with the given name or NULL if the 82 /// given name does not exist in the dictionary. 83 MLIR_CAPI_EXPORTED MlirAttribute 84 mlirDictionaryAttrGetElementByName(MlirAttribute attr, MlirStringRef name); 85 86 //===----------------------------------------------------------------------===// 87 // Floating point attribute. 88 //===----------------------------------------------------------------------===// 89 90 // TODO: add support for APFloat and APInt to LLVM IR C API, then expose the 91 // relevant functions here. 92 93 /// Checks whether the given attribute is a floating point attribute. 94 MLIR_CAPI_EXPORTED bool mlirAttributeIsAFloat(MlirAttribute attr); 95 96 /// Creates a floating point attribute in the given context with the given 97 /// double value and double-precision FP semantics. 98 MLIR_CAPI_EXPORTED MlirAttribute mlirFloatAttrDoubleGet(MlirContext ctx, 99 MlirType type, 100 double value); 101 102 /// Same as "mlirFloatAttrDoubleGet", but if the type is not valid for a 103 /// construction of a FloatAttr, returns a null MlirAttribute. 104 MLIR_CAPI_EXPORTED MlirAttribute mlirFloatAttrDoubleGetChecked(MlirLocation loc, 105 MlirType type, 106 double value); 107 108 /// Returns the value stored in the given floating point attribute, interpreting 109 /// the value as double. 110 MLIR_CAPI_EXPORTED double mlirFloatAttrGetValueDouble(MlirAttribute attr); 111 112 //===----------------------------------------------------------------------===// 113 // Integer attribute. 114 //===----------------------------------------------------------------------===// 115 116 // TODO: add support for APFloat and APInt to LLVM IR C API, then expose the 117 // relevant functions here. 118 119 /// Checks whether the given attribute is an integer attribute. 120 MLIR_CAPI_EXPORTED bool mlirAttributeIsAInteger(MlirAttribute attr); 121 122 /// Creates an integer attribute of the given type with the given integer 123 /// value. 124 MLIR_CAPI_EXPORTED MlirAttribute mlirIntegerAttrGet(MlirType type, 125 int64_t value); 126 127 /// Returns the value stored in the given integer attribute, assuming the value 128 /// is of signless type and fits into a signed 64-bit integer. 129 MLIR_CAPI_EXPORTED int64_t mlirIntegerAttrGetValueInt(MlirAttribute attr); 130 131 /// Returns the value stored in the given integer attribute, assuming the value 132 /// is of signed type and fits into a signed 64-bit integer. 133 MLIR_CAPI_EXPORTED int64_t mlirIntegerAttrGetValueSInt(MlirAttribute attr); 134 135 /// Returns the value stored in the given integer attribute, assuming the value 136 /// is of unsigned type and fits into an unsigned 64-bit integer. 137 MLIR_CAPI_EXPORTED uint64_t mlirIntegerAttrGetValueUInt(MlirAttribute attr); 138 139 //===----------------------------------------------------------------------===// 140 // Bool attribute. 141 //===----------------------------------------------------------------------===// 142 143 /// Checks whether the given attribute is a bool attribute. 144 MLIR_CAPI_EXPORTED bool mlirAttributeIsABool(MlirAttribute attr); 145 146 /// Creates a bool attribute in the given context with the given value. 147 MLIR_CAPI_EXPORTED MlirAttribute mlirBoolAttrGet(MlirContext ctx, int value); 148 149 /// Returns the value stored in the given bool attribute. 150 MLIR_CAPI_EXPORTED bool mlirBoolAttrGetValue(MlirAttribute attr); 151 152 //===----------------------------------------------------------------------===// 153 // Integer set attribute. 154 //===----------------------------------------------------------------------===// 155 156 /// Checks whether the given attribute is an integer set attribute. 157 MLIR_CAPI_EXPORTED bool mlirAttributeIsAIntegerSet(MlirAttribute attr); 158 159 //===----------------------------------------------------------------------===// 160 // Opaque attribute. 161 //===----------------------------------------------------------------------===// 162 163 /// Checks whether the given attribute is an opaque attribute. 164 MLIR_CAPI_EXPORTED bool mlirAttributeIsAOpaque(MlirAttribute attr); 165 166 /// Creates an opaque attribute in the given context associated with the dialect 167 /// identified by its namespace. The attribute contains opaque byte data of the 168 /// specified length (data need not be null-terminated). 169 MLIR_CAPI_EXPORTED MlirAttribute 170 mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace, 171 intptr_t dataLength, const char *data, MlirType type); 172 173 /// Returns the namespace of the dialect with which the given opaque attribute 174 /// is associated. The namespace string is owned by the context. 175 MLIR_CAPI_EXPORTED MlirStringRef 176 mlirOpaqueAttrGetDialectNamespace(MlirAttribute attr); 177 178 /// Returns the raw data as a string reference. The data remains live as long as 179 /// the context in which the attribute lives. 180 MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueAttrGetData(MlirAttribute attr); 181 182 //===----------------------------------------------------------------------===// 183 // String attribute. 184 //===----------------------------------------------------------------------===// 185 186 /// Checks whether the given attribute is a string attribute. 187 MLIR_CAPI_EXPORTED bool mlirAttributeIsAString(MlirAttribute attr); 188 189 /// Creates a string attribute in the given context containing the given string. 190 191 MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrGet(MlirContext ctx, 192 MlirStringRef str); 193 194 /// Creates a string attribute in the given context containing the given string. 195 /// Additionally, the attribute has the given type. 196 MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrTypedGet(MlirType type, 197 MlirStringRef str); 198 199 /// Returns the attribute values as a string reference. The data remains live as 200 /// long as the context in which the attribute lives. 201 MLIR_CAPI_EXPORTED MlirStringRef mlirStringAttrGetValue(MlirAttribute attr); 202 203 //===----------------------------------------------------------------------===// 204 // SymbolRef attribute. 205 //===----------------------------------------------------------------------===// 206 207 /// Checks whether the given attribute is a symbol reference attribute. 208 MLIR_CAPI_EXPORTED bool mlirAttributeIsASymbolRef(MlirAttribute attr); 209 210 /// Creates a symbol reference attribute in the given context referencing a 211 /// symbol identified by the given string inside a list of nested references. 212 /// Each of the references in the list must not be nested. 213 MLIR_CAPI_EXPORTED MlirAttribute 214 mlirSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol, 215 intptr_t numReferences, MlirAttribute const *references); 216 217 /// Returns the string reference to the root referenced symbol. The data remains 218 /// live as long as the context in which the attribute lives. 219 MLIR_CAPI_EXPORTED MlirStringRef 220 mlirSymbolRefAttrGetRootReference(MlirAttribute attr); 221 222 /// Returns the string reference to the leaf referenced symbol. The data remains 223 /// live as long as the context in which the attribute lives. 224 MLIR_CAPI_EXPORTED MlirStringRef 225 mlirSymbolRefAttrGetLeafReference(MlirAttribute attr); 226 227 /// Returns the number of references nested in the given symbol reference 228 /// attribute. 229 MLIR_CAPI_EXPORTED intptr_t 230 mlirSymbolRefAttrGetNumNestedReferences(MlirAttribute attr); 231 232 /// Returns pos-th reference nested in the given symbol reference attribute. 233 MLIR_CAPI_EXPORTED MlirAttribute 234 mlirSymbolRefAttrGetNestedReference(MlirAttribute attr, intptr_t pos); 235 236 //===----------------------------------------------------------------------===// 237 // Flat SymbolRef attribute. 238 //===----------------------------------------------------------------------===// 239 240 /// Checks whether the given attribute is a flat symbol reference attribute. 241 MLIR_CAPI_EXPORTED bool mlirAttributeIsAFlatSymbolRef(MlirAttribute attr); 242 243 /// Creates a flat symbol reference attribute in the given context referencing a 244 /// symbol identified by the given string. 245 MLIR_CAPI_EXPORTED MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx, 246 MlirStringRef symbol); 247 248 /// Returns the referenced symbol as a string reference. The data remains live 249 /// as long as the context in which the attribute lives. 250 MLIR_CAPI_EXPORTED MlirStringRef 251 mlirFlatSymbolRefAttrGetValue(MlirAttribute attr); 252 253 //===----------------------------------------------------------------------===// 254 // Type attribute. 255 //===----------------------------------------------------------------------===// 256 257 /// Checks whether the given attribute is a type attribute. 258 MLIR_CAPI_EXPORTED bool mlirAttributeIsAType(MlirAttribute attr); 259 260 /// Creates a type attribute wrapping the given type in the same context as the 261 /// type. 262 MLIR_CAPI_EXPORTED MlirAttribute mlirTypeAttrGet(MlirType type); 263 264 /// Returns the type stored in the given type attribute. 265 MLIR_CAPI_EXPORTED MlirType mlirTypeAttrGetValue(MlirAttribute attr); 266 267 //===----------------------------------------------------------------------===// 268 // Unit attribute. 269 //===----------------------------------------------------------------------===// 270 271 /// Checks whether the given attribute is a unit attribute. 272 MLIR_CAPI_EXPORTED bool mlirAttributeIsAUnit(MlirAttribute attr); 273 274 /// Creates a unit attribute in the given context. 275 MLIR_CAPI_EXPORTED MlirAttribute mlirUnitAttrGet(MlirContext ctx); 276 277 //===----------------------------------------------------------------------===// 278 // Elements attributes. 279 //===----------------------------------------------------------------------===// 280 281 /// Checks whether the given attribute is an elements attribute. 282 MLIR_CAPI_EXPORTED bool mlirAttributeIsAElements(MlirAttribute attr); 283 284 /// Returns the element at the given rank-dimensional index. 285 MLIR_CAPI_EXPORTED MlirAttribute mlirElementsAttrGetValue(MlirAttribute attr, 286 intptr_t rank, 287 uint64_t *idxs); 288 289 /// Checks whether the given rank-dimensional index is valid in the given 290 /// elements attribute. 291 MLIR_CAPI_EXPORTED bool 292 mlirElementsAttrIsValidIndex(MlirAttribute attr, intptr_t rank, uint64_t *idxs); 293 294 /// Gets the total number of elements in the given elements attribute. In order 295 /// to iterate over the attribute, obtain its type, which must be a statically 296 /// shaped type and use its sizes to build a multi-dimensional index. 297 MLIR_CAPI_EXPORTED int64_t mlirElementsAttrGetNumElements(MlirAttribute attr); 298 299 //===----------------------------------------------------------------------===// 300 // Dense elements attribute. 301 //===----------------------------------------------------------------------===// 302 303 // TODO: decide on the interface and add support for complex elements. 304 // TODO: add support for APFloat and APInt to LLVM IR C API, then expose the 305 // relevant functions here. 306 307 /// Checks whether the given attribute is a dense elements attribute. 308 MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseElements(MlirAttribute attr); 309 MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseIntElements(MlirAttribute attr); 310 MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseFPElements(MlirAttribute attr); 311 312 /// Creates a dense elements attribute with the given Shaped type and elements 313 /// in the same context as the type. 314 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrGet( 315 MlirType shapedType, intptr_t numElements, MlirAttribute const *elements); 316 317 /// Creates a dense elements attribute with the given Shaped type and elements 318 /// populated from a packed, row-major opaque buffer of contents. 319 /// 320 /// The format of the raw buffer is a densely packed array of values that 321 /// can be bitcast to the storage format of the element type specified. 322 /// Types that are not byte aligned will be: 323 /// - For bitwidth > 1: Rounded up to the next byte. 324 /// - For bitwidth = 1: Packed into 8bit bytes with bits corresponding to 325 /// the linear order of the shape type from MSB to LSB, padded to on the 326 /// right. 327 /// 328 /// A raw buffer of a single element (or for 1-bit, a byte of value 0 or 255) 329 /// will be interpreted as a splat. User code should be prepared for additional, 330 /// conformant patterns to be identified as splats in the future. 331 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrRawBufferGet( 332 MlirType shapedType, size_t rawBufferSize, const void *rawBuffer); 333 334 /// Creates a dense elements attribute with the given Shaped type containing a 335 /// single replicated element (splat). 336 MLIR_CAPI_EXPORTED MlirAttribute 337 mlirDenseElementsAttrSplatGet(MlirType shapedType, MlirAttribute element); 338 MLIR_CAPI_EXPORTED MlirAttribute 339 mlirDenseElementsAttrBoolSplatGet(MlirType shapedType, bool element); 340 MLIR_CAPI_EXPORTED MlirAttribute 341 mlirDenseElementsAttrUInt8SplatGet(MlirType shapedType, uint8_t element); 342 MLIR_CAPI_EXPORTED MlirAttribute 343 mlirDenseElementsAttrInt8SplatGet(MlirType shapedType, int8_t element); 344 MLIR_CAPI_EXPORTED MlirAttribute 345 mlirDenseElementsAttrUInt32SplatGet(MlirType shapedType, uint32_t element); 346 MLIR_CAPI_EXPORTED MlirAttribute 347 mlirDenseElementsAttrInt32SplatGet(MlirType shapedType, int32_t element); 348 MLIR_CAPI_EXPORTED MlirAttribute 349 mlirDenseElementsAttrUInt64SplatGet(MlirType shapedType, uint64_t element); 350 MLIR_CAPI_EXPORTED MlirAttribute 351 mlirDenseElementsAttrInt64SplatGet(MlirType shapedType, int64_t element); 352 MLIR_CAPI_EXPORTED MlirAttribute 353 mlirDenseElementsAttrFloatSplatGet(MlirType shapedType, float element); 354 MLIR_CAPI_EXPORTED MlirAttribute 355 mlirDenseElementsAttrDoubleSplatGet(MlirType shapedType, double element); 356 357 /// Creates a dense elements attribute with the given shaped type from elements 358 /// of a specific type. Expects the element type of the shaped type to match the 359 /// data element type. 360 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrBoolGet( 361 MlirType shapedType, intptr_t numElements, const int *elements); 362 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt8Get( 363 MlirType shapedType, intptr_t numElements, const uint8_t *elements); 364 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt8Get( 365 MlirType shapedType, intptr_t numElements, const int8_t *elements); 366 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt16Get( 367 MlirType shapedType, intptr_t numElements, const uint16_t *elements); 368 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt16Get( 369 MlirType shapedType, intptr_t numElements, const int16_t *elements); 370 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt32Get( 371 MlirType shapedType, intptr_t numElements, const uint32_t *elements); 372 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt32Get( 373 MlirType shapedType, intptr_t numElements, const int32_t *elements); 374 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrUInt64Get( 375 MlirType shapedType, intptr_t numElements, const uint64_t *elements); 376 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrInt64Get( 377 MlirType shapedType, intptr_t numElements, const int64_t *elements); 378 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrFloatGet( 379 MlirType shapedType, intptr_t numElements, const float *elements); 380 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrDoubleGet( 381 MlirType shapedType, intptr_t numElements, const double *elements); 382 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrBFloat16Get( 383 MlirType shapedType, intptr_t numElements, const uint16_t *elements); 384 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrFloat16Get( 385 MlirType shapedType, intptr_t numElements, const uint16_t *elements); 386 387 /// Creates a dense elements attribute with the given shaped type from string 388 /// elements. 389 MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrStringGet( 390 MlirType shapedType, intptr_t numElements, MlirStringRef *strs); 391 392 /// Creates a dense elements attribute that has the same data as the given dense 393 /// elements attribute and a different shaped type. The new type must have the 394 /// same total number of elements. 395 MLIR_CAPI_EXPORTED MlirAttribute 396 mlirDenseElementsAttrReshapeGet(MlirAttribute attr, MlirType shapedType); 397 398 /// Checks whether the given dense elements attribute contains a single 399 /// replicated value (splat). 400 MLIR_CAPI_EXPORTED bool mlirDenseElementsAttrIsSplat(MlirAttribute attr); 401 402 /// Returns the single replicated value (splat) of a specific type contained by 403 /// the given dense elements attribute. 404 MLIR_CAPI_EXPORTED MlirAttribute 405 mlirDenseElementsAttrGetSplatValue(MlirAttribute attr); 406 MLIR_CAPI_EXPORTED int 407 mlirDenseElementsAttrGetBoolSplatValue(MlirAttribute attr); 408 MLIR_CAPI_EXPORTED int8_t 409 mlirDenseElementsAttrGetInt8SplatValue(MlirAttribute attr); 410 MLIR_CAPI_EXPORTED uint8_t 411 mlirDenseElementsAttrGetUInt8SplatValue(MlirAttribute attr); 412 MLIR_CAPI_EXPORTED int32_t 413 mlirDenseElementsAttrGetInt32SplatValue(MlirAttribute attr); 414 MLIR_CAPI_EXPORTED uint32_t 415 mlirDenseElementsAttrGetUInt32SplatValue(MlirAttribute attr); 416 MLIR_CAPI_EXPORTED int64_t 417 mlirDenseElementsAttrGetInt64SplatValue(MlirAttribute attr); 418 MLIR_CAPI_EXPORTED uint64_t 419 mlirDenseElementsAttrGetUInt64SplatValue(MlirAttribute attr); 420 MLIR_CAPI_EXPORTED float 421 mlirDenseElementsAttrGetFloatSplatValue(MlirAttribute attr); 422 MLIR_CAPI_EXPORTED double 423 mlirDenseElementsAttrGetDoubleSplatValue(MlirAttribute attr); 424 MLIR_CAPI_EXPORTED MlirStringRef 425 mlirDenseElementsAttrGetStringSplatValue(MlirAttribute attr); 426 427 /// Returns the pos-th value (flat contiguous indexing) of a specific type 428 /// contained by the given dense elements attribute. 429 MLIR_CAPI_EXPORTED bool mlirDenseElementsAttrGetBoolValue(MlirAttribute attr, 430 intptr_t pos); 431 MLIR_CAPI_EXPORTED int8_t mlirDenseElementsAttrGetInt8Value(MlirAttribute attr, 432 intptr_t pos); 433 MLIR_CAPI_EXPORTED uint8_t 434 mlirDenseElementsAttrGetUInt8Value(MlirAttribute attr, intptr_t pos); 435 MLIR_CAPI_EXPORTED int16_t 436 mlirDenseElementsAttrGetInt16Value(MlirAttribute attr, intptr_t pos); 437 MLIR_CAPI_EXPORTED uint16_t 438 mlirDenseElementsAttrGetUInt16Value(MlirAttribute attr, intptr_t pos); 439 MLIR_CAPI_EXPORTED int32_t 440 mlirDenseElementsAttrGetInt32Value(MlirAttribute attr, intptr_t pos); 441 MLIR_CAPI_EXPORTED uint32_t 442 mlirDenseElementsAttrGetUInt32Value(MlirAttribute attr, intptr_t pos); 443 MLIR_CAPI_EXPORTED int64_t 444 mlirDenseElementsAttrGetInt64Value(MlirAttribute attr, intptr_t pos); 445 MLIR_CAPI_EXPORTED uint64_t 446 mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos); 447 MLIR_CAPI_EXPORTED float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr, 448 intptr_t pos); 449 MLIR_CAPI_EXPORTED double 450 mlirDenseElementsAttrGetDoubleValue(MlirAttribute attr, intptr_t pos); 451 MLIR_CAPI_EXPORTED MlirStringRef 452 mlirDenseElementsAttrGetStringValue(MlirAttribute attr, intptr_t pos); 453 454 /// Returns the raw data of the given dense elements attribute. 455 MLIR_CAPI_EXPORTED const void * 456 mlirDenseElementsAttrGetRawData(MlirAttribute attr); 457 458 //===----------------------------------------------------------------------===// 459 // Opaque elements attribute. 460 //===----------------------------------------------------------------------===// 461 462 // TODO: expose Dialect to the bindings and implement accessors here. 463 464 /// Checks whether the given attribute is an opaque elements attribute. 465 MLIR_CAPI_EXPORTED bool mlirAttributeIsAOpaqueElements(MlirAttribute attr); 466 467 //===----------------------------------------------------------------------===// 468 // Sparse elements attribute. 469 //===----------------------------------------------------------------------===// 470 471 /// Checks whether the given attribute is a sparse elements attribute. 472 MLIR_CAPI_EXPORTED bool mlirAttributeIsASparseElements(MlirAttribute attr); 473 474 /// Creates a sparse elements attribute of the given shape from a list of 475 /// indices and a list of associated values. Both lists are expected to be dense 476 /// elements attributes with the same number of elements. The list of indices is 477 /// expected to contain 64-bit integers. The attribute is created in the same 478 /// context as the type. 479 MLIR_CAPI_EXPORTED MlirAttribute mlirSparseElementsAttribute( 480 MlirType shapedType, MlirAttribute denseIndices, MlirAttribute denseValues); 481 482 /// Returns the dense elements attribute containing 64-bit integer indices of 483 /// non-null elements in the given sparse elements attribute. 484 MLIR_CAPI_EXPORTED MlirAttribute 485 mlirSparseElementsAttrGetIndices(MlirAttribute attr); 486 487 /// Returns the dense elements attribute containing the non-null elements in the 488 /// given sparse elements attribute. 489 MLIR_CAPI_EXPORTED MlirAttribute 490 mlirSparseElementsAttrGetValues(MlirAttribute attr); 491 492 #ifdef __cplusplus 493 } 494 #endif 495 496 #endif // MLIR_C_BUILTINATTRIBUTES_H 497