MLIR  22.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(Float4E2M1FNType::getTypeID());
90 }
91 
92 bool mlirTypeIsAFloat4E2M1FN(MlirType type) {
93  return llvm::isa<Float4E2M1FNType>(unwrap(type));
94 }
95 
96 MlirType mlirFloat4E2M1FNTypeGet(MlirContext ctx) {
97  return wrap(Float4E2M1FNType::get(unwrap(ctx)));
98 }
99 
101  return wrap(Float6E2M3FNType::getTypeID());
102 }
103 
104 bool mlirTypeIsAFloat6E2M3FN(MlirType type) {
105  return llvm::isa<Float6E2M3FNType>(unwrap(type));
106 }
107 
108 MlirType mlirFloat6E2M3FNTypeGet(MlirContext ctx) {
109  return wrap(Float6E2M3FNType::get(unwrap(ctx)));
110 }
111 
113  return wrap(Float6E3M2FNType::getTypeID());
114 }
115 
116 bool mlirTypeIsAFloat6E3M2FN(MlirType type) {
117  return llvm::isa<Float6E3M2FNType>(unwrap(type));
118 }
119 
120 MlirType mlirFloat6E3M2FNTypeGet(MlirContext ctx) {
121  return wrap(Float6E3M2FNType::get(unwrap(ctx)));
122 }
123 
125  return wrap(Float8E5M2Type::getTypeID());
126 }
127 
128 bool mlirTypeIsAFloat8E5M2(MlirType type) {
129  return llvm::isa<Float8E5M2Type>(unwrap(type));
130 }
131 
132 MlirType mlirFloat8E5M2TypeGet(MlirContext ctx) {
133  return wrap(Float8E5M2Type::get(unwrap(ctx)));
134 }
135 
137  return wrap(Float8E4M3Type::getTypeID());
138 }
139 
140 bool mlirTypeIsAFloat8E4M3(MlirType type) {
141  return llvm::isa<Float8E4M3Type>(unwrap(type));
142 }
143 
144 MlirType mlirFloat8E4M3TypeGet(MlirContext ctx) {
145  return wrap(Float8E4M3Type::get(unwrap(ctx)));
146 }
147 
149  return wrap(Float8E4M3FNType::getTypeID());
150 }
151 
152 bool mlirTypeIsAFloat8E4M3FN(MlirType type) {
153  return llvm::isa<Float8E4M3FNType>(unwrap(type));
154 }
155 
156 MlirType mlirFloat8E4M3FNTypeGet(MlirContext ctx) {
157  return wrap(Float8E4M3FNType::get(unwrap(ctx)));
158 }
159 
161  return wrap(Float8E5M2FNUZType::getTypeID());
162 }
163 
164 bool mlirTypeIsAFloat8E5M2FNUZ(MlirType type) {
165  return llvm::isa<Float8E5M2FNUZType>(unwrap(type));
166 }
167 
168 MlirType mlirFloat8E5M2FNUZTypeGet(MlirContext ctx) {
169  return wrap(Float8E5M2FNUZType::get(unwrap(ctx)));
170 }
171 
173  return wrap(Float8E4M3FNUZType::getTypeID());
174 }
175 
176 bool mlirTypeIsAFloat8E4M3FNUZ(MlirType type) {
177  return llvm::isa<Float8E4M3FNUZType>(unwrap(type));
178 }
179 
180 MlirType mlirFloat8E4M3FNUZTypeGet(MlirContext ctx) {
181  return wrap(Float8E4M3FNUZType::get(unwrap(ctx)));
182 }
183 
185  return wrap(Float8E4M3B11FNUZType::getTypeID());
186 }
187 
188 bool mlirTypeIsAFloat8E4M3B11FNUZ(MlirType type) {
189  return llvm::isa<Float8E4M3B11FNUZType>(unwrap(type));
190 }
191 
192 MlirType mlirFloat8E4M3B11FNUZTypeGet(MlirContext ctx) {
193  return wrap(Float8E4M3B11FNUZType::get(unwrap(ctx)));
194 }
195 
197  return wrap(Float8E3M4Type::getTypeID());
198 }
199 
200 bool mlirTypeIsAFloat8E3M4(MlirType type) {
201  return llvm::isa<Float8E3M4Type>(unwrap(type));
202 }
203 
204 MlirType mlirFloat8E3M4TypeGet(MlirContext ctx) {
205  return wrap(Float8E3M4Type::get(unwrap(ctx)));
206 }
207 
209  return wrap(Float8E8M0FNUType::getTypeID());
210 }
211 
212 bool mlirTypeIsAFloat8E8M0FNU(MlirType type) {
213  return llvm::isa<Float8E8M0FNUType>(unwrap(type));
214 }
215 
216 MlirType mlirFloat8E8M0FNUTypeGet(MlirContext ctx) {
217  return wrap(Float8E8M0FNUType::get(unwrap(ctx)));
218 }
219 
221  return wrap(BFloat16Type::getTypeID());
222 }
223 
224 bool mlirTypeIsABF16(MlirType type) {
225  return llvm::isa<BFloat16Type>(unwrap(type));
226 }
227 
228 MlirType mlirBF16TypeGet(MlirContext ctx) {
229  return wrap(BFloat16Type::get(unwrap(ctx)));
230 }
231 
232 MlirTypeID mlirFloat16TypeGetTypeID() { return wrap(Float16Type::getTypeID()); }
233 
234 bool mlirTypeIsAF16(MlirType type) {
235  return llvm::isa<Float16Type>(unwrap(type));
236 }
237 
238 MlirType mlirF16TypeGet(MlirContext ctx) {
239  return wrap(Float16Type::get(unwrap(ctx)));
240 }
241 
243  return wrap(FloatTF32Type::getTypeID());
244 }
245 
246 bool mlirTypeIsATF32(MlirType type) {
247  return llvm::isa<FloatTF32Type>(unwrap(type));
248 }
249 
250 MlirType mlirTF32TypeGet(MlirContext ctx) {
251  return wrap(FloatTF32Type::get(unwrap(ctx)));
252 }
253 
254 MlirTypeID mlirFloat32TypeGetTypeID() { return wrap(Float32Type::getTypeID()); }
255 
256 bool mlirTypeIsAF32(MlirType type) {
257  return llvm::isa<Float32Type>(unwrap(type));
258 }
259 
260 MlirType mlirF32TypeGet(MlirContext ctx) {
261  return wrap(Float32Type::get(unwrap(ctx)));
262 }
263 
264 MlirTypeID mlirFloat64TypeGetTypeID() { return wrap(Float64Type::getTypeID()); }
265 
266 bool mlirTypeIsAF64(MlirType type) {
267  return llvm::isa<Float64Type>(unwrap(type));
268 }
269 
270 MlirType mlirF64TypeGet(MlirContext ctx) {
271  return wrap(Float64Type::get(unwrap(ctx)));
272 }
273 
274 //===----------------------------------------------------------------------===//
275 // None type.
276 //===----------------------------------------------------------------------===//
277 
278 MlirTypeID mlirNoneTypeGetTypeID() { return wrap(NoneType::getTypeID()); }
279 
280 bool mlirTypeIsANone(MlirType type) {
281  return llvm::isa<NoneType>(unwrap(type));
282 }
283 
284 MlirType mlirNoneTypeGet(MlirContext ctx) {
285  return wrap(NoneType::get(unwrap(ctx)));
286 }
287 
288 //===----------------------------------------------------------------------===//
289 // Complex type.
290 //===----------------------------------------------------------------------===//
291 
292 MlirTypeID mlirComplexTypeGetTypeID() { return wrap(ComplexType::getTypeID()); }
293 
294 bool mlirTypeIsAComplex(MlirType type) {
295  return llvm::isa<ComplexType>(unwrap(type));
296 }
297 
298 MlirType mlirComplexTypeGet(MlirType elementType) {
299  return wrap(ComplexType::get(unwrap(elementType)));
300 }
301 
302 MlirType mlirComplexTypeGetElementType(MlirType type) {
303  return wrap(llvm::cast<ComplexType>(unwrap(type)).getElementType());
304 }
305 
306 //===----------------------------------------------------------------------===//
307 // Shaped type.
308 //===----------------------------------------------------------------------===//
309 
310 bool mlirTypeIsAShaped(MlirType type) {
311  return llvm::isa<ShapedType>(unwrap(type));
312 }
313 
314 MlirType mlirShapedTypeGetElementType(MlirType type) {
315  return wrap(llvm::cast<ShapedType>(unwrap(type)).getElementType());
316 }
317 
318 bool mlirShapedTypeHasRank(MlirType type) {
319  return llvm::cast<ShapedType>(unwrap(type)).hasRank();
320 }
321 
322 int64_t mlirShapedTypeGetRank(MlirType type) {
323  return llvm::cast<ShapedType>(unwrap(type)).getRank();
324 }
325 
326 bool mlirShapedTypeHasStaticShape(MlirType type) {
327  return llvm::cast<ShapedType>(unwrap(type)).hasStaticShape();
328 }
329 
330 bool mlirShapedTypeIsDynamicDim(MlirType type, intptr_t dim) {
331  return llvm::cast<ShapedType>(unwrap(type))
332  .isDynamicDim(static_cast<unsigned>(dim));
333 }
334 
335 bool mlirShapedTypeIsStaticDim(MlirType type, intptr_t dim) {
336  return llvm::cast<ShapedType>(unwrap(type))
337  .isStaticDim(static_cast<unsigned>(dim));
338 }
339 
340 int64_t mlirShapedTypeGetDimSize(MlirType type, intptr_t dim) {
341  return llvm::cast<ShapedType>(unwrap(type))
342  .getDimSize(static_cast<unsigned>(dim));
343 }
344 
345 int64_t mlirShapedTypeGetDynamicSize() { return ShapedType::kDynamic; }
346 
347 bool mlirShapedTypeIsDynamicSize(int64_t size) {
348  return ShapedType::isDynamic(size);
349 }
350 
351 bool mlirShapedTypeIsStaticSize(int64_t size) {
352  return ShapedType::isStatic(size);
353 }
354 
356  return ShapedType::isDynamic(val);
357 }
358 
360  return ShapedType::isStatic(val);
361 }
362 
364  return ShapedType::kDynamic;
365 }
366 
367 //===----------------------------------------------------------------------===//
368 // Vector type.
369 //===----------------------------------------------------------------------===//
370 
371 MlirTypeID mlirVectorTypeGetTypeID() { return wrap(VectorType::getTypeID()); }
372 
373 bool mlirTypeIsAVector(MlirType type) {
374  return llvm::isa<VectorType>(unwrap(type));
375 }
376 
377 MlirType mlirVectorTypeGet(intptr_t rank, const int64_t *shape,
378  MlirType elementType) {
379  return wrap(VectorType::get(llvm::ArrayRef(shape, static_cast<size_t>(rank)),
380  unwrap(elementType)));
381 }
382 
383 MlirType mlirVectorTypeGetChecked(MlirLocation loc, intptr_t rank,
384  const int64_t *shape, MlirType elementType) {
385  return wrap(VectorType::getChecked(
386  unwrap(loc), llvm::ArrayRef(shape, static_cast<size_t>(rank)),
387  unwrap(elementType)));
388 }
389 
390 MlirType mlirVectorTypeGetScalable(intptr_t rank, const int64_t *shape,
391  const bool *scalable, MlirType elementType) {
392  return wrap(VectorType::get(
393  llvm::ArrayRef(shape, static_cast<size_t>(rank)), unwrap(elementType),
394  llvm::ArrayRef(scalable, static_cast<size_t>(rank))));
395 }
396 
397 MlirType mlirVectorTypeGetScalableChecked(MlirLocation loc, intptr_t rank,
398  const int64_t *shape,
399  const bool *scalable,
400  MlirType elementType) {
401  return wrap(VectorType::getChecked(
402  unwrap(loc), llvm::ArrayRef(shape, static_cast<size_t>(rank)),
403  unwrap(elementType),
404  llvm::ArrayRef(scalable, static_cast<size_t>(rank))));
405 }
406 
407 bool mlirVectorTypeIsScalable(MlirType type) {
408  return cast<VectorType>(unwrap(type)).isScalable();
409 }
410 
411 bool mlirVectorTypeIsDimScalable(MlirType type, intptr_t dim) {
412  return cast<VectorType>(unwrap(type)).getScalableDims()[dim];
413 }
414 
415 //===----------------------------------------------------------------------===//
416 // Ranked / Unranked tensor type.
417 //===----------------------------------------------------------------------===//
418 
419 bool mlirTypeIsATensor(MlirType type) {
420  return llvm::isa<TensorType>(unwrap(type));
421 }
422 
424  return wrap(RankedTensorType::getTypeID());
425 }
426 
427 bool mlirTypeIsARankedTensor(MlirType type) {
428  return llvm::isa<RankedTensorType>(unwrap(type));
429 }
430 
432  return wrap(UnrankedTensorType::getTypeID());
433 }
434 
435 bool mlirTypeIsAUnrankedTensor(MlirType type) {
436  return llvm::isa<UnrankedTensorType>(unwrap(type));
437 }
438 
439 MlirType mlirRankedTensorTypeGet(intptr_t rank, const int64_t *shape,
440  MlirType elementType, MlirAttribute encoding) {
441  return wrap(
442  RankedTensorType::get(llvm::ArrayRef(shape, static_cast<size_t>(rank)),
443  unwrap(elementType), unwrap(encoding)));
444 }
445 
446 MlirType mlirRankedTensorTypeGetChecked(MlirLocation loc, intptr_t rank,
447  const int64_t *shape,
448  MlirType elementType,
449  MlirAttribute encoding) {
450  return wrap(RankedTensorType::getChecked(
451  unwrap(loc), llvm::ArrayRef(shape, static_cast<size_t>(rank)),
452  unwrap(elementType), unwrap(encoding)));
453 }
454 
455 MlirAttribute mlirRankedTensorTypeGetEncoding(MlirType type) {
456  return wrap(llvm::cast<RankedTensorType>(unwrap(type)).getEncoding());
457 }
458 
459 MlirType mlirUnrankedTensorTypeGet(MlirType elementType) {
460  return wrap(UnrankedTensorType::get(unwrap(elementType)));
461 }
462 
463 MlirType mlirUnrankedTensorTypeGetChecked(MlirLocation loc,
464  MlirType elementType) {
465  return wrap(UnrankedTensorType::getChecked(unwrap(loc), unwrap(elementType)));
466 }
467 
468 //===----------------------------------------------------------------------===//
469 // Ranked / Unranked MemRef type.
470 //===----------------------------------------------------------------------===//
471 
472 MlirTypeID mlirMemRefTypeGetTypeID() { return wrap(MemRefType::getTypeID()); }
473 
474 bool mlirTypeIsAMemRef(MlirType type) {
475  return llvm::isa<MemRefType>(unwrap(type));
476 }
477 
478 MlirType mlirMemRefTypeGet(MlirType elementType, intptr_t rank,
479  const int64_t *shape, MlirAttribute layout,
480  MlirAttribute memorySpace) {
481  return wrap(MemRefType::get(
482  llvm::ArrayRef(shape, static_cast<size_t>(rank)), unwrap(elementType),
483  mlirAttributeIsNull(layout)
484  ? MemRefLayoutAttrInterface()
485  : llvm::cast<MemRefLayoutAttrInterface>(unwrap(layout)),
486  unwrap(memorySpace)));
487 }
488 
489 MlirType mlirMemRefTypeGetChecked(MlirLocation loc, MlirType elementType,
490  intptr_t rank, const int64_t *shape,
491  MlirAttribute layout,
492  MlirAttribute memorySpace) {
493  return wrap(MemRefType::getChecked(
494  unwrap(loc), llvm::ArrayRef(shape, static_cast<size_t>(rank)),
495  unwrap(elementType),
496  mlirAttributeIsNull(layout)
497  ? MemRefLayoutAttrInterface()
498  : llvm::cast<MemRefLayoutAttrInterface>(unwrap(layout)),
499  unwrap(memorySpace)));
500 }
501 
502 MlirType mlirMemRefTypeContiguousGet(MlirType elementType, intptr_t rank,
503  const int64_t *shape,
504  MlirAttribute memorySpace) {
505  return wrap(MemRefType::get(llvm::ArrayRef(shape, static_cast<size_t>(rank)),
506  unwrap(elementType), MemRefLayoutAttrInterface(),
507  unwrap(memorySpace)));
508 }
509 
510 MlirType mlirMemRefTypeContiguousGetChecked(MlirLocation loc,
511  MlirType elementType, intptr_t rank,
512  const int64_t *shape,
513  MlirAttribute memorySpace) {
514  return wrap(MemRefType::getChecked(
515  unwrap(loc), llvm::ArrayRef(shape, static_cast<size_t>(rank)),
516  unwrap(elementType), MemRefLayoutAttrInterface(), unwrap(memorySpace)));
517 }
518 
519 MlirAttribute mlirMemRefTypeGetLayout(MlirType type) {
520  return wrap(llvm::cast<MemRefType>(unwrap(type)).getLayout());
521 }
522 
523 MlirAffineMap mlirMemRefTypeGetAffineMap(MlirType type) {
524  return wrap(llvm::cast<MemRefType>(unwrap(type)).getLayout().getAffineMap());
525 }
526 
527 MlirAttribute mlirMemRefTypeGetMemorySpace(MlirType type) {
528  return wrap(llvm::cast<MemRefType>(unwrap(type)).getMemorySpace());
529 }
530 
532  int64_t *strides,
533  int64_t *offset) {
534  MemRefType memrefType = llvm::cast<MemRefType>(unwrap(type));
535  SmallVector<int64_t> strides_;
536  if (failed(memrefType.getStridesAndOffset(strides_, *offset)))
537  return mlirLogicalResultFailure();
538 
539  (void)std::copy(strides_.begin(), strides_.end(), strides);
540  return mlirLogicalResultSuccess();
541 }
542 
544  return wrap(UnrankedMemRefType::getTypeID());
545 }
546 
547 bool mlirTypeIsAUnrankedMemRef(MlirType type) {
548  return llvm::isa<UnrankedMemRefType>(unwrap(type));
549 }
550 
551 MlirType mlirUnrankedMemRefTypeGet(MlirType elementType,
552  MlirAttribute memorySpace) {
553  return wrap(
554  UnrankedMemRefType::get(unwrap(elementType), unwrap(memorySpace)));
555 }
556 
557 MlirType mlirUnrankedMemRefTypeGetChecked(MlirLocation loc,
558  MlirType elementType,
559  MlirAttribute memorySpace) {
560  return wrap(UnrankedMemRefType::getChecked(unwrap(loc), unwrap(elementType),
561  unwrap(memorySpace)));
562 }
563 
564 MlirAttribute mlirUnrankedMemrefGetMemorySpace(MlirType type) {
565  return wrap(llvm::cast<UnrankedMemRefType>(unwrap(type)).getMemorySpace());
566 }
567 
568 //===----------------------------------------------------------------------===//
569 // Tuple type.
570 //===----------------------------------------------------------------------===//
571 
572 MlirTypeID mlirTupleTypeGetTypeID() { return wrap(TupleType::getTypeID()); }
573 
574 bool mlirTypeIsATuple(MlirType type) {
575  return llvm::isa<TupleType>(unwrap(type));
576 }
577 
578 MlirType mlirTupleTypeGet(MlirContext ctx, intptr_t numElements,
579  MlirType const *elements) {
580  SmallVector<Type, 4> types;
581  ArrayRef<Type> typeRef = unwrapList(numElements, elements, types);
582  return wrap(TupleType::get(unwrap(ctx), typeRef));
583 }
584 
585 intptr_t mlirTupleTypeGetNumTypes(MlirType type) {
586  return llvm::cast<TupleType>(unwrap(type)).size();
587 }
588 
589 MlirType mlirTupleTypeGetType(MlirType type, intptr_t pos) {
590  return wrap(
591  llvm::cast<TupleType>(unwrap(type)).getType(static_cast<size_t>(pos)));
592 }
593 
594 //===----------------------------------------------------------------------===//
595 // Function type.
596 //===----------------------------------------------------------------------===//
597 
599  return wrap(FunctionType::getTypeID());
600 }
601 
602 bool mlirTypeIsAFunction(MlirType type) {
603  return llvm::isa<FunctionType>(unwrap(type));
604 }
605 
606 MlirType mlirFunctionTypeGet(MlirContext ctx, intptr_t numInputs,
607  MlirType const *inputs, intptr_t numResults,
608  MlirType const *results) {
609  SmallVector<Type, 4> inputsList;
610  SmallVector<Type, 4> resultsList;
611  (void)unwrapList(numInputs, inputs, inputsList);
612  (void)unwrapList(numResults, results, resultsList);
613  return wrap(FunctionType::get(unwrap(ctx), inputsList, resultsList));
614 }
615 
616 intptr_t mlirFunctionTypeGetNumInputs(MlirType type) {
617  return llvm::cast<FunctionType>(unwrap(type)).getNumInputs();
618 }
619 
620 intptr_t mlirFunctionTypeGetNumResults(MlirType type) {
621  return llvm::cast<FunctionType>(unwrap(type)).getNumResults();
622 }
623 
624 MlirType mlirFunctionTypeGetInput(MlirType type, intptr_t pos) {
625  assert(pos >= 0 && "pos in array must be positive");
626  return wrap(llvm::cast<FunctionType>(unwrap(type))
627  .getInput(static_cast<unsigned>(pos)));
628 }
629 
630 MlirType mlirFunctionTypeGetResult(MlirType type, intptr_t pos) {
631  assert(pos >= 0 && "pos in array must be positive");
632  return wrap(llvm::cast<FunctionType>(unwrap(type))
633  .getResult(static_cast<unsigned>(pos)));
634 }
635 
636 //===----------------------------------------------------------------------===//
637 // Opaque type.
638 //===----------------------------------------------------------------------===//
639 
640 MlirTypeID mlirOpaqueTypeGetTypeID() { return wrap(OpaqueType::getTypeID()); }
641 
642 bool mlirTypeIsAOpaque(MlirType type) {
643  return llvm::isa<OpaqueType>(unwrap(type));
644 }
645 
646 MlirType mlirOpaqueTypeGet(MlirContext ctx, MlirStringRef dialectNamespace,
647  MlirStringRef typeData) {
648  return wrap(
649  OpaqueType::get(StringAttr::get(unwrap(ctx), unwrap(dialectNamespace)),
650  unwrap(typeData)));
651 }
652 
654  return wrap(
655  llvm::cast<OpaqueType>(unwrap(type)).getDialectNamespace().strref());
656 }
657 
659  return wrap(llvm::cast<OpaqueType>(unwrap(type)).getTypeData());
660 }
bool mlirTypeIsAF16(MlirType type)
Checks whether the given type is an f16 type.
MlirTypeID mlirFloat6E2M3FNTypeGetTypeID()
Returns the typeID of an Float6E2M3FN 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.
MlirType mlirFloat8E8M0FNUTypeGet(MlirContext ctx)
Creates an f8E8M0FNU type in the given context.
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.
MlirType mlirFloat6E2M3FNTypeGet(MlirContext ctx)
Creates an f6E2M3FN type in the given 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.
MlirTypeID mlirFloat8E3M4TypeGetTypeID()
Returns the typeID of an Float8E3M4 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.
MlirType mlirFloat8E3M4TypeGet(MlirContext ctx)
Creates an f8E3M4 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...
MlirTypeID mlirFloat6E3M2FNTypeGetTypeID()
Returns the typeID of an Float6E3M2FN type.
bool mlirShapedTypeIsDynamicDim(MlirType type, intptr_t dim)
Checks whether 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 mlirTypeIsAFloat4E2M1FN(MlirType type)
Checks whether the given type is an f4E2M1FN type.
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 mlirShapedTypeIsStaticDim(MlirType type, intptr_t dim)
Checks whether the dim-th dimension of the given shaped type is static.
bool mlirTypeIsAInteger(MlirType type)
Checks whether the given type is an integer type.
MlirType mlirFloat6E3M2FNTypeGet(MlirContext ctx)
Creates an f6E3M2FN type in the given context.
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.
bool mlirTypeIsAFloat8E3M4(MlirType type)
Checks whether the given type is an f8E3M4 type.
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 mlirShapedTypeIsStaticSize(int64_t size)
Checks whether the given shaped type dimension value is statically-sized.
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.
bool mlirTypeIsAFloat8E8M0FNU(MlirType type)
Checks whether the given type is an f8E8M0FNU 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 mlirTypeIsAFloat6E3M2FN(MlirType type)
Checks whether the given type is an f6E3M2FN 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.
bool mlirShapedTypeIsStaticStrideOrOffset(int64_t val)
Checks whether the given dimension value of a stride or an offset is statically-sized.
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,...
MlirTypeID mlirFloat8E8M0FNUTypeGetTypeID()
Returns the typeID of an Float8E8M0FNU type.
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 mlirFloat4E2M1FNTypeGet(MlirContext ctx)
Creates an f4E2M1FN type in the given context.
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.
bool mlirTypeIsAFloat6E2M3FN(MlirType type)
Checks whether the given type is an f6E2M3FN type.
MlirType mlirFloat8E5M2TypeGet(MlirContext ctx)
Creates an f8E5M2 type in the given context.
MlirTypeID mlirFloat4E2M1FNTypeGetTypeID()
Returns the typeID of an Float4E2M1FN type.
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)
Determine the element type of type.
static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
Definition: Wrap.h:40
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:1170
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
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition: Remarks.h:491
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
Definition: Utils.cpp:304
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