1 //===-- mlir-c/BuiltinTypes.h - C API for MLIR Builtin 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_BUILTINTYPES_H 11 #define MLIR_C_BUILTINTYPES_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 MLIR_CAPI_EXPORTED bool 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 MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeGet(MlirContext ctx, 31 unsigned bitwidth); 32 33 /** Creates a signed integer type of the given bitwidth in the context. The type 34 * is owned by the context. */ 35 MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeSignedGet(MlirContext ctx, 36 unsigned bitwidth); 37 38 /** Creates an unsigned integer type of the given bitwidth in the context. The 39 * type is owned by the context. */ 40 MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeUnsignedGet(MlirContext ctx, 41 unsigned bitwidth); 42 43 /// Returns the bitwidth of an integer type. 44 MLIR_CAPI_EXPORTED unsigned mlirIntegerTypeGetWidth(MlirType type); 45 46 /// Checks whether the given integer type is signless. 47 MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsSignless(MlirType type); 48 49 /// Checks whether the given integer type is signed. 50 MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsSigned(MlirType type); 51 52 /// Checks whether the given integer type is unsigned. 53 MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsUnsigned(MlirType type); 54 55 //===----------------------------------------------------------------------===// 56 // Index type. 57 //===----------------------------------------------------------------------===// 58 59 /// Checks whether the given type is an index type. 60 MLIR_CAPI_EXPORTED bool mlirTypeIsAIndex(MlirType type); 61 62 /** Creates an index type in the given context. The type is owned by the 63 * context. */ 64 MLIR_CAPI_EXPORTED MlirType mlirIndexTypeGet(MlirContext ctx); 65 66 //===----------------------------------------------------------------------===// 67 // Floating-point types. 68 //===----------------------------------------------------------------------===// 69 70 /// Checks whether the given type is a bf16 type. 71 MLIR_CAPI_EXPORTED bool mlirTypeIsABF16(MlirType type); 72 73 /** Creates a bf16 type in the given context. The type is owned by the 74 * context. */ 75 MLIR_CAPI_EXPORTED MlirType mlirBF16TypeGet(MlirContext ctx); 76 77 /// Checks whether the given type is an f16 type. 78 MLIR_CAPI_EXPORTED bool mlirTypeIsAF16(MlirType type); 79 80 /** Creates an f16 type in the given context. The type is owned by the 81 * context. */ 82 MLIR_CAPI_EXPORTED MlirType mlirF16TypeGet(MlirContext ctx); 83 84 /// Checks whether the given type is an f32 type. 85 MLIR_CAPI_EXPORTED bool mlirTypeIsAF32(MlirType type); 86 87 /** Creates an f32 type in the given context. The type is owned by the 88 * context. */ 89 MLIR_CAPI_EXPORTED MlirType mlirF32TypeGet(MlirContext ctx); 90 91 /// Checks whether the given type is an f64 type. 92 MLIR_CAPI_EXPORTED bool mlirTypeIsAF64(MlirType type); 93 94 /** Creates a f64 type in the given context. The type is owned by the 95 * context. */ 96 MLIR_CAPI_EXPORTED MlirType mlirF64TypeGet(MlirContext ctx); 97 98 //===----------------------------------------------------------------------===// 99 // None type. 100 //===----------------------------------------------------------------------===// 101 102 /// Checks whether the given type is a None type. 103 MLIR_CAPI_EXPORTED bool mlirTypeIsANone(MlirType type); 104 105 /** Creates a None type in the given context. The type is owned by the 106 * context. */ 107 MLIR_CAPI_EXPORTED MlirType mlirNoneTypeGet(MlirContext ctx); 108 109 //===----------------------------------------------------------------------===// 110 // Complex type. 111 //===----------------------------------------------------------------------===// 112 113 /// Checks whether the given type is a Complex type. 114 MLIR_CAPI_EXPORTED bool mlirTypeIsAComplex(MlirType type); 115 116 /** Creates a complex type with the given element type in the same context as 117 * the element type. The type is owned by the context. */ 118 MLIR_CAPI_EXPORTED MlirType mlirComplexTypeGet(MlirType elementType); 119 120 /// Returns the element type of the given complex type. 121 MLIR_CAPI_EXPORTED MlirType mlirComplexTypeGetElementType(MlirType type); 122 123 //===----------------------------------------------------------------------===// 124 // Shaped type. 125 //===----------------------------------------------------------------------===// 126 127 /// Checks whether the given type is a Shaped type. 128 MLIR_CAPI_EXPORTED bool mlirTypeIsAShaped(MlirType type); 129 130 /// Returns the element type of the shaped type. 131 MLIR_CAPI_EXPORTED MlirType mlirShapedTypeGetElementType(MlirType type); 132 133 /// Checks whether the given shaped type is ranked. 134 MLIR_CAPI_EXPORTED bool mlirShapedTypeHasRank(MlirType type); 135 136 /// Returns the rank of the given ranked shaped type. 137 MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetRank(MlirType type); 138 139 /// Checks whether the given shaped type has a static shape. 140 MLIR_CAPI_EXPORTED bool mlirShapedTypeHasStaticShape(MlirType type); 141 142 /// Checks wither the dim-th dimension of the given shaped type is dynamic. 143 MLIR_CAPI_EXPORTED bool mlirShapedTypeIsDynamicDim(MlirType type, intptr_t dim); 144 145 /// Returns the dim-th dimension of the given ranked shaped type. 146 MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetDimSize(MlirType type, 147 intptr_t dim); 148 149 /** Checks whether the given value is used as a placeholder for dynamic sizes 150 * in shaped types. */ 151 MLIR_CAPI_EXPORTED bool mlirShapedTypeIsDynamicSize(int64_t size); 152 153 /** Checks whether the given value is used as a placeholder for dynamic strides 154 * and offsets in shaped types. */ 155 MLIR_CAPI_EXPORTED bool mlirShapedTypeIsDynamicStrideOrOffset(int64_t val); 156 157 //===----------------------------------------------------------------------===// 158 // Vector type. 159 //===----------------------------------------------------------------------===// 160 161 /// Checks whether the given type is a Vector type. 162 MLIR_CAPI_EXPORTED bool mlirTypeIsAVector(MlirType type); 163 164 /** Creates a vector type of the shape identified by its rank and dimensions, 165 * with the given element type in the same context as the element type. The type 166 * is owned by the context. */ 167 MLIR_CAPI_EXPORTED MlirType mlirVectorTypeGet(intptr_t rank, 168 const int64_t *shape, 169 MlirType elementType); 170 171 /** Same as "mlirVectorTypeGet" but returns a nullptr wrapping MlirType on 172 * illegal arguments, emitting appropriate diagnostics. */ 173 MLIR_CAPI_EXPORTED MlirType mlirVectorTypeGetChecked(intptr_t rank, 174 const int64_t *shape, 175 MlirType elementType, 176 MlirLocation loc); 177 178 //===----------------------------------------------------------------------===// 179 // Ranked / Unranked Tensor type. 180 //===----------------------------------------------------------------------===// 181 182 /// Checks whether the given type is a Tensor type. 183 MLIR_CAPI_EXPORTED bool mlirTypeIsATensor(MlirType type); 184 185 /// Checks whether the given type is a ranked tensor type. 186 MLIR_CAPI_EXPORTED bool mlirTypeIsARankedTensor(MlirType type); 187 188 /// Checks whether the given type is an unranked tensor type. 189 MLIR_CAPI_EXPORTED bool mlirTypeIsAUnrankedTensor(MlirType type); 190 191 /** Creates a tensor type of a fixed rank with the given shape and element type 192 * in the same context as the element type. The type is owned by the context. */ 193 MLIR_CAPI_EXPORTED MlirType mlirRankedTensorTypeGet(intptr_t rank, 194 const int64_t *shape, 195 MlirType elementType); 196 197 /** Same as "mlirRankedTensorTypeGet" but returns a nullptr wrapping MlirType on 198 * illegal arguments, emitting appropriate diagnostics. */ 199 MLIR_CAPI_EXPORTED MlirType mlirRankedTensorTypeGetChecked(intptr_t rank, 200 const int64_t *shape, 201 MlirType elementType, 202 MlirLocation loc); 203 204 /** Creates an unranked tensor type with the given element type in the same 205 * context as the element type. The type is owned by the context. */ 206 MLIR_CAPI_EXPORTED MlirType mlirUnrankedTensorTypeGet(MlirType elementType); 207 208 /** Same as "mlirUnrankedTensorTypeGet" but returns a nullptr wrapping MlirType 209 * on illegal arguments, emitting appropriate diagnostics. */ 210 MLIR_CAPI_EXPORTED MlirType 211 mlirUnrankedTensorTypeGetChecked(MlirType elementType, MlirLocation loc); 212 213 //===----------------------------------------------------------------------===// 214 // Ranked / Unranked MemRef type. 215 //===----------------------------------------------------------------------===// 216 217 /// Checks whether the given type is a MemRef type. 218 MLIR_CAPI_EXPORTED bool mlirTypeIsAMemRef(MlirType type); 219 220 /// Checks whether the given type is an UnrankedMemRef type. 221 MLIR_CAPI_EXPORTED bool mlirTypeIsAUnrankedMemRef(MlirType type); 222 223 /** Creates a MemRef type with the given rank and shape, a potentially empty 224 * list of affine layout maps, the given memory space and element type, in the 225 * same context as element type. The type is owned by the context. */ 226 MLIR_CAPI_EXPORTED MlirType mlirMemRefTypeGet( 227 MlirType elementType, intptr_t rank, const int64_t *shape, intptr_t numMaps, 228 MlirAttribute const *affineMaps, unsigned memorySpace); 229 230 /** Creates a MemRef type with the given rank, shape, memory space and element 231 * type in the same context as the element type. The type has no affine maps, 232 * i.e. represents a default row-major contiguous memref. The type is owned by 233 * the context. */ 234 MLIR_CAPI_EXPORTED MlirType mlirMemRefTypeContiguousGet(MlirType elementType, 235 intptr_t rank, 236 const int64_t *shape, 237 unsigned memorySpace); 238 239 /** Same as "mlirMemRefTypeContiguousGet" but returns a nullptr wrapping 240 * MlirType on illegal arguments, emitting appropriate diagnostics. */ 241 MLIR_CAPI_EXPORTED MlirType mlirMemRefTypeContiguousGetChecked( 242 MlirType elementType, intptr_t rank, const int64_t *shape, 243 unsigned memorySpace, MlirLocation loc); 244 245 /** Creates an Unranked MemRef type with the given element type and in the given 246 * memory space. The type is owned by the context of element type. */ 247 MLIR_CAPI_EXPORTED MlirType mlirUnrankedMemRefTypeGet(MlirType elementType, 248 unsigned memorySpace); 249 250 /** Same as "mlirUnrankedMemRefTypeGet" but returns a nullptr wrapping 251 * MlirType on illegal arguments, emitting appropriate diagnostics. */ 252 MLIR_CAPI_EXPORTED MlirType mlirUnrankedMemRefTypeGetChecked( 253 MlirType elementType, unsigned memorySpace, MlirLocation loc); 254 255 /// Returns the number of affine layout maps in the given MemRef type. 256 MLIR_CAPI_EXPORTED intptr_t mlirMemRefTypeGetNumAffineMaps(MlirType type); 257 258 /// Returns the pos-th affine map of the given MemRef type. 259 MLIR_CAPI_EXPORTED MlirAffineMap mlirMemRefTypeGetAffineMap(MlirType type, 260 intptr_t pos); 261 262 /// Returns the memory space of the given MemRef type. 263 MLIR_CAPI_EXPORTED unsigned mlirMemRefTypeGetMemorySpace(MlirType type); 264 265 /// Returns the memory spcae of the given Unranked MemRef type. 266 MLIR_CAPI_EXPORTED unsigned mlirUnrankedMemrefGetMemorySpace(MlirType type); 267 268 //===----------------------------------------------------------------------===// 269 // Tuple type. 270 //===----------------------------------------------------------------------===// 271 272 /// Checks whether the given type is a tuple type. 273 MLIR_CAPI_EXPORTED bool mlirTypeIsATuple(MlirType type); 274 275 /** Creates a tuple type that consists of the given list of elemental types. The 276 * type is owned by the context. */ 277 MLIR_CAPI_EXPORTED MlirType mlirTupleTypeGet(MlirContext ctx, 278 intptr_t numElements, 279 MlirType const *elements); 280 281 /// Returns the number of types contained in a tuple. 282 MLIR_CAPI_EXPORTED intptr_t mlirTupleTypeGetNumTypes(MlirType type); 283 284 /// Returns the pos-th type in the tuple type. 285 MLIR_CAPI_EXPORTED MlirType mlirTupleTypeGetType(MlirType type, intptr_t pos); 286 287 //===----------------------------------------------------------------------===// 288 // Function type. 289 //===----------------------------------------------------------------------===// 290 291 /// Checks whether the given type is a function type. 292 MLIR_CAPI_EXPORTED bool mlirTypeIsAFunction(MlirType type); 293 294 /// Creates a function type, mapping a list of input types to result types. 295 MLIR_CAPI_EXPORTED MlirType mlirFunctionTypeGet(MlirContext ctx, 296 intptr_t numInputs, 297 MlirType const *inputs, 298 intptr_t numResults, 299 MlirType const *results); 300 301 /// Returns the number of input types. 302 MLIR_CAPI_EXPORTED intptr_t mlirFunctionTypeGetNumInputs(MlirType type); 303 304 /// Returns the number of result types. 305 MLIR_CAPI_EXPORTED intptr_t mlirFunctionTypeGetNumResults(MlirType type); 306 307 /// Returns the pos-th input type. 308 MLIR_CAPI_EXPORTED MlirType mlirFunctionTypeGetInput(MlirType type, 309 intptr_t pos); 310 311 /// Returns the pos-th result type. 312 MLIR_CAPI_EXPORTED MlirType mlirFunctionTypeGetResult(MlirType type, 313 intptr_t pos); 314 315 #ifdef __cplusplus 316 } 317 #endif 318 319 #endif // MLIR_C_BUILTINTYPES_H 320