[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / mlir / include / mlir-c / Dialect / SparseTensor.h
blob859a4f0dd9f52c8d8fd3da130052caae6e53a3ae
1 //===-- mlir-c/Dialect/SparseTensor.h - C API for SparseTensor ----*- 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 //===----------------------------------------------------------------------===//
10 #ifndef MLIR_C_DIALECT_SPARSETENSOR_H
11 #define MLIR_C_DIALECT_SPARSETENSOR_H
13 #include "mlir-c/AffineMap.h"
14 #include "mlir-c/IR.h"
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
20 MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(SparseTensor, sparse_tensor);
22 /// Dimension level types (and properties) that define sparse tensors.
23 /// See the documentation in SparseTensorAttrDefs.td for their meaning.
24 ///
25 /// These correspond to SparseTensorEncodingAttr::DimLevelType in the C++ API.
26 /// If updating, keep them in sync and update the static_assert in the impl
27 /// file.
28 enum MlirSparseTensorDimLevelType {
29 MLIR_SPARSE_TENSOR_DIM_LEVEL_DENSE = 4, // 0b00001_00
30 MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED = 8, // 0b00010_00
31 MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NU = 9, // 0b00010_01
32 MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NO = 10, // 0b00010_10
33 MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NU_NO = 11, // 0b00010_11
34 MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON = 16, // 0b00100_00
35 MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NU = 17, // 0b00100_01
36 MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NO = 18, // 0b00100_10
37 MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NU_NO = 19, // 0b00100_11
38 MLIR_SPARSE_TENSOR_DIM_LEVEL_LOOSE_COMPRESSED = 32, // 0b01000_00
39 MLIR_SPARSE_TENSOR_DIM_LEVEL_LOOSE_COMPRESSED_NU = 33, // 0b01000_01
40 MLIR_SPARSE_TENSOR_DIM_LEVEL_LOOSE_COMPRESSED_NO = 34, // 0b01000_10
41 MLIR_SPARSE_TENSOR_DIM_LEVEL_LOOSE_COMPRESSED_NU_NO = 35, // 0b01000_11
42 MLIR_SPARSE_TENSOR_DIM_LEVEL_TWO_OUT_OF_FOUR = 64, // 0b10000_00
45 //===----------------------------------------------------------------------===//
46 // SparseTensorEncodingAttr
47 //===----------------------------------------------------------------------===//
49 /// Checks whether the given attribute is a `sparse_tensor.encoding` attribute.
50 MLIR_CAPI_EXPORTED bool
51 mlirAttributeIsASparseTensorEncodingAttr(MlirAttribute attr);
53 /// Creates a `sparse_tensor.encoding` attribute with the given parameters.
54 MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGet(
55 MlirContext ctx, intptr_t lvlRank,
56 enum MlirSparseTensorDimLevelType const *lvlTypes, MlirAffineMap dimToLvl,
57 MlirAffineMap lvlTodim, int posWidth, int crdWidth);
59 /// Returns the level-rank of the `sparse_tensor.encoding` attribute.
60 MLIR_CAPI_EXPORTED intptr_t
61 mlirSparseTensorEncodingGetLvlRank(MlirAttribute attr);
63 /// Returns a specified level-type of the `sparse_tensor.encoding` attribute.
64 MLIR_CAPI_EXPORTED enum MlirSparseTensorDimLevelType
65 mlirSparseTensorEncodingAttrGetLvlType(MlirAttribute attr, intptr_t lvl);
67 /// Returns the dimension-to-level mapping of the `sparse_tensor.encoding`
68 /// attribute.
69 MLIR_CAPI_EXPORTED MlirAffineMap
70 mlirSparseTensorEncodingAttrGetDimToLvl(MlirAttribute attr);
72 /// Returns the level-to-dimension mapping of the `sparse_tensor.encoding`
73 /// attribute.
74 MLIR_CAPI_EXPORTED MlirAffineMap
75 mlirSparseTensorEncodingAttrGetLvlToDim(MlirAttribute attr);
77 /// Returns the position bitwidth of the `sparse_tensor.encoding` attribute.
78 MLIR_CAPI_EXPORTED int
79 mlirSparseTensorEncodingAttrGetPosWidth(MlirAttribute attr);
81 /// Returns the coordinate bitwidth of the `sparse_tensor.encoding` attribute.
82 MLIR_CAPI_EXPORTED int
83 mlirSparseTensorEncodingAttrGetCrdWidth(MlirAttribute attr);
85 #ifdef __cplusplus
87 #endif
89 #include "mlir/Dialect/SparseTensor/Transforms/Passes.capi.h.inc"
91 #endif // MLIR_C_DIALECT_SPARSETENSOR_H