MLIR  20.0.0git
BuiltinTypes.cpp
Go to the documentation of this file.
1 //===- BuiltinTypes.cpp - C Interface to MLIR Builtin Types ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "mlir-c/BuiltinTypes.h"
10 #include "mlir-c/AffineMap.h"
11 #include "mlir-c/IR.h"
12 #include "mlir-c/Support.h"
13 #include "mlir/CAPI/AffineMap.h"
14 #include "mlir/CAPI/IR.h"
15 #include "mlir/CAPI/Support.h"
16 #include "mlir/IR/AffineMap.h"
17 #include "mlir/IR/BuiltinTypes.h"
18 #include "mlir/IR/Types.h"
19 
20 #include <algorithm>
21 
22 using namespace mlir;
23 
24 //===----------------------------------------------------------------------===//
25 // Integer types.
26 //===----------------------------------------------------------------------===//
27 
28 MlirTypeID mlirIntegerTypeGetTypeID() { return wrap(IntegerType::getTypeID()); }
29 
30 bool mlirTypeIsAInteger(MlirType type) {
31  return llvm::isa<IntegerType>(unwrap(type));
32 }
33 
34 MlirType mlirIntegerTypeGet(MlirContext ctx, unsigned bitwidth) {
35  return wrap(IntegerType::get(unwrap(ctx), bitwidth));
36 }
37 
38 MlirType mlirIntegerTypeSignedGet(MlirContext ctx, unsigned bitwidth) {
39  return wrap(IntegerType::get(unwrap(ctx), bitwidth, IntegerType::Signed));
40 }
41 
42 MlirType mlirIntegerTypeUnsignedGet(MlirContext ctx, unsigned bitwidth) {
43  return wrap(IntegerType::get(unwrap(ctx), bitwidth, IntegerType::Unsigned));
44 }
45 
46 unsigned mlirIntegerTypeGetWidth(MlirType type) {
47  return llvm::cast<IntegerType>(unwrap(type)).getWidth();
48 }
49 
50 bool mlirIntegerTypeIsSignless(MlirType type) {
51  return llvm::cast<IntegerType>(unwrap(type)).isSignless();
52 }
53 
54 bool mlirIntegerTypeIsSigned(MlirType type) {
55  return llvm::cast<IntegerType>(unwrap(type)).isSigned();
56 }
57 
58 bool mlirIntegerTypeIsUnsigned(MlirType type) {
59  return llvm::cast<IntegerType>(unwrap(type)).isUnsigned();
60 }
61 
62 //===----------------------------------------------------------------------===//
63 // Index type.
64 //===----------------------------------------------------------------------===//
65 
66 MlirTypeID mlirIndexTypeGetTypeID() { return wrap(IndexType::getTypeID()); }
67 
68 bool mlirTypeIsAIndex(MlirType type) {
69  return llvm::isa<IndexType>(unwrap(type));
70 }
71 
72 MlirType mlirIndexTypeGet(MlirContext ctx) {
73  return wrap(IndexType::get(unwrap(ctx)));
74 }
75 
76 //===----------------------------------------------------------------------===//
77 // Floating-point types.
78 //===----------------------------------------------------------------------===//
79 
80 bool mlirTypeIsAFloat(MlirType type) {
81  return llvm::isa<FloatType>(unwrap(type));
82 }
83 
84 unsigned mlirFloatTypeGetWidth(MlirType type) {
85  return llvm::cast<FloatType>(unwrap(type)).getWidth();
86 }
87 
89  return wrap(Float8E5M2Type::getTypeID());
90 }
91 
92 bool mlirTypeIsAFloat8E5M2(MlirType type) {
93  return unwrap(type).isFloat8E5M2();
94 }
95 
96 MlirType mlirFloat8E5M2TypeGet(MlirContext ctx) {
97  return wrap(FloatType::getFloat8E5M2(unwrap(ctx)));
98 }
99 
101  return wrap(Float8E4M3Type::getTypeID());
102 }
103 
104 bool mlirTypeIsAFloat8E4M3(MlirType type) {
105  return unwrap(type).isFloat8E4M3();
106 }
107 
108 MlirType mlirFloat8E4M3TypeGet(MlirContext ctx) {
109  return wrap(FloatType::getFloat8E4M3(unwrap(ctx)));
110 }
111 
113  return wrap(Float8E4M3FNType::getTypeID());
114 }
115 
116 bool mlirTypeIsAFloat8E4M3FN(MlirType type) {
117  return unwrap(type).isFloat8E4M3FN();
118 }
119 
120 MlirType mlirFloat8E4M3FNTypeGet(MlirContext ctx) {
121  return wrap(FloatType::getFloat8E4M3FN(unwrap(ctx)));
122 }
123 
125  return wrap(Float8E5M2FNUZType::getTypeID());
126 }
127 
128 bool mlirTypeIsAFloat8E5M2FNUZ(MlirType type) {
129  return unwrap(type).isFloat8E5M2FNUZ();
130 }
131 
132 MlirType mlirFloat8E5M2FNUZTypeGet(MlirContext ctx) {
134 }
135 
137  return wrap(Float8E4M3FNUZType::getTypeID());
138 }
139 
140 bool mlirTypeIsAFloat8E4M3FNUZ(MlirType type) {
141  return unwrap(type).isFloat8E4M3FNUZ();
142 }
143 
144 MlirType mlirFloat8E4M3FNUZTypeGet(MlirContext ctx) {
146 }
147 
149  return wrap(Float8E4M3B11FNUZType::getTypeID());
150 }
151 
152 bool mlirTypeIsAFloat8E4M3B11FNUZ(MlirType type) {
153  return unwrap(type).isFloat8E4M3B11FNUZ();
154 }
155 
156 MlirType mlirFloat8E4M3B11FNUZTypeGet(MlirContext ctx) {
158 }
159 
161  return wrap(BFloat16Type::getTypeID());
162 }
163 
164 bool mlirTypeIsABF16(MlirType type) { return unwrap(type).isBF16(); }
165 
166 MlirType mlirBF16TypeGet(MlirContext ctx) {
167  return wrap(FloatType::getBF16(unwrap(ctx)));
168 }
169 
170 MlirTypeID mlirFloat16TypeGetTypeID() { return wrap(Float16Type::getTypeID()); }
171 
172 bool mlirTypeIsAF16(MlirType type) { return unwrap(type).isF16(); }
173 
174 MlirType mlirF16TypeGet(MlirContext ctx) {
175  return wrap(FloatType::getF16(unwrap(ctx)));
176 }
177 
179  return wrap(FloatTF32Type::getTypeID());
180 }
181 
182 bool mlirTypeIsATF32(MlirType type) { return unwrap(type).isTF32(); }
183 
184 MlirType mlirTF32TypeGet(MlirContext ctx) {
185  return wrap(FloatType::getTF32(unwrap(ctx)));
186 }
187 
188 MlirTypeID mlirFloat32TypeGetTypeID() { return wrap(Float32Type::getTypeID()); }
189 
190 bool mlirTypeIsAF32(MlirType type) { return unwrap(type).isF32(); }
191 
192 MlirType mlirF32TypeGet(MlirContext ctx) {
193  return wrap(FloatType::getF32(unwrap(ctx)));
194 }
195 
196 MlirTypeID mlirFloat64TypeGetTypeID() { return wrap(Float64Type::getTypeID()); }
197 
198 bool mlirTypeIsAF64(MlirType type) { return unwrap(type).isF64(); }
199 
200 MlirType mlirF64TypeGet(MlirContext ctx) {
201  return wrap(FloatType::getF64(unwrap(ctx)));
202 }
203 
204 //===----------------------------------------------------------------------===//
205 // None type.
206 //===----------------------------------------------------------------------===//
207 
208 MlirTypeID mlirNoneTypeGetTypeID() { return wrap(NoneType::getTypeID()); }
209 
210 bool mlirTypeIsANone(MlirType type) {
211  return llvm::isa<NoneType>(unwrap(type));
212 }
213 
214 MlirType mlirNoneTypeGet(MlirContext ctx) {
215  return wrap(NoneType::get(unwrap(ctx)));
216 }
217 
218 //===----------------------------------------------------------------------===//
219 // Complex type.
220 //===----------------------------------------------------------------------===//
221 
222 MlirTypeID mlirComplexTypeGetTypeID() { return wrap(ComplexType::getTypeID()); }
223 
224 bool mlirTypeIsAComplex(MlirType type) {
225  return llvm::isa<ComplexType>(unwrap(type));
226 }
227 
228 MlirType mlirComplexTypeGet(MlirType elementType) {
229  return wrap(ComplexType::get(unwrap(elementType)));
230 }
231 
232 MlirType mlirComplexTypeGetElementType(MlirType type) {
233  return wrap(llvm::cast<ComplexType>(unwrap(type)).getElementType());
234 }
235 
236 //===----------------------------------------------------------------------===//
237 // Shaped type.
238 //===----------------------------------------------------------------------===//
239 
240 bool mlirTypeIsAShaped(MlirType type) {
241  return llvm::isa<ShapedType>(unwrap(type));
242 }
243 
244 MlirType mlirShapedTypeGetElementType(MlirType type) {
245  return wrap(llvm::cast<ShapedType>(unwrap(type)).getElementType());
246 }
247 
248 bool mlirShapedTypeHasRank(MlirType type) {
249  return llvm::cast<ShapedType>(unwrap(type)).hasRank();
250 }
251 
252 int64_t mlirShapedTypeGetRank(MlirType type) {
253  return llvm::cast<ShapedType>(unwrap(type)).getRank();
254 }
255 
256 bool mlirShapedTypeHasStaticShape(MlirType type) {
257  return llvm::cast<ShapedType>(unwrap(type)).hasStaticShape();
258 }
259 
260 bool mlirShapedTypeIsDynamicDim(MlirType type, intptr_t dim) {
261  return llvm::cast<ShapedType>(unwrap(type))
262  .isDynamicDim(static_cast<unsigned>(dim));
263 }
264 
265 int64_t mlirShapedTypeGetDimSize(MlirType type, intptr_t dim) {
266  return llvm::cast<ShapedType>(unwrap(type))
267  .getDimSize(static_cast<unsigned>(dim));
268 }
269 
270 int64_t mlirShapedTypeGetDynamicSize() { return ShapedType::kDynamic; }
271 
272 bool mlirShapedTypeIsDynamicSize(int64_t size) {
273  return ShapedType::isDynamic(size);
274 }
275 
277  return ShapedType::isDynamic(val);
278 }
279 
281  return ShapedType::kDynamic;
282 }
283 
284 //===----------------------------------------------------------------------===//
285 // Vector type.
286 //===----------------------------------------------------------------------===//
287 
288 MlirTypeID mlirVectorTypeGetTypeID() { return wrap(VectorType::getTypeID()); }
289 
290 bool mlirTypeIsAVector(MlirType type) {
291  return llvm::isa<VectorType>(unwrap(type));
292 }
293 
294 MlirType mlirVectorTypeGet(intptr_t rank, const int64_t *shape,
295  MlirType elementType) {
296  return wrap(VectorType::get(llvm::ArrayRef(shape, static_cast<size_t>(rank)),
297  unwrap(elementType)));
298 }
299 
300 MlirType mlirVectorTypeGetChecked(MlirLocation loc, intptr_t rank,
301  const int64_t *shape, MlirType elementType) {
302  return wrap(VectorType::getChecked(
303  unwrap(loc), llvm::ArrayRef(shape, static_cast<size_t>(rank)),
304  unwrap(elementType)));
305 }
306 
307 MlirType mlirVectorTypeGetScalable(intptr_t rank, const int64_t *shape,
308  const bool *scalable, MlirType elementType) {
309  return wrap(VectorType::get(
310  llvm::ArrayRef(shape, static_cast<size_t>(rank)), unwrap(elementType),
311  llvm::ArrayRef(scalable, static_cast<size_t>(rank))));
312 }
313 
314 MlirType mlirVectorTypeGetScalableChecked(MlirLocation loc, intptr_t rank,
315  const int64_t *shape,
316  const bool *scalable,
317  MlirType elementType) {
318  return wrap(VectorType::getChecked(
319  unwrap(loc), llvm::ArrayRef(shape, static_cast<size_t>(rank)),
320  unwrap(elementType),
321  llvm::ArrayRef(scalable, static_cast<size_t>(rank))));
322 }
323 
324 bool mlirVectorTypeIsScalable(MlirType type) {
325  return cast<VectorType>(unwrap(type)).isScalable();
326 }
327 
328 bool mlirVectorTypeIsDimScalable(MlirType type, intptr_t dim) {
329  return cast<VectorType>(unwrap(type)).getScalableDims()[dim];
330 }
331 
332 //===----------------------------------------------------------------------===//
333 // Ranked / Unranked tensor type.
334 //===----------------------------------------------------------------------===//
335 
336 bool mlirTypeIsATensor(MlirType type) {
337  return llvm::isa<TensorType>(unwrap(type));
338 }
339 
341  return wrap(RankedTensorType::getTypeID());
342 }
343 
344 bool mlirTypeIsARankedTensor(MlirType type) {
345  return llvm::isa<RankedTensorType>(unwrap(type));
346 }
347 
349  return wrap(UnrankedTensorType::getTypeID());
350 }
351 
352 bool mlirTypeIsAUnrankedTensor(MlirType type) {
353  return llvm::isa<UnrankedTensorType>(unwrap(type));
354 }
355 
356 MlirType mlirRankedTensorTypeGet(intptr_t rank, const int64_t *shape,
357  MlirType elementType, MlirAttribute encoding) {
358  return wrap(
359  RankedTensorType::get(llvm::ArrayRef(shape, static_cast<size_t>(rank)),
360  unwrap(elementType), unwrap(encoding)));
361 }
362 
363 MlirType mlirRankedTensorTypeGetChecked(MlirLocation loc, intptr_t rank,
364  const int64_t *shape,
365  MlirType elementType,
366  MlirAttribute encoding) {
367  return wrap(RankedTensorType::getChecked(
368  unwrap(loc), llvm::ArrayRef(shape, static_cast<size_t>(rank)),
369  unwrap(elementType), unwrap(encoding)));
370 }
371 
372 MlirAttribute mlirRankedTensorTypeGetEncoding(MlirType type) {
373  return wrap(llvm::cast<RankedTensorType>(unwrap(type)).getEncoding());
374 }
375 
376 MlirType mlirUnrankedTensorTypeGet(MlirType elementType) {
377  return wrap(UnrankedTensorType::get(unwrap(elementType)));
378 }
379 
380 MlirType mlirUnrankedTensorTypeGetChecked(MlirLocation loc,
381  MlirType elementType) {
382  return wrap(UnrankedTensorType::getChecked(unwrap(loc), unwrap(elementType)));
383 }
384 
385 MlirType mlirUnrankedTensorTypeGetElementType(MlirType type) {
386  return wrap(llvm::cast<UnrankedTensorType>(unwrap(type)).getElementType());
387 }
388 
389 //===----------------------------------------------------------------------===//
390 // Ranked / Unranked MemRef type.
391 //===----------------------------------------------------------------------===//
392 
393 MlirTypeID mlirMemRefTypeGetTypeID() { return wrap(MemRefType::getTypeID()); }
394 
395 bool mlirTypeIsAMemRef(MlirType type) {
396  return llvm::isa<MemRefType>(unwrap(type));
397 }
398 
399 MlirType mlirMemRefTypeGet(MlirType elementType, intptr_t rank,
400  const int64_t *shape, MlirAttribute layout,
401  MlirAttribute memorySpace) {
402  return wrap(MemRefType::get(
403  llvm::ArrayRef(shape, static_cast<size_t>(rank)), unwrap(elementType),
404  mlirAttributeIsNull(layout)
405  ? MemRefLayoutAttrInterface()
406  : llvm::cast<MemRefLayoutAttrInterface>(unwrap(layout)),
407  unwrap(memorySpace)));
408 }
409 
410 MlirType mlirMemRefTypeGetChecked(MlirLocation loc, MlirType elementType,
411  intptr_t rank, const int64_t *shape,
412  MlirAttribute layout,
413  MlirAttribute memorySpace) {
414  return wrap(MemRefType::getChecked(
415  unwrap(loc), llvm::ArrayRef(shape, static_cast<size_t>(rank)),
416  unwrap(elementType),
417  mlirAttributeIsNull(layout)
418  ? MemRefLayoutAttrInterface()
419  : llvm::cast<MemRefLayoutAttrInterface>(unwrap(layout)),
420  unwrap(memorySpace)));
421 }
422 
423 MlirType mlirMemRefTypeContiguousGet(MlirType elementType, intptr_t rank,
424  const int64_t *shape,
425  MlirAttribute memorySpace) {
426  return wrap(MemRefType::get(llvm::ArrayRef(shape, static_cast<size_t>(rank)),
427  unwrap(elementType), MemRefLayoutAttrInterface(),
428  unwrap(memorySpace)));
429 }
430 
431 MlirType mlirMemRefTypeContiguousGetChecked(MlirLocation loc,
432  MlirType elementType, intptr_t rank,
433  const int64_t *shape,
434  MlirAttribute memorySpace) {
435  return wrap(MemRefType::getChecked(
436  unwrap(loc), llvm::ArrayRef(shape, static_cast<size_t>(rank)),
437  unwrap(elementType), MemRefLayoutAttrInterface(), unwrap(memorySpace)));
438 }
439 
440 MlirAttribute mlirMemRefTypeGetLayout(MlirType type) {
441  return wrap(llvm::cast<MemRefType>(unwrap(type)).getLayout());
442 }
443 
444 MlirAffineMap mlirMemRefTypeGetAffineMap(MlirType type) {
445  return wrap(llvm::cast<MemRefType>(unwrap(type)).getLayout().getAffineMap());
446 }
447 
448 MlirAttribute mlirMemRefTypeGetMemorySpace(MlirType type) {
449  return wrap(llvm::cast<MemRefType>(unwrap(type)).getMemorySpace());
450 }
451 
453  int64_t *strides,
454  int64_t *offset) {
455  MemRefType memrefType = llvm::cast<MemRefType>(unwrap(type));
456  SmallVector<int64_t> strides_;
457  if (failed(getStridesAndOffset(memrefType, strides_, *offset)))
458  return mlirLogicalResultFailure();
459 
460  (void)std::copy(strides_.begin(), strides_.end(), strides);
461  return mlirLogicalResultSuccess();
462 }
463 
465  return wrap(UnrankedMemRefType::getTypeID());
466 }
467 
468 bool mlirTypeIsAUnrankedMemRef(MlirType type) {
469  return llvm::isa<UnrankedMemRefType>(unwrap(type));
470 }
471 
472 MlirType mlirUnrankedMemRefTypeGet(MlirType elementType,
473  MlirAttribute memorySpace) {
474  return wrap(
475  UnrankedMemRefType::get(unwrap(elementType), unwrap(memorySpace)));
476 }
477 
478 MlirType mlirUnrankedMemRefTypeGetChecked(MlirLocation loc,
479  MlirType elementType,
480  MlirAttribute memorySpace) {
481  return wrap(UnrankedMemRefType::getChecked(unwrap(loc), unwrap(elementType),
482  unwrap(memorySpace)));
483 }
484 
485 MlirAttribute mlirUnrankedMemrefGetMemorySpace(MlirType type) {
486  return wrap(llvm::cast<UnrankedMemRefType>(unwrap(type)).getMemorySpace());
487 }
488 
489 //===----------------------------------------------------------------------===//
490 // Tuple type.
491 //===----------------------------------------------------------------------===//
492 
493 MlirTypeID mlirTupleTypeGetTypeID() { return wrap(TupleType::getTypeID()); }
494 
495 bool mlirTypeIsATuple(MlirType type) {
496  return llvm::isa<TupleType>(unwrap(type));
497 }
498 
499 MlirType mlirTupleTypeGet(MlirContext ctx, intptr_t numElements,
500  MlirType const *elements) {
501  SmallVector<Type, 4> types;
502  ArrayRef<Type> typeRef = unwrapList(numElements, elements, types);
503  return wrap(TupleType::get(unwrap(ctx), typeRef));
504 }
505 
506 intptr_t mlirTupleTypeGetNumTypes(MlirType type) {
507  return llvm::cast<TupleType>(unwrap(type)).size();
508 }
509 
510 MlirType mlirTupleTypeGetType(MlirType type, intptr_t pos) {
511  return wrap(
512  llvm::cast<TupleType>(unwrap(type)).getType(static_cast<size_t>(pos)));
513 }
514 
515 //===----------------------------------------------------------------------===//
516 // Function type.
517 //===----------------------------------------------------------------------===//
518 
520  return wrap(FunctionType::getTypeID());
521 }
522 
523 bool mlirTypeIsAFunction(MlirType type) {
524  return llvm::isa<FunctionType>(unwrap(type));
525 }
526 
527 MlirType mlirFunctionTypeGet(MlirContext ctx, intptr_t numInputs,
528  MlirType const *inputs, intptr_t numResults,
529  MlirType const *results) {
530  SmallVector<Type, 4> inputsList;
531  SmallVector<Type, 4> resultsList;
532  (void)unwrapList(numInputs, inputs, inputsList);
533  (void)unwrapList(numResults, results, resultsList);
534  return wrap(FunctionType::get(unwrap(ctx), inputsList, resultsList));
535 }
536 
537 intptr_t mlirFunctionTypeGetNumInputs(MlirType type) {
538  return llvm::cast<FunctionType>(unwrap(type)).getNumInputs();
539 }
540 
541 intptr_t mlirFunctionTypeGetNumResults(MlirType type) {
542  return llvm::cast<FunctionType>(unwrap(type)).getNumResults();
543 }
544 
545 MlirType mlirFunctionTypeGetInput(MlirType type, intptr_t pos) {
546  assert(pos >= 0 && "pos in array must be positive");
547  return wrap(llvm::cast<FunctionType>(unwrap(type))
548  .getInput(static_cast<unsigned>(pos)));
549 }
550 
551 MlirType mlirFunctionTypeGetResult(MlirType type, intptr_t pos) {
552  assert(pos >= 0 && "pos in array must be positive");
553  return wrap(llvm::cast<FunctionType>(unwrap(type))
554  .getResult(static_cast<unsigned>(pos)));
555 }
556 
557 //===----------------------------------------------------------------------===//
558 // Opaque type.
559 //===----------------------------------------------------------------------===//
560 
561 MlirTypeID mlirOpaqueTypeGetTypeID() { return wrap(OpaqueType::getTypeID()); }
562 
563 bool mlirTypeIsAOpaque(MlirType type) {
564  return llvm::isa<OpaqueType>(unwrap(type));
565 }
566 
567 MlirType mlirOpaqueTypeGet(MlirContext ctx, MlirStringRef dialectNamespace,
568  MlirStringRef typeData) {
569  return wrap(
570  OpaqueType::get(StringAttr::get(unwrap(ctx), unwrap(dialectNamespace)),
571  unwrap(typeData)));
572 }
573 
575  return wrap(
576  llvm::cast<OpaqueType>(unwrap(type)).getDialectNamespace().strref());
577 }
578 
580  return wrap(llvm::cast<OpaqueType>(unwrap(type)).getTypeData());
581 }
bool mlirTypeIsAF16(MlirType type)
Checks whether the given type is an f16 type.
bool mlirTypeIsAF64(MlirType type)
Checks whether the given type is an f64 type.
bool mlirTypeIsAFloat8E4M3FNUZ(MlirType type)
Checks whether the given type is an f8E4M3FNUZ type.
bool mlirIntegerTypeIsUnsigned(MlirType type)
Checks whether the given integer type is unsigned.
MlirType mlirF32TypeGet(MlirContext ctx)
Creates an f32 type in the given context.
MlirTypeID mlirIntegerTypeGetTypeID()
Returns the typeID of an Integer type.
MlirLogicalResult mlirMemRefTypeGetStridesAndOffset(MlirType type, int64_t *strides, int64_t *offset)
Returns the strides of the MemRef if the layout map is in strided form.
MlirType mlirVectorTypeGetChecked(MlirLocation loc, intptr_t rank, const int64_t *shape, MlirType elementType)
Same as "mlirVectorTypeGet" but returns a nullptr wrapping MlirType on illegal arguments,...
MlirTypeID mlirBFloat16TypeGetTypeID()
Returns the typeID of an BFloat16 type.
MlirType mlirIntegerTypeGet(MlirContext ctx, unsigned bitwidth)
Creates a signless integer type of the given bitwidth in the context.
intptr_t mlirFunctionTypeGetNumResults(MlirType type)
Returns the number of result types.
unsigned mlirIntegerTypeGetWidth(MlirType type)
Returns the bitwidth of an integer type.
bool mlirTypeIsAUnrankedTensor(MlirType type)
Checks whether the given type is an unranked tensor type.
int64_t mlirShapedTypeGetDynamicStrideOrOffset()
Returns the value indicating a dynamic stride or offset in a shaped type.
MlirType mlirF64TypeGet(MlirContext ctx)
Creates a f64 type in the given context.
MlirAttribute mlirUnrankedMemrefGetMemorySpace(MlirType type)
Returns the memory spcae of the given Unranked MemRef type.
bool mlirTypeIsAFloat8E4M3B11FNUZ(MlirType type)
Checks whether the given type is an f8E4M3B11FNUZ type.
bool mlirTypeIsAFloat8E5M2(MlirType type)
Checks whether the given type is an f8E5M2 type.
MlirTypeID mlirFloatTF32TypeGetTypeID()
Returns the typeID of a TF32 type.
MlirType mlirIntegerTypeSignedGet(MlirContext ctx, unsigned bitwidth)
Creates a signed integer type of the given bitwidth in the context.
MlirTypeID mlirComplexTypeGetTypeID()
Returns the typeID of an Complex type.
int64_t mlirShapedTypeGetDimSize(MlirType type, intptr_t dim)
Returns the dim-th dimension of the given ranked shaped type.
MlirType mlirMemRefTypeGetChecked(MlirLocation loc, MlirType elementType, intptr_t rank, const int64_t *shape, MlirAttribute layout, MlirAttribute memorySpace)
Same as "mlirMemRefTypeGet" but returns a nullptr-wrapping MlirType o illegal arguments,...
MlirType mlirUnrankedTensorTypeGet(MlirType elementType)
Creates an unranked tensor type with the given element type in the same context as the element type.
MlirStringRef mlirOpaqueTypeGetData(MlirType type)
Returns the raw data as a string reference.
bool mlirTypeIsAF32(MlirType type)
Checks whether the given type is an f32 type.
MlirType mlirUnrankedTensorTypeGetElementType(MlirType type)
MlirTypeID mlirFloat8E4M3B11FNUZTypeGetTypeID()
Returns the typeID of an Float8E4M3B11FNUZ type.
MlirTypeID mlirFunctionTypeGetTypeID()
Returns the typeID of an Function type.
bool mlirTypeIsAFunction(MlirType type)
Checks whether the given type is a function type.
MlirAffineMap mlirMemRefTypeGetAffineMap(MlirType type)
Returns the affine map of the given MemRef type.
MlirTypeID mlirNoneTypeGetTypeID()
Returns the typeID of an None type.
MlirTypeID mlirUnrankedTensorTypeGetTypeID()
Returns the typeID of an UnrankedTensor type.
MlirTypeID mlirMemRefTypeGetTypeID()
Returns the typeID of an MemRef type.
MlirType mlirUnrankedMemRefTypeGetChecked(MlirLocation loc, MlirType elementType, MlirAttribute memorySpace)
Same as "mlirUnrankedMemRefTypeGet" but returns a nullptr wrapping MlirType on illegal arguments,...
bool mlirTypeIsAMemRef(MlirType type)
Checks whether the given type is a MemRef type.
MlirType mlirFunctionTypeGetResult(MlirType type, intptr_t pos)
Returns the pos-th result type.
MlirType mlirF16TypeGet(MlirContext ctx)
Creates an f16 type in the given context.
bool mlirTypeIsAComplex(MlirType type)
Checks whether the given type is a Complex type.
MlirType mlirNoneTypeGet(MlirContext ctx)
Creates a None type in the given context.
bool mlirTypeIsATF32(MlirType type)
Checks whether the given type is an TF32 type.
bool mlirShapedTypeHasRank(MlirType type)
Checks whether the given shaped type is ranked.
bool mlirTypeIsAShaped(MlirType type)
Checks whether the given type is a Shaped type.
MlirTypeID mlirIndexTypeGetTypeID()
Returns the typeID of an Index type.
MlirType mlirUnrankedTensorTypeGetChecked(MlirLocation loc, MlirType elementType)
Same as "mlirUnrankedTensorTypeGet" but returns a nullptr wrapping MlirType on illegal arguments,...
bool mlirIntegerTypeIsSignless(MlirType type)
Checks whether the given integer type is signless.
MlirType mlirRankedTensorTypeGet(intptr_t rank, const int64_t *shape, MlirType elementType, MlirAttribute encoding)
Creates a tensor type of a fixed rank with the given shape, element type, and optional encoding in th...
bool mlirShapedTypeIsDynamicDim(MlirType type, intptr_t dim)
Checks wither the dim-th dimension of the given shaped type is dynamic.
MlirType mlirFloat8E4M3B11FNUZTypeGet(MlirContext ctx)
Creates an f8E4M3B11FNUZ type in the given context.
bool mlirVectorTypeIsScalable(MlirType type)
Checks whether the given vector type is scalable, i.e., has at least one scalable dimension.
MlirType mlirFunctionTypeGet(MlirContext ctx, intptr_t numInputs, MlirType const *inputs, intptr_t numResults, MlirType const *results)
Creates a function type, mapping a list of input types to result types.
bool mlirTypeIsAUnrankedMemRef(MlirType type)
Checks whether the given type is an UnrankedMemRef type.
MlirTypeID mlirFloat8E4M3FNUZTypeGetTypeID()
Returns the typeID of an Float8E4M3FNUZ type.
MlirType mlirIntegerTypeUnsignedGet(MlirContext ctx, unsigned bitwidth)
Creates an unsigned integer type of the given bitwidth in the context.
MlirType mlirShapedTypeGetElementType(MlirType type)
Returns the element type of the shaped type.
int64_t mlirShapedTypeGetDynamicSize()
Returns the value indicating a dynamic size in a shaped type.
MlirTypeID mlirFloat8E4M3FNTypeGetTypeID()
Returns the typeID of an Float8E4M3FN type.
bool mlirTypeIsAVector(MlirType type)
Checks whether the given type is a Vector type.
MlirType mlirFloat8E4M3FNUZTypeGet(MlirContext ctx)
Creates an f8E4M3FNUZ type in the given context.
MlirAttribute mlirMemRefTypeGetLayout(MlirType type)
Returns the layout of the given MemRef type.
MlirTypeID mlirFloat64TypeGetTypeID()
Returns the typeID of an Float64 type.
MlirType mlirFloat8E5M2FNUZTypeGet(MlirContext ctx)
Creates an f8E5M2FNUZ type in the given context.
MlirType mlirVectorTypeGetScalableChecked(MlirLocation loc, intptr_t rank, const int64_t *shape, const bool *scalable, MlirType elementType)
Same as "mlirVectorTypeGetScalable" but returns a nullptr wrapping MlirType on illegal arguments,...
bool mlirShapedTypeIsDynamicStrideOrOffset(int64_t val)
Checks whether the given value is used as a placeholder for dynamic strides and offsets in shaped typ...
MlirType mlirMemRefTypeGet(MlirType elementType, intptr_t rank, const int64_t *shape, MlirAttribute layout, MlirAttribute memorySpace)
Creates a MemRef type with the given rank and shape, a potentially empty list of affine layout maps,...
bool mlirTypeIsABF16(MlirType type)
Checks whether the given type is a bf16 type.
intptr_t mlirTupleTypeGetNumTypes(MlirType type)
Returns the number of types contained in a tuple.
MlirType mlirFloat8E4M3TypeGet(MlirContext ctx)
Creates an f8E4M3 type in the given context.
bool mlirVectorTypeIsDimScalable(MlirType type, intptr_t dim)
Checks whether the "dim"-th dimension of the given vector is scalable.
MlirStringRef mlirOpaqueTypeGetDialectNamespace(MlirType type)
Returns the namespace of the dialect with which the given opaque type is associated.
bool mlirTypeIsAFloat(MlirType type)
Checks whether the given type is a floating-point type.
MlirType mlirFunctionTypeGetInput(MlirType type, intptr_t pos)
Returns the pos-th input type.
MlirType mlirMemRefTypeContiguousGetChecked(MlirLocation loc, MlirType elementType, intptr_t rank, const int64_t *shape, MlirAttribute memorySpace)
Same as "mlirMemRefTypeContiguousGet" but returns a nullptr wrapping MlirType on illegal arguments,...
bool mlirTypeIsAInteger(MlirType type)
Checks whether the given type is an integer type.
MlirTypeID mlirFloat8E4M3TypeGetTypeID()
Returns the typeID of an Float8E4M3 type.
MlirAttribute mlirRankedTensorTypeGetEncoding(MlirType type)
Gets the 'encoding' attribute from the ranked tensor type, returning a null attribute if none.
MlirTypeID mlirFloat8E5M2FNUZTypeGetTypeID()
Returns the typeID of an Float8E5M2FNUZ type.
intptr_t mlirFunctionTypeGetNumInputs(MlirType type)
Returns the number of input types.
bool mlirTypeIsATuple(MlirType type)
Checks whether the given type is a tuple type.
MlirType mlirTupleTypeGet(MlirContext ctx, intptr_t numElements, MlirType const *elements)
Creates a tuple type that consists of the given list of elemental types.
MlirTypeID mlirTupleTypeGetTypeID()
Returns the typeID of an Tuple type.
MlirType mlirVectorTypeGetScalable(intptr_t rank, const int64_t *shape, const bool *scalable, MlirType elementType)
Creates a scalable vector type with the shape identified by its rank and dimensions.
MlirTypeID mlirFloat16TypeGetTypeID()
Returns the typeID of an Float16 type.
MlirType mlirComplexTypeGet(MlirType elementType)
Creates a complex type with the given element type in the same context as the element type.
MlirTypeID mlirFloat8E5M2TypeGetTypeID()
Returns the typeID of an Float8E5M2 type.
MlirTypeID mlirFloat32TypeGetTypeID()
Returns the typeID of an Float32 type.
bool mlirTypeIsAFloat8E4M3(MlirType type)
Checks whether the given type is an f8E4M3 type.
int64_t mlirShapedTypeGetRank(MlirType type)
Returns the rank of the given ranked shaped type.
bool mlirTypeIsAFloat8E4M3FN(MlirType type)
Checks whether the given type is an f8E4M3FN type.
bool mlirTypeIsAOpaque(MlirType type)
Checks whether the given type is an opaque type.
MlirType mlirTupleTypeGetType(MlirType type, intptr_t pos)
Returns the pos-th type in the tuple type.
bool mlirTypeIsATensor(MlirType type)
Checks whether the given type is a Tensor type.
bool mlirIntegerTypeIsSigned(MlirType type)
Checks whether the given integer type is signed.
bool mlirShapedTypeHasStaticShape(MlirType type)
Checks whether the given shaped type has a static shape.
MlirTypeID mlirRankedTensorTypeGetTypeID()
Returns the typeID of an RankedTensor type.
MlirType mlirBF16TypeGet(MlirContext ctx)
Creates a bf16 type in the given context.
MlirType mlirComplexTypeGetElementType(MlirType type)
Returns the element type of the given complex type.
bool mlirTypeIsAIndex(MlirType type)
Checks whether the given type is an index type.
bool mlirTypeIsAFloat8E5M2FNUZ(MlirType type)
Checks whether the given type is an f8E5M2FNUZ type.
MlirType mlirOpaqueTypeGet(MlirContext ctx, MlirStringRef dialectNamespace, MlirStringRef typeData)
Creates an opaque type in the given context associated with the dialect identified by its namespace.
MlirAttribute mlirMemRefTypeGetMemorySpace(MlirType type)
Returns the memory space of the given MemRef type.
MlirType mlirRankedTensorTypeGetChecked(MlirLocation loc, intptr_t rank, const int64_t *shape, MlirType elementType, MlirAttribute encoding)
Same as "mlirRankedTensorTypeGet" but returns a nullptr wrapping MlirType on illegal arguments,...
MlirType mlirVectorTypeGet(intptr_t rank, const int64_t *shape, MlirType elementType)
Creates a vector type of the shape identified by its rank and dimensions, with the given element type...
MlirType mlirMemRefTypeContiguousGet(MlirType elementType, intptr_t rank, const int64_t *shape, MlirAttribute memorySpace)
Creates a MemRef type with the given rank, shape, memory space and element type in the same context a...
MlirType mlirFloat8E4M3FNTypeGet(MlirContext ctx)
Creates an f8E4M3FN type in the given context.
MlirType mlirIndexTypeGet(MlirContext ctx)
Creates an index type in the given context.
MlirTypeID mlirVectorTypeGetTypeID()
Returns the typeID of an Vector type.
bool mlirTypeIsARankedTensor(MlirType type)
Checks whether the given type is a ranked tensor type.
MlirTypeID mlirOpaqueTypeGetTypeID()
Returns the typeID of an Opaque type.
MlirTypeID mlirUnrankedMemRefTypeGetTypeID()
Returns the typeID of an UnrankedMemRef type.
bool mlirShapedTypeIsDynamicSize(int64_t size)
Checks whether the given value is used as a placeholder for dynamic sizes in shaped types.
bool mlirTypeIsANone(MlirType type)
Checks whether the given type is a None type.
MlirType mlirTF32TypeGet(MlirContext ctx)
Creates a TF32 type in the given context.
MlirType mlirFloat8E5M2TypeGet(MlirContext ctx)
Creates an f8E5M2 type in the given context.
unsigned mlirFloatTypeGetWidth(MlirType type)
Returns the bitwidth of a floating-point type.
MlirType mlirUnrankedMemRefTypeGet(MlirType elementType, MlirAttribute memorySpace)
Creates an Unranked MemRef type with the given element type and in the given memory space.
static void copy(Location loc, Value dst, Value src, Value size, OpBuilder &builder)
Copies the given number of bytes from src to dst pointers.
static Type getElementType(Type type, ArrayRef< int32_t > indices, function_ref< InFlightDiagnostic(StringRef)> emitErrorFn)
Walks the given type hierarchy with the given indices, potentially down to component granularity,...
Definition: SPIRVOps.cpp:215
static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
Definition: Wrap.h:40
static FloatType getF64(MLIRContext *ctx)
Definition: BuiltinTypes.h:460
static FloatType getFloat8E5M2(MLIRContext *ctx)
Definition: BuiltinTypes.h:420
static FloatType getFloat8E4M3FN(MLIRContext *ctx)
Definition: BuiltinTypes.h:428
static FloatType getF16(MLIRContext *ctx)
Definition: BuiltinTypes.h:448
static FloatType getTF32(MLIRContext *ctx)
Definition: BuiltinTypes.h:452
static FloatType getBF16(MLIRContext *ctx)
Definition: BuiltinTypes.h:444
static FloatType getFloat8E4M3FNUZ(MLIRContext *ctx)
Definition: BuiltinTypes.h:436
static FloatType getFloat8E4M3B11FNUZ(MLIRContext *ctx)
Definition: BuiltinTypes.h:440
static FloatType getFloat8E5M2FNUZ(MLIRContext *ctx)
Definition: BuiltinTypes.h:432
static FloatType getFloat8E4M3(MLIRContext *ctx)
Definition: BuiltinTypes.h:424
static FloatType getF32(MLIRContext *ctx)
Definition: BuiltinTypes.h:456
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition: Diagnostics.h:19
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition: Diagnostics.h:24
static bool mlirAttributeIsNull(MlirAttribute attr)
Checks whether an attribute is null.
Definition: IR.h:1034
static MlirLogicalResult mlirLogicalResultFailure(void)
Creates a logical result representing a failure.
Definition: Support.h:138
static MlirLogicalResult mlirLogicalResultSuccess(void)
Creates a logical result representing a success.
Definition: Support.h:132
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
Definition: Utils.cpp:305
LogicalResult getStridesAndOffset(MemRefType t, SmallVectorImpl< int64_t > &strides, int64_t &offset)
Returns the strides of the MemRef if the layout map is in strided form.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
A logical result value, essentially a boolean with named states.
Definition: Support.h:116
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition: Support.h:73