|
| 1 | +/*===-- mlir-c/StandardTypes.h - C API for MLIR Standard types ----*- 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 | +#ifndef MLIR_C_STANDARDTYPES_H |
| 11 | +#define MLIR_C_STANDARDTYPES_H |
| 12 | + |
| 13 | +#include "mlir-c/AffineMap.h" |
| 14 | +#include "mlir-c/IR.h" |
| 15 | +#include <stdint.h> |
| 16 | + |
| 17 | +#ifdef __cplusplus |
| 18 | +extern "C" { |
| 19 | +#endif |
| 20 | + |
| 21 | +/*============================================================================*/ |
| 22 | +/* Integer types. */ |
| 23 | +/*============================================================================*/ |
| 24 | + |
| 25 | +/** Checks whether the given type is an integer type. */ |
| 26 | +int mlirTypeIsAInteger(MlirType type); |
| 27 | + |
| 28 | +/** Creates a signless integer type of the given bitwidth in the context. The |
| 29 | + * type is owned by the context. */ |
| 30 | +MlirType mlirIntegerTypeGet(MlirContext ctx, unsigned bitwidth); |
| 31 | + |
| 32 | +/** Creates a signed integer type of the given bitwidth in the context. The type |
| 33 | + * is owned by the context. */ |
| 34 | +MlirType mlirIntegerTypeSignedGet(MlirContext ctx, unsigned bitwidth); |
| 35 | + |
| 36 | +/** Creates an unsigned integer type of the given bitwidth in the context. The |
| 37 | + * type is owned by the context. */ |
| 38 | +MlirType mlirIntegerTypeUnsignedGet(MlirContext ctx, unsigned bitwidth); |
| 39 | + |
| 40 | +/** Returns the bitwidth of an integer type. */ |
| 41 | +unsigned mlirIntegerTypeGetWidth(MlirType type); |
| 42 | + |
| 43 | +/** Checks whether the given integer type is signless. */ |
| 44 | +int mlirIntegerTypeIsSignless(MlirType type); |
| 45 | + |
| 46 | +/** Checks whether the given integer type is signed. */ |
| 47 | +int mlirIntegerTypeIsSigned(MlirType type); |
| 48 | + |
| 49 | +/** Checks whether the given integer type is unsigned. */ |
| 50 | +int mlirIntegerTypeIsUnsigned(MlirType type); |
| 51 | + |
| 52 | +/*============================================================================*/ |
| 53 | +/* Index type. */ |
| 54 | +/*============================================================================*/ |
| 55 | + |
| 56 | +/** Checks whether the given type is an index type. */ |
| 57 | +int mlirTypeIsAIndex(MlirType type); |
| 58 | + |
| 59 | +/** Creates an index type in the given context. The type is owned by the |
| 60 | + * context. */ |
| 61 | +MlirType mlirIndexTypeGet(MlirContext ctx); |
| 62 | + |
| 63 | +/*============================================================================*/ |
| 64 | +/* Floating-point types. */ |
| 65 | +/*============================================================================*/ |
| 66 | + |
| 67 | +/** Checks whether the given type is a bf16 type. */ |
| 68 | +int mlirTypeIsABF16(MlirType type); |
| 69 | + |
| 70 | +/** Creates a bf16 type in the given context. The type is owned by the |
| 71 | + * context. */ |
| 72 | +MlirType mlirBF16TypeGet(MlirContext ctx); |
| 73 | + |
| 74 | +/** Checks whether the given type is an f16 type. */ |
| 75 | +int mlirTypeIsAF16(MlirType type); |
| 76 | + |
| 77 | +/** Creates an f16 type in the given context. The type is owned by the |
| 78 | + * context. */ |
| 79 | +MlirType mlirF16TypeGet(MlirContext ctx); |
| 80 | + |
| 81 | +/** Checks whether the given type is an f32 type. */ |
| 82 | +int mlirTypeIsAF32(MlirType type); |
| 83 | + |
| 84 | +/** Creates an f32 type in the given context. The type is owned by the |
| 85 | + * context. */ |
| 86 | +MlirType mlirF32TypeGet(MlirContext ctx); |
| 87 | + |
| 88 | +/** Checks whether the given type is an f64 type. */ |
| 89 | +int mlirTypeIsAF64(MlirType type); |
| 90 | + |
| 91 | +/** Creates a f64 type in the given context. The type is owned by the |
| 92 | + * context. */ |
| 93 | +MlirType mlirF64TypeGet(MlirContext ctx); |
| 94 | + |
| 95 | +/*============================================================================*/ |
| 96 | +/* None type. */ |
| 97 | +/*============================================================================*/ |
| 98 | + |
| 99 | +/** Checks whether the given type is a None type. */ |
| 100 | +int mlirTypeIsANone(MlirType type); |
| 101 | + |
| 102 | +/** Creates a None type in the given context. The type is owned by the |
| 103 | + * context. */ |
| 104 | +MlirType mlirNoneTypeGet(MlirContext ctx); |
| 105 | + |
| 106 | +/*============================================================================*/ |
| 107 | +/* Complex type. */ |
| 108 | +/*============================================================================*/ |
| 109 | + |
| 110 | +/** Checks whether the given type is a Complex type. */ |
| 111 | +int mlirTypeIsAComplex(MlirType type); |
| 112 | + |
| 113 | +/** Creates a complex type with the given element type in the same context as |
| 114 | + * the element type. The type is owned by the context. */ |
| 115 | +MlirType mlirComplexTypeGet(MlirType elementType); |
| 116 | + |
| 117 | +/** Returns the element type of the given complex type. */ |
| 118 | +MlirType mlirComplexTypeGetElementType(MlirType type); |
| 119 | + |
| 120 | +/*============================================================================*/ |
| 121 | +/* Shaped type. */ |
| 122 | +/*============================================================================*/ |
| 123 | + |
| 124 | +/** Checks whether the given type is a Shaped type. */ |
| 125 | +int mlirTypeIsAShaped(MlirType type); |
| 126 | + |
| 127 | +/** Returns the element type of the shaped type. */ |
| 128 | +MlirType mlirShapedTypeGetElementType(MlirType type); |
| 129 | + |
| 130 | +/** Checks whether the given shaped type is ranked. */ |
| 131 | +int mlirShapedTypeHasRank(MlirType type); |
| 132 | + |
| 133 | +/** Returns the rank of the given ranked shaped type. */ |
| 134 | +int64_t mlirShapedTypeGetRank(MlirType type); |
| 135 | + |
| 136 | +/** Checks whether the given shaped type has a static shape. */ |
| 137 | +int mlirShapedTypeHasStaticShape(MlirType type); |
| 138 | + |
| 139 | +/** Checks wither the dim-th dimension of the given shaped type is dynamic. */ |
| 140 | +int mlirShapedTypeIsDynamicDim(MlirType type, intptr_t dim); |
| 141 | + |
| 142 | +/** Returns the dim-th dimension of the given ranked shaped type. */ |
| 143 | +int64_t mlirShapedTypeGetDimSize(MlirType type, intptr_t dim); |
| 144 | + |
| 145 | +/** Checks whether the given value is used as a placeholder for dynamic sizes |
| 146 | + * in shaped types. */ |
| 147 | +int mlirShapedTypeIsDynamicSize(int64_t size); |
| 148 | + |
| 149 | +/** Checks whether the given value is used as a placeholder for dynamic strides |
| 150 | + * and offsets in shaped types. */ |
| 151 | +int mlirShapedTypeIsDynamicStrideOrOffset(int64_t val); |
| 152 | + |
| 153 | +/*============================================================================*/ |
| 154 | +/* Vector type. */ |
| 155 | +/*============================================================================*/ |
| 156 | + |
| 157 | +/** Checks whether the given type is a Vector type. */ |
| 158 | +int mlirTypeIsAVector(MlirType type); |
| 159 | + |
| 160 | +/** Creates a vector type of the shape identified by its rank and dimensios, |
| 161 | + * with the given element type in the same context as the element type. The type |
| 162 | + * is owned by the context. */ |
| 163 | +MlirType mlirVectorTypeGet(intptr_t rank, int64_t *shape, MlirType elementType); |
| 164 | + |
| 165 | +/*============================================================================*/ |
| 166 | +/* Ranked / Unranked Tensor type. */ |
| 167 | +/*============================================================================*/ |
| 168 | + |
| 169 | +/** Checks whether the given type is a Tensor type. */ |
| 170 | +int mlirTypeIsATensor(MlirType type); |
| 171 | + |
| 172 | +/** Checks whether the given type is a ranked tensor type. */ |
| 173 | +int mlirTypeIsARankedTensor(MlirType type); |
| 174 | + |
| 175 | +/** Checks whether the given type is an unranked tensor type. */ |
| 176 | +int mlirTypeIsAUnrankedTensor(MlirType type); |
| 177 | + |
| 178 | +/** Creates a tensor type of a fixed rank with the given shape and element type |
| 179 | + * in the same context as the element type. The type is owned by the context. */ |
| 180 | +MlirType mlirRankedTensorTypeGet(intptr_t rank, int64_t *shape, |
| 181 | + MlirType elementType); |
| 182 | + |
| 183 | +/** Creates an unranked tensor type with the given element type in the same |
| 184 | + * context as the element type. The type is owned by the context. */ |
| 185 | +MlirType mlirUnrankedTensorTypeGet(MlirType elementType); |
| 186 | + |
| 187 | +/*============================================================================*/ |
| 188 | +/* Ranked / Unranked MemRef type. */ |
| 189 | +/*============================================================================*/ |
| 190 | + |
| 191 | +/** Checks whether the given type is a MemRef type. */ |
| 192 | +int mlirTypeIsAMemRef(MlirType type); |
| 193 | + |
| 194 | +/** Checks whether the given type is an UnrankedMemRef type. */ |
| 195 | +int mlirTypeIsAUnrankedMemRef(MlirType type); |
| 196 | + |
| 197 | +/** Creates a MemRef type with the given rank and shape, a potentially empty |
| 198 | + * list of affine layout maps, the given memory space and element type, in the |
| 199 | + * same context as element type. The type is owned by the context. */ |
| 200 | +MlirType mlirMemRefTypeGet(MlirType elementType, intptr_t rank, int64_t *shape, |
| 201 | + intptr_t numMaps, MlirAttribute *affineMaps, |
| 202 | + unsigned memorySpace); |
| 203 | + |
| 204 | +/** Creates a MemRef type with the given rank, shape, memory space and element |
| 205 | + * type in the same context as the element type. The type has no affine maps, |
| 206 | + * i.e. represents a default row-major contiguous memref. The type is owned by |
| 207 | + * the context. */ |
| 208 | +MlirType mlirMemRefTypeContiguousGet(MlirType elementType, intptr_t rank, |
| 209 | + int64_t *shape, unsigned memorySpace); |
| 210 | + |
| 211 | +/** Creates an Unranked MemRef type with the given element type and in the given |
| 212 | + * memory space. The type is owned by the context of element type. */ |
| 213 | +MlirType mlirUnrankedMemRefTypeGet(MlirType elementType, unsigned memorySpace); |
| 214 | + |
| 215 | +/** Returns the number of affine layout maps in the given MemRef type. */ |
| 216 | +intptr_t mlirMemRefTypeGetNumAffineMaps(MlirType type); |
| 217 | + |
| 218 | +/** Returns the pos-th affine map of the given MemRef type. */ |
| 219 | +MlirAffineMap mlirMemRefTypeGetAffineMap(MlirType type, intptr_t pos); |
| 220 | + |
| 221 | +/** Returns the memory space of the given MemRef type. */ |
| 222 | +unsigned mlirMemRefTypeGetMemorySpace(MlirType type); |
| 223 | + |
| 224 | +/** Returns the memory spcae of the given Unranked MemRef type. */ |
| 225 | +unsigned mlirUnrankedMemrefGetMemorySpace(MlirType type); |
| 226 | + |
| 227 | +/*============================================================================*/ |
| 228 | +/* Tuple type. */ |
| 229 | +/*============================================================================*/ |
| 230 | + |
| 231 | +/** Checks whether the given type is a tuple type. */ |
| 232 | +int mlirTypeIsATuple(MlirType type); |
| 233 | + |
| 234 | +/** Creates a tuple type that consists of the given list of elemental types. The |
| 235 | + * type is owned by the context. */ |
| 236 | +MlirType mlirTupleTypeGet(MlirContext ctx, intptr_t numElements, |
| 237 | + MlirType *elements); |
| 238 | + |
| 239 | +/** Returns the number of types contained in a tuple. */ |
| 240 | +intptr_t mlirTupleTypeGetNumTypes(MlirType type); |
| 241 | + |
| 242 | +/** Returns the pos-th type in the tuple type. */ |
| 243 | +MlirType mlirTupleTypeGetType(MlirType type, intptr_t pos); |
| 244 | + |
| 245 | +#ifdef __cplusplus |
| 246 | +} |
| 247 | +#endif |
| 248 | + |
| 249 | +#endif // MLIR_C_STANDARDTYPES_H |
0 commit comments