MLIR 23.0.0git
IRTypes.cpp
Go to the documentation of this file.
1//===- IRTypes.cpp - Exports builtin and standard 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// clang-format off
13// clang-format on
14
15#include <optional>
16#include <vector>
17
19#include "mlir-c/BuiltinTypes.h"
20#include "mlir-c/Support.h"
22
23namespace nb = nanobind;
24using namespace mlir;
26
27namespace mlir {
28namespace python {
30
31int mlirTypeIsAIntegerOrFloat(MlirType type) {
32 return mlirTypeIsAInteger(type) || mlirTypeIsABF16(type) ||
33 mlirTypeIsAF16(type) || mlirTypeIsAF32(type) || mlirTypeIsAF64(type);
34}
35
37 nb::enum_<Signedness>(c, "Signedness")
38 .value("SIGNLESS", Signless)
39 .value("SIGNED", Signed)
40 .value("UNSIGNED", Unsigned)
41 .export_values();
42
43 c.def_static(
44 "get_signless",
45 [](unsigned width, DefaultingPyMlirContext context) {
46 MlirType t = mlirIntegerTypeGet(context->get(), width);
47 return PyIntegerType(context->getRef(), t);
48 },
49 nb::arg("width"), nb::arg("context") = nb::none(),
50 "Create a signless integer type");
51 c.def_static(
52 "get_signed",
53 [](unsigned width, DefaultingPyMlirContext context) {
54 MlirType t = mlirIntegerTypeSignedGet(context->get(), width);
55 return PyIntegerType(context->getRef(), t);
56 },
57 nb::arg("width"), nb::arg("context") = nb::none(),
58 "Create a signed integer type");
59 c.def_static(
60 "get_unsigned",
61 [](unsigned width, DefaultingPyMlirContext context) {
62 MlirType t = mlirIntegerTypeUnsignedGet(context->get(), width);
63 return PyIntegerType(context->getRef(), t);
64 },
65 nb::arg("width"), nb::arg("context") = nb::none(),
66 "Create an unsigned integer type");
67 c.def_static(
68 "get",
69 [](unsigned width, Signedness signedness,
71 MlirType t;
72 switch (signedness) {
73 case Signless:
74 t = mlirIntegerTypeGet(context->get(), width);
75 break;
76 case Signed:
77 t = mlirIntegerTypeSignedGet(context->get(), width);
78 break;
79 case Unsigned:
80 t = mlirIntegerTypeUnsignedGet(context->get(), width);
81 break;
82 }
83 return PyIntegerType(context->getRef(), t);
84 },
85 nb::arg("width"), nb::arg("signedness") = Signless,
86 nb::arg("context") = nb::none(), "Create an integer type");
87 c.def_prop_ro("signedness", [](PyIntegerType &self) -> Signedness {
89 return Signless;
91 return Signed;
92 return Unsigned;
93 });
94 c.def_prop_ro(
95 "width",
96 [](PyIntegerType &self) { return mlirIntegerTypeGetWidth(self); },
97 "Returns the width of the integer type");
98 c.def_prop_ro(
99 "is_signless",
100 [](PyIntegerType &self) -> bool {
101 return mlirIntegerTypeIsSignless(self);
102 },
103 "Returns whether this is a signless integer");
104 c.def_prop_ro(
105 "is_signed",
106 [](PyIntegerType &self) -> bool { return mlirIntegerTypeIsSigned(self); },
107 "Returns whether this is a signed integer");
108 c.def_prop_ro(
109 "is_unsigned",
110 [](PyIntegerType &self) -> bool {
111 return mlirIntegerTypeIsUnsigned(self);
112 },
113 "Returns whether this is an unsigned integer");
114}
115
117 c.def_static(
118 "get",
119 [](DefaultingPyMlirContext context) {
120 MlirType t = mlirIndexTypeGet(context->get());
121 return PyIndexType(context->getRef(), t);
122 },
123 nb::arg("context") = nb::none(), "Create a index type.");
124}
125
127 c.def_prop_ro(
128 "width", [](PyFloatType &self) { return mlirFloatTypeGetWidth(self); },
129 "Returns the width of the floating-point type");
130}
131
133 c.def_static(
134 "get",
135 [](DefaultingPyMlirContext context) {
136 MlirType t = mlirFloat4E2M1FNTypeGet(context->get());
137 return PyFloat4E2M1FNType(context->getRef(), t);
138 },
139 nb::arg("context") = nb::none(), "Create a float4_e2m1fn type.");
140}
141
143 c.def_static(
144 "get",
145 [](DefaultingPyMlirContext context) {
146 MlirType t = mlirFloat6E2M3FNTypeGet(context->get());
147 return PyFloat6E2M3FNType(context->getRef(), t);
148 },
149 nb::arg("context") = nb::none(), "Create a float6_e2m3fn type.");
150}
151
153 c.def_static(
154 "get",
155 [](DefaultingPyMlirContext context) {
156 MlirType t = mlirFloat6E3M2FNTypeGet(context->get());
157 return PyFloat6E3M2FNType(context->getRef(), t);
158 },
159 nb::arg("context") = nb::none(), "Create a float6_e3m2fn type.");
160}
161
163 c.def_static(
164 "get",
165 [](DefaultingPyMlirContext context) {
166 MlirType t = mlirFloat8E4M3FNTypeGet(context->get());
167 return PyFloat8E4M3FNType(context->getRef(), t);
168 },
169 nb::arg("context") = nb::none(), "Create a float8_e4m3fn type.");
170}
171
173 c.def_static(
174 "get",
175 [](DefaultingPyMlirContext context) {
176 MlirType t = mlirFloat8E5M2TypeGet(context->get());
177 return PyFloat8E5M2Type(context->getRef(), t);
178 },
179 nb::arg("context") = nb::none(), "Create a float8_e5m2 type.");
180}
181
183 c.def_static(
184 "get",
185 [](DefaultingPyMlirContext context) {
186 MlirType t = mlirFloat8E4M3TypeGet(context->get());
187 return PyFloat8E4M3Type(context->getRef(), t);
188 },
189 nb::arg("context") = nb::none(), "Create a float8_e4m3 type.");
190}
191
193 c.def_static(
194 "get",
195 [](DefaultingPyMlirContext context) {
196 MlirType t = mlirFloat8E4M3FNUZTypeGet(context->get());
197 return PyFloat8E4M3FNUZType(context->getRef(), t);
198 },
199 nb::arg("context") = nb::none(), "Create a float8_e4m3fnuz type.");
200}
201
203 c.def_static(
204 "get",
205 [](DefaultingPyMlirContext context) {
206 MlirType t = mlirFloat8E4M3B11FNUZTypeGet(context->get());
207 return PyFloat8E4M3B11FNUZType(context->getRef(), t);
208 },
209 nb::arg("context") = nb::none(), "Create a float8_e4m3b11fnuz type.");
210}
211
213 c.def_static(
214 "get",
215 [](DefaultingPyMlirContext context) {
216 MlirType t = mlirFloat8E5M2FNUZTypeGet(context->get());
217 return PyFloat8E5M2FNUZType(context->getRef(), t);
218 },
219 nb::arg("context") = nb::none(), "Create a float8_e5m2fnuz type.");
220}
221
223 c.def_static(
224 "get",
225 [](DefaultingPyMlirContext context) {
226 MlirType t = mlirFloat8E3M4TypeGet(context->get());
227 return PyFloat8E3M4Type(context->getRef(), t);
228 },
229 nb::arg("context") = nb::none(), "Create a float8_e3m4 type.");
230}
231
233 c.def_static(
234 "get",
235 [](DefaultingPyMlirContext context) {
236 MlirType t = mlirFloat8E8M0FNUTypeGet(context->get());
237 return PyFloat8E8M0FNUType(context->getRef(), t);
238 },
239 nb::arg("context") = nb::none(), "Create a float8_e8m0fnu type.");
240}
241
243 c.def_static(
244 "get",
245 [](DefaultingPyMlirContext context) {
246 MlirType t = mlirBF16TypeGet(context->get());
247 return PyBF16Type(context->getRef(), t);
248 },
249 nb::arg("context") = nb::none(), "Create a bf16 type.");
250}
251
253 c.def_static(
254 "get",
255 [](DefaultingPyMlirContext context) {
256 MlirType t = mlirF16TypeGet(context->get());
257 return PyF16Type(context->getRef(), t);
258 },
259 nb::arg("context") = nb::none(), "Create a f16 type.");
260}
261
263 c.def_static(
264 "get",
265 [](DefaultingPyMlirContext context) {
266 MlirType t = mlirTF32TypeGet(context->get());
267 return PyTF32Type(context->getRef(), t);
268 },
269 nb::arg("context") = nb::none(), "Create a tf32 type.");
270}
271
273 c.def_static(
274 "get",
275 [](DefaultingPyMlirContext context) {
276 MlirType t = mlirF32TypeGet(context->get());
277 return PyF32Type(context->getRef(), t);
278 },
279 nb::arg("context") = nb::none(), "Create a f32 type.");
280}
281
283 c.def_static(
284 "get",
285 [](DefaultingPyMlirContext context) {
286 MlirType t = mlirF64TypeGet(context->get());
287 return PyF64Type(context->getRef(), t);
288 },
289 nb::arg("context") = nb::none(), "Create a f64 type.");
290}
291
293 c.def_static(
294 "get",
295 [](DefaultingPyMlirContext context) {
296 MlirType t = mlirNoneTypeGet(context->get());
297 return PyNoneType(context->getRef(), t);
298 },
299 nb::arg("context") = nb::none(), "Create a none type.");
300}
301
303 c.def_static(
304 "get",
305 [](PyType &elementType) {
306 // The element must be a floating point or integer scalar type.
307 if (mlirTypeIsAIntegerOrFloat(elementType)) {
308 MlirType t = mlirComplexTypeGet(elementType);
309 return PyComplexType(elementType.getContext(), t);
310 }
311 throw nb::value_error(
313 "invalid '",
314 nb::cast<std::string>(nb::repr(nb::cast(elementType))),
315 "' and expected floating point or integer type.")
316 .c_str());
317 },
318 "Create a complex type");
319 c.def_prop_ro(
320 "element_type",
321 [](PyComplexType &self) -> nb::typed<nb::object, PyType> {
323 .maybeDownCast();
324 },
325 "Returns element type.");
326}
327
328// Shaped Type Interface - ShapedType
330 c.def_prop_ro(
331 "element_type",
332 [](PyShapedType &self) -> nb::typed<nb::object, PyType> {
334 .maybeDownCast();
335 },
336 "Returns the element type of the shaped type.");
337 c.def_prop_ro(
338 "has_rank",
339 [](PyShapedType &self) -> bool { return mlirShapedTypeHasRank(self); },
340 "Returns whether the given shaped type is ranked.");
341 c.def_prop_ro(
342 "rank",
343 [](PyShapedType &self) {
344 self.requireHasRank();
345 return mlirShapedTypeGetRank(self);
346 },
347 "Returns the rank of the given ranked shaped type.");
348 c.def_prop_ro(
349 "has_static_shape",
350 [](PyShapedType &self) -> bool {
351 return mlirShapedTypeHasStaticShape(self);
352 },
353 "Returns whether the given shaped type has a static shape.");
354 c.def(
355 "is_dynamic_dim",
356 [](PyShapedType &self, intptr_t dim) -> bool {
357 self.requireHasRank();
358 return mlirShapedTypeIsDynamicDim(self, dim);
359 },
360 nb::arg("dim"),
361 "Returns whether the dim-th dimension of the given shaped type is "
362 "dynamic.");
363 c.def(
364 "is_static_dim",
365 [](PyShapedType &self, intptr_t dim) -> bool {
366 self.requireHasRank();
367 return mlirShapedTypeIsStaticDim(self, dim);
368 },
369 nb::arg("dim"),
370 "Returns whether the dim-th dimension of the given shaped type is "
371 "static.");
372 c.def(
373 "get_dim_size",
374 [](PyShapedType &self, intptr_t dim) {
375 self.requireHasRank();
376 return mlirShapedTypeGetDimSize(self, dim);
377 },
378 nb::arg("dim"),
379 "Returns the dim-th dimension of the given ranked shaped type.");
380 c.def_static(
381 "is_dynamic_size",
382 [](int64_t size) -> bool { return mlirShapedTypeIsDynamicSize(size); },
383 nb::arg("dim_size"),
384 "Returns whether the given dimension size indicates a dynamic "
385 "dimension.");
386 c.def_static(
387 "is_static_size",
388 [](int64_t size) -> bool { return mlirShapedTypeIsStaticSize(size); },
389 nb::arg("dim_size"),
390 "Returns whether the given dimension size indicates a static "
391 "dimension.");
392 c.def(
393 "is_dynamic_stride_or_offset",
394 [](PyShapedType &self, int64_t val) -> bool {
395 self.requireHasRank();
397 },
398 nb::arg("dim_size"),
399 "Returns whether the given value is used as a placeholder for dynamic "
400 "strides and offsets in shaped types.");
401 c.def(
402 "is_static_stride_or_offset",
403 [](PyShapedType &self, int64_t val) -> bool {
404 self.requireHasRank();
406 },
407 nb::arg("dim_size"),
408 "Returns whether the given shaped type stride or offset value is "
409 "statically-sized.");
410 c.def_prop_ro(
411 "shape",
412 [](PyShapedType &self) {
413 self.requireHasRank();
414
415 std::vector<int64_t> shape;
416 int64_t rank = mlirShapedTypeGetRank(self);
417 shape.reserve(rank);
418 for (int64_t i = 0; i < rank; ++i)
419 shape.push_back(mlirShapedTypeGetDimSize(self, i));
420 return shape;
421 },
422 "Returns the shape of the ranked shaped type as a list of integers.");
423 c.def_static(
424 "get_dynamic_size", []() { return mlirShapedTypeGetDynamicSize(); },
425 "Returns the value used to indicate dynamic dimensions in shaped "
426 "types.");
427 c.def_static(
428 "get_dynamic_stride_or_offset",
430 "Returns the value used to indicate dynamic strides or offsets in "
431 "shaped types.");
432}
433
434void PyShapedType::requireHasRank() {
435 if (!mlirShapedTypeHasRank(*this)) {
436 throw nb::value_error(
437 "calling this method requires that the type has a rank.");
438 }
439}
440
442
444 c.def_static("get", &PyVectorType::getChecked, nb::arg("shape"),
445 nb::arg("element_type"), nb::kw_only(),
446 nb::arg("scalable") = nb::none(),
447 nb::arg("scalable_dims") = nb::none(),
448 nb::arg("loc") = nb::none(), "Create a vector type")
449 .def_static("get_unchecked", &PyVectorType::get, nb::arg("shape"),
450 nb::arg("element_type"), nb::kw_only(),
451 nb::arg("scalable") = nb::none(),
452 nb::arg("scalable_dims") = nb::none(),
453 nb::arg("context") = nb::none(), "Create a vector type")
454 .def_prop_ro("scalable",
455 [](PyType self) { return mlirVectorTypeIsScalable(self); })
456 .def_prop_ro("scalable_dims", [](PyType self) {
457 std::vector<bool> scalableDims;
458 size_t rank = static_cast<size_t>(mlirShapedTypeGetRank(self));
459 scalableDims.reserve(rank);
460 for (size_t i = 0; i < rank; ++i)
461 scalableDims.push_back(mlirVectorTypeIsDimScalable(self, i));
462 return scalableDims;
463 });
464}
465
467PyVectorType::getChecked(std::vector<int64_t> shape, PyType &elementType,
468 std::optional<nb::list> scalable,
469 std::optional<std::vector<int64_t>> scalableDims,
471 if (scalable && scalableDims) {
472 throw nb::value_error("'scalable' and 'scalable_dims' kwargs "
473 "are mutually exclusive.");
474 }
475
476 PyMlirContext::ErrorCapture errors(loc->getContext());
477 MlirType type;
478 if (scalable) {
479 if (scalable->size() != shape.size())
480 throw nb::value_error("Expected len(scalable) == len(shape).");
481
482 std::vector<char> scalableDimFlags;
483 scalableDimFlags.reserve(scalable->size());
484 for (const nb::handle &h : *scalable) {
485 scalableDimFlags.push_back(nb::cast<bool>(h) ? 1 : 0);
486 }
488 loc, shape.size(), shape.data(),
489 reinterpret_cast<const bool *>(scalableDimFlags.data()), elementType);
490 } else if (scalableDims) {
491 std::vector<char> scalableDimFlags(shape.size(), 0);
492 for (int64_t dim : *scalableDims) {
493 if (static_cast<size_t>(dim) >= scalableDimFlags.size() || dim < 0)
494 throw nb::value_error("Scalable dimension index out of bounds.");
495 scalableDimFlags[dim] = 1;
496 }
498 loc, shape.size(), shape.data(),
499 reinterpret_cast<const bool *>(scalableDimFlags.data()), elementType);
500 } else {
501 type =
502 mlirVectorTypeGetChecked(loc, shape.size(), shape.data(), elementType);
503 }
504 if (mlirTypeIsNull(type))
505 throw MLIRError("Invalid type", errors.take());
506 return PyVectorType(elementType.getContext(), type);
507}
508
509PyVectorType PyVectorType::get(std::vector<int64_t> shape, PyType &elementType,
510 std::optional<nb::list> scalable,
511 std::optional<std::vector<int64_t>> scalableDims,
512 DefaultingPyMlirContext context) {
513 if (scalable && scalableDims) {
514 throw nb::value_error("'scalable' and 'scalable_dims' kwargs "
515 "are mutually exclusive.");
516 }
517
518 PyMlirContext::ErrorCapture errors(context->getRef());
519 MlirType type;
520 if (scalable) {
521 if (scalable->size() != shape.size())
522 throw nb::value_error("Expected len(scalable) == len(shape).");
523
524 std::vector<char> scalableDimFlags;
525 scalableDimFlags.reserve(scalable->size());
526 for (const nb::handle &h : *scalable) {
527 scalableDimFlags.push_back(nb::cast<bool>(h) ? 1 : 0);
528 }
530 shape.size(), shape.data(),
531 reinterpret_cast<const bool *>(scalableDimFlags.data()), elementType);
532 } else if (scalableDims) {
533 std::vector<char> scalableDimFlags(shape.size(), 0);
534 for (int64_t dim : *scalableDims) {
535 if (static_cast<size_t>(dim) >= scalableDimFlags.size() || dim < 0)
536 throw nb::value_error("Scalable dimension index out of bounds.");
537 scalableDimFlags[dim] = 1;
538 }
540 shape.size(), shape.data(),
541 reinterpret_cast<const bool *>(scalableDimFlags.data()), elementType);
542 } else {
543 type = mlirVectorTypeGet(shape.size(), shape.data(), elementType);
544 }
545 if (mlirTypeIsNull(type))
546 throw MLIRError("Invalid type", errors.take());
547 return PyVectorType(elementType.getContext(), type);
548}
549
551 c.def_static(
552 "get",
553 [](std::vector<int64_t> shape, PyType &elementType,
554 std::optional<PyAttribute> &encodingAttr, DefaultingPyLocation loc) {
555 PyMlirContext::ErrorCapture errors(loc->getContext());
557 loc, shape.size(), shape.data(), elementType,
558 encodingAttr ? encodingAttr->get() : mlirAttributeGetNull());
559 if (mlirTypeIsNull(t))
560 throw MLIRError("Invalid type", errors.take());
561 return PyRankedTensorType(elementType.getContext(), t);
562 },
563 nb::arg("shape"), nb::arg("element_type"),
564 nb::arg("encoding") = nb::none(), nb::arg("loc") = nb::none(),
565 "Create a ranked tensor type");
566 c.def_static(
567 "get_unchecked",
568 [](std::vector<int64_t> shape, PyType &elementType,
569 std::optional<PyAttribute> &encodingAttr,
570 DefaultingPyMlirContext context) {
571 PyMlirContext::ErrorCapture errors(context->getRef());
572 MlirType t = mlirRankedTensorTypeGet(
573 shape.size(), shape.data(), elementType,
574 encodingAttr ? encodingAttr->get() : mlirAttributeGetNull());
575 if (mlirTypeIsNull(t))
576 throw MLIRError("Invalid type", errors.take());
577 return PyRankedTensorType(elementType.getContext(), t);
578 },
579 nb::arg("shape"), nb::arg("element_type"),
580 nb::arg("encoding") = nb::none(), nb::arg("context") = nb::none(),
581 "Create a ranked tensor type");
582 c.def_prop_ro(
583 "encoding",
584 [](PyRankedTensorType &self)
585 -> std::optional<nb::typed<nb::object, PyAttribute>> {
586 MlirAttribute encoding = mlirRankedTensorTypeGetEncoding(self.get());
587 if (mlirAttributeIsNull(encoding))
588 return std::nullopt;
589 return PyAttribute(self.getContext(), encoding).maybeDownCast();
590 });
591}
592
594 c.def_static(
595 "get",
596 [](PyType &elementType, DefaultingPyLocation loc) {
597 PyMlirContext::ErrorCapture errors(loc->getContext());
598 MlirType t = mlirUnrankedTensorTypeGetChecked(loc, elementType);
599 if (mlirTypeIsNull(t))
600 throw MLIRError("Invalid type", errors.take());
601 return PyUnrankedTensorType(elementType.getContext(), t);
602 },
603 nb::arg("element_type"), nb::arg("loc") = nb::none(),
604 "Create a unranked tensor type");
605 c.def_static(
606 "get_unchecked",
607 [](PyType &elementType, DefaultingPyMlirContext context) {
608 PyMlirContext::ErrorCapture errors(context->getRef());
609 MlirType t = mlirUnrankedTensorTypeGet(elementType);
610 if (mlirTypeIsNull(t))
611 throw MLIRError("Invalid type", errors.take());
612 return PyUnrankedTensorType(elementType.getContext(), t);
613 },
614 nb::arg("element_type"), nb::arg("context") = nb::none(),
615 "Create a unranked tensor type");
616}
617
619 c.def_static(
620 "get",
621 [](std::vector<int64_t> shape, PyType &elementType, PyAttribute *layout,
622 PyAttribute *memorySpace, DefaultingPyLocation loc) {
623 PyMlirContext::ErrorCapture errors(loc->getContext());
624 MlirAttribute layoutAttr = layout ? *layout : mlirAttributeGetNull();
625 MlirAttribute memSpaceAttr =
626 memorySpace ? *memorySpace : mlirAttributeGetNull();
627 MlirType t =
628 mlirMemRefTypeGetChecked(loc, elementType, shape.size(),
629 shape.data(), layoutAttr, memSpaceAttr);
630 if (mlirTypeIsNull(t))
631 throw MLIRError("Invalid type", errors.take());
632 return PyMemRefType(elementType.getContext(), t);
633 },
634 nb::arg("shape"), nb::arg("element_type"),
635 nb::arg("layout") = nb::none(), nb::arg("memory_space") = nb::none(),
636 nb::arg("loc") = nb::none(), "Create a memref type")
637 .def_static(
638 "get_unchecked",
639 [](std::vector<int64_t> shape, PyType &elementType,
640 PyAttribute *layout, PyAttribute *memorySpace,
641 DefaultingPyMlirContext context) {
642 PyMlirContext::ErrorCapture errors(context->getRef());
643 MlirAttribute layoutAttr =
644 layout ? *layout : mlirAttributeGetNull();
645 MlirAttribute memSpaceAttr =
646 memorySpace ? *memorySpace : mlirAttributeGetNull();
647 MlirType t =
648 mlirMemRefTypeGet(elementType, shape.size(), shape.data(),
649 layoutAttr, memSpaceAttr);
650 if (mlirTypeIsNull(t))
651 throw MLIRError("Invalid type", errors.take());
652 return PyMemRefType(elementType.getContext(), t);
653 },
654 nb::arg("shape"), nb::arg("element_type"),
655 nb::arg("layout") = nb::none(), nb::arg("memory_space") = nb::none(),
656 nb::arg("context") = nb::none(), "Create a memref type")
657 .def_prop_ro(
658 "layout",
659 [](PyMemRefType &self) -> nb::typed<nb::object, PyAttribute> {
661 .maybeDownCast();
662 },
663 "The layout of the MemRef type.")
664 .def(
665 "get_strides_and_offset",
666 [](PyMemRefType &self) -> std::pair<std::vector<int64_t>, int64_t> {
667 std::vector<int64_t> strides(mlirShapedTypeGetRank(self));
668 int64_t offset;
670 self, strides.data(), &offset)))
671 throw std::runtime_error(
672 "Failed to extract strides and offset from memref.");
673 return {strides, offset};
674 },
675 "The strides and offset of the MemRef type.")
676 .def_prop_ro(
677 "affine_map",
678 [](PyMemRefType &self) -> PyAffineMap {
679 MlirAffineMap map = mlirMemRefTypeGetAffineMap(self);
680 return PyAffineMap(self.getContext(), map);
681 },
682 "The layout of the MemRef type as an affine map.")
683 .def_prop_ro(
684 "memory_space",
685 [](PyMemRefType &self)
686 -> std::optional<nb::typed<nb::object, PyAttribute>> {
687 MlirAttribute a = mlirMemRefTypeGetMemorySpace(self);
688 if (mlirAttributeIsNull(a))
689 return std::nullopt;
690 return PyAttribute(self.getContext(), a).maybeDownCast();
691 },
692 "Returns the memory space of the given MemRef type.");
693}
694
696 c.def_static(
697 "get",
698 [](PyType &elementType, PyAttribute *memorySpace,
700 PyMlirContext::ErrorCapture errors(loc->getContext());
701 MlirAttribute memSpaceAttr = {};
702 if (memorySpace)
703 memSpaceAttr = *memorySpace;
704
705 MlirType t =
706 mlirUnrankedMemRefTypeGetChecked(loc, elementType, memSpaceAttr);
707 if (mlirTypeIsNull(t))
708 throw MLIRError("Invalid type", errors.take());
709 return PyUnrankedMemRefType(elementType.getContext(), t);
710 },
711 nb::arg("element_type"), nb::arg("memory_space").none(),
712 nb::arg("loc") = nb::none(), "Create a unranked memref type")
713 .def_static(
714 "get_unchecked",
715 [](PyType &elementType, PyAttribute *memorySpace,
716 DefaultingPyMlirContext context) {
717 PyMlirContext::ErrorCapture errors(context->getRef());
718 MlirAttribute memSpaceAttr = {};
719 if (memorySpace)
720 memSpaceAttr = *memorySpace;
721
722 MlirType t = mlirUnrankedMemRefTypeGet(elementType, memSpaceAttr);
723 if (mlirTypeIsNull(t))
724 throw MLIRError("Invalid type", errors.take());
725 return PyUnrankedMemRefType(elementType.getContext(), t);
726 },
727 nb::arg("element_type"), nb::arg("memory_space").none(),
728 nb::arg("context") = nb::none(), "Create a unranked memref type")
729 .def_prop_ro(
730 "memory_space",
731 [](PyUnrankedMemRefType &self)
732 -> std::optional<nb::typed<nb::object, PyAttribute>> {
733 MlirAttribute a = mlirUnrankedMemrefGetMemorySpace(self);
734 if (mlirAttributeIsNull(a))
735 return std::nullopt;
736 return PyAttribute(self.getContext(), a).maybeDownCast();
737 },
738 "Returns the memory space of the given Unranked MemRef type.");
739}
740
742 c.def_static(
743 "get_tuple",
744 [](const std::vector<PyType> &elements, DefaultingPyMlirContext context) {
745 std::vector<MlirType> mlirElements;
746 mlirElements.reserve(elements.size());
747 for (const auto &element : elements)
748 mlirElements.push_back(element.get());
749 MlirType t = mlirTupleTypeGet(context->get(), elements.size(),
750 mlirElements.data());
751 return PyTupleType(context->getRef(), t);
752 },
753 nb::arg("elements"), nb::arg("context") = nb::none(),
754 "Create a tuple type");
755 c.def(
756 "get_type",
757 [](PyTupleType &self, intptr_t pos) -> nb::typed<nb::object, PyType> {
758 return PyType(self.getContext(), mlirTupleTypeGetType(self, pos))
759 .maybeDownCast();
760 },
761 nb::arg("pos"), "Returns the pos-th type in the tuple type.");
762 c.def_prop_ro(
763 "num_types",
764 [](PyTupleType &self) -> intptr_t {
765 return mlirTupleTypeGetNumTypes(self);
766 },
767 "Returns the number of types contained in a tuple.");
768}
769
771 c.def_static(
772 "get",
773 [](std::vector<PyType> inputs, std::vector<PyType> results,
774 DefaultingPyMlirContext context) {
775 std::vector<MlirType> mlirInputs;
776 mlirInputs.reserve(inputs.size());
777 for (const auto &input : inputs)
778 mlirInputs.push_back(input.get());
779 std::vector<MlirType> mlirResults;
780 mlirResults.reserve(results.size());
781 for (const auto &result : results)
782 mlirResults.push_back(result.get());
783
784 MlirType t = mlirFunctionTypeGet(context->get(), inputs.size(),
785 mlirInputs.data(), results.size(),
786 mlirResults.data());
787 return PyFunctionType(context->getRef(), t);
788 },
789 nb::arg("inputs"), nb::arg("results"), nb::arg("context") = nb::none(),
790 "Gets a FunctionType from a list of input and result types");
791 c.def_prop_ro(
792 "inputs",
793 [](PyFunctionType &self) {
794 MlirType t = self;
795 nb::list types;
796 for (intptr_t i = 0, e = mlirFunctionTypeGetNumInputs(self); i < e;
797 ++i) {
798 types.append(mlirFunctionTypeGetInput(t, i));
799 }
800 return types;
801 },
802 "Returns the list of input types in the FunctionType.");
803 c.def_prop_ro(
804 "results",
805 [](PyFunctionType &self) {
806 nb::list types;
807 for (intptr_t i = 0, e = mlirFunctionTypeGetNumResults(self); i < e;
808 ++i) {
809 types.append(mlirFunctionTypeGetResult(self, i));
810 }
811 return types;
812 },
813 "Returns the list of result types in the FunctionType.");
814}
815
817 c.def_static(
818 "get",
819 [](const std::string &dialectNamespace, const std::string &typeData,
820 DefaultingPyMlirContext context) {
821 MlirType type =
822 mlirOpaqueTypeGet(context->get(), toMlirStringRef(dialectNamespace),
823 toMlirStringRef(typeData));
824 return PyOpaqueType(context->getRef(), type);
825 },
826 nb::arg("dialect_namespace"), nb::arg("buffer"),
827 nb::arg("context") = nb::none(),
828 "Create an unregistered (opaque) dialect type.");
829 c.def_prop_ro(
830 "dialect_namespace",
831 [](PyOpaqueType &self) {
833 return nb::str(stringRef.data, stringRef.length);
834 },
835 "Returns the dialect namespace for the Opaque type as a string.");
836 c.def_prop_ro(
837 "data",
838 [](PyOpaqueType &self) {
839 MlirStringRef stringRef = mlirOpaqueTypeGetData(self);
840 return nb::str(stringRef.data, stringRef.length);
841 },
842 "Returns the data for the Opaque type as a string.");
843}
844
845static MlirDynamicTypeDefinition
846getDynamicTypeDef(const std::string &fullTypeName,
847 DefaultingPyMlirContext context) {
848 size_t dotPos = fullTypeName.find('.');
849 if (dotPos == std::string::npos) {
850 throw nb::value_error("Expected full type name to be in the format "
851 "'<dialectName>.<typeName>'.");
852 }
853
854 std::string dialectName = fullTypeName.substr(0, dotPos);
855 std::string typeName = fullTypeName.substr(dotPos + 1);
856 PyDialects dialects(context->getRef());
857 MlirDialect dialect = dialects.getDialectForKey(dialectName, false);
859 throw nb::value_error(
860 ("Dialect '" + dialectName + "' is not an extensible dialect.")
861 .c_str());
862
863 MlirDynamicTypeDefinition typeDef = mlirExtensibleDialectLookupTypeDefinition(
864 dialect, toMlirStringRef(typeName));
865 if (typeDef.ptr == nullptr) {
866 throw nb::value_error(("Dialect '" + dialectName +
867 "' does not contain a type named '" + typeName +
868 "'.")
869 .c_str());
870 }
871
872 return typeDef;
873}
874
876 c.def_static(
877 "get",
878 [](const std::string &fullTypeName, const std::vector<PyAttribute> &attrs,
879 DefaultingPyMlirContext context) {
880 MlirDynamicTypeDefinition typeDef =
881 getDynamicTypeDef(fullTypeName, context);
882
883 std::vector<MlirAttribute> mlirAttrs;
884 mlirAttrs.reserve(attrs.size());
885 for (const auto &attr : attrs)
886 mlirAttrs.push_back(attr.get());
887 MlirType t =
888 mlirDynamicTypeGet(typeDef, mlirAttrs.data(), mlirAttrs.size());
889 return PyDynamicType(context->getRef(), t);
890 },
891 nb::arg("full_type_name"), nb::arg("attributes"),
892 nb::arg("context") = nb::none(), "Create a dynamic type.");
893 c.def_prop_ro(
894 "params",
895 [](PyDynamicType &self) {
896 size_t numParams = mlirDynamicTypeGetNumParams(self);
897 std::vector<PyAttribute> params;
898 params.reserve(numParams);
899 for (size_t i = 0; i < numParams; ++i)
900 params.emplace_back(self.getContext(),
901 mlirDynamicTypeGetParam(self, i));
902 return params;
903 },
904 "Returns the parameters of the dynamic type as a list of attributes.");
905 c.def_prop_ro("type_name", [](PyDynamicType &self) {
906 MlirDynamicTypeDefinition typeDef = mlirDynamicTypeGetTypeDef(self);
908 MlirDialect dialect = mlirDynamicTypeDefinitionGetDialect(typeDef);
909 MlirStringRef dialectNamespace = mlirDialectGetNamespace(dialect);
910 return std::string(dialectNamespace.data, dialectNamespace.length) + "." +
911 std::string(name.data, name.length);
912 });
913 c.def_static(
914 "lookup_typeid",
915 [](const std::string &fullTypeName, DefaultingPyMlirContext context) {
916 MlirDynamicTypeDefinition typeDef =
917 getDynamicTypeDef(fullTypeName, context);
919 },
920 nb::arg("full_type_name"), nb::arg("context") = nb::none(),
921 "Look up the TypeID for the given dynamic type name.");
922}
923
957} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
958} // namespace python
959} // namespace mlir
ReferrentTy * get() const
PyMlirContextRef & getContext()
Accesses the context reference.
Definition IRCore.h:297
Used in function arguments when None should resolve to the current context manager set instance.
Definition IRCore.h:524
Used in function arguments when None should resolve to the current context manager set instance.
Definition IRCore.h:278
Wrapper around the generic MlirAttribute.
Definition IRCore.h:1005
nanobind::typed< nanobind::object, PyAttribute > maybeDownCast()
Definition IRCore.cpp:1896
Floating Point Type subclass - BF16Type.
Definition IRTypes.h:216
Complex Type subclass - ComplexType.
Definition IRTypes.h:299
User-level object for accessing dialects with dotted syntax such as: ctx.dialect.std.
Definition IRCore.h:473
MlirDialect getDialectForKey(const std::string &key, bool attrError)
Definition IRCore.cpp:820
Floating Point Type subclass - F16Type.
Definition IRTypes.h:230
Floating Point Type subclass - F32Type.
Definition IRTypes.h:258
Floating Point Type subclass - F64Type.
Definition IRTypes.h:272
Floating Point Type subclass - Float4E2M1FNType.
Definition IRTypes.h:62
Floating Point Type subclass - Float6E2M3FNType.
Definition IRTypes.h:76
Floating Point Type subclass - Float6E3M2FNType.
Definition IRTypes.h:90
Floating Point Type subclass - Float8E3M4Type.
Definition IRTypes.h:188
Floating Point Type subclass - Float8E4M3B11FNUZ.
Definition IRTypes.h:160
Floating Point Type subclass - Float8E4M3FNType.
Definition IRTypes.h:104
Floating Point Type subclass - Float8E4M3FNUZ.
Definition IRTypes.h:146
Floating Point Type subclass - Float8E4M3Type.
Definition IRTypes.h:132
Floating Point Type subclass - Float8E5M2FNUZ.
Definition IRTypes.h:174
Floating Point Type subclass - Float8E5M2Type.
Definition IRTypes.h:118
Floating Point Type subclass - Float8E8M0FNUType.
Definition IRTypes.h:202
Ranked MemRef Type subclass - MemRefType.
Definition IRTypes.h:381
Ranked Tensor Type subclass - RankedTensorType.
Definition IRTypes.h:353
Shaped Type Interface - ShapedType.
Definition IRTypes.h:313
Floating Point Type subclass - TF32Type.
Definition IRTypes.h:244
A TypeID provides an efficient and unique identifier for a specific C++ type.
Definition IRCore.h:900
Wrapper around the generic MlirType.
Definition IRCore.h:874
PyType(PyMlirContextRef contextRef, MlirType type)
Definition IRCore.h:876
Unranked MemRef Type subclass - UnrankedMemRefType.
Definition IRTypes.h:395
Unranked Tensor Type subclass - UnrankedTensorType.
Definition IRTypes.h:367
MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeGetNull(void)
Returns an empty attribute.
MLIR_CAPI_EXPORTED 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...
MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsSignless(MlirType type)
Checks whether the given integer type is signless.
MLIR_CAPI_EXPORTED MlirAttribute mlirRankedTensorTypeGetEncoding(MlirType type)
Gets the 'encoding' attribute from the ranked tensor type, returning a null attribute if none.
MLIR_CAPI_EXPORTED bool mlirTypeIsAInteger(MlirType type)
Checks whether the given type is an integer type.
MLIR_CAPI_EXPORTED MlirAffineMap mlirMemRefTypeGetAffineMap(MlirType type)
Returns the affine map of the given MemRef type.
MLIR_CAPI_EXPORTED unsigned mlirFloatTypeGetWidth(MlirType type)
Returns the bitwidth of a floating-point type.
MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetDimSize(MlirType type, intptr_t dim)
Returns the dim-th dimension of the given ranked shaped type.
MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeGet(MlirContext ctx, unsigned bitwidth)
Creates a signless integer type of the given bitwidth in the context.
MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueTypeGetData(MlirType type)
Returns the raw data as a string reference.
MLIR_CAPI_EXPORTED MlirType mlirFunctionTypeGetInput(MlirType type, intptr_t pos)
Returns the pos-th input type.
MLIR_CAPI_EXPORTED MlirType mlirIndexTypeGet(MlirContext ctx)
Creates an index type in the given context.
MLIR_CAPI_EXPORTED bool mlirShapedTypeIsStaticDim(MlirType type, intptr_t dim)
Checks whether the dim-th dimension of the given shaped type is static.
MLIR_CAPI_EXPORTED MlirType mlirFloat8E3M4TypeGet(MlirContext ctx)
Creates an f8E3M4 type in the given context.
MLIR_CAPI_EXPORTED bool mlirShapedTypeIsStaticStrideOrOffset(int64_t val)
Checks whether the given dimension value of a stride or an offset is statically-sized.
MLIR_CAPI_EXPORTED MlirType mlirFloat8E5M2FNUZTypeGet(MlirContext ctx)
Creates an f8E5M2FNUZ type in the given context.
MLIR_CAPI_EXPORTED MlirType mlirFloat8E8M0FNUTypeGet(MlirContext ctx)
Creates an f8E8M0FNU type in the given context.
MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsUnsigned(MlirType type)
Checks whether the given integer type is unsigned.
MLIR_CAPI_EXPORTED unsigned mlirIntegerTypeGetWidth(MlirType type)
Returns the bitwidth of an integer type.
MLIR_CAPI_EXPORTED MlirType mlirFloat8E5M2TypeGet(MlirContext ctx)
Creates an f8E5M2 type in the given context.
MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetRank(MlirType type)
Returns the rank of the given ranked shaped type.
MLIR_CAPI_EXPORTED MlirType mlirF64TypeGet(MlirContext ctx)
Creates a f64 type in the given context.
MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeSignedGet(MlirContext ctx, unsigned bitwidth)
Creates a signed integer type of the given bitwidth in the context.
MLIR_CAPI_EXPORTED MlirType mlirUnrankedTensorTypeGetChecked(MlirLocation loc, MlirType elementType)
Same as "mlirUnrankedTensorTypeGet" but returns a nullptr wrapping MlirType on illegal arguments,...
MLIR_CAPI_EXPORTED 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,...
MLIR_CAPI_EXPORTED MlirType mlirF16TypeGet(MlirContext ctx)
Creates an f16 type in the given context.
MLIR_CAPI_EXPORTED MlirAttribute mlirMemRefTypeGetMemorySpace(MlirType type)
Returns the memory space of the given MemRef type.
MLIR_CAPI_EXPORTED bool mlirTypeIsAF64(MlirType type)
Checks whether the given type is an f64 type.
MLIR_CAPI_EXPORTED MlirType mlirFloat6E2M3FNTypeGet(MlirContext ctx)
Creates an f6E2M3FN type in the given context.
MLIR_CAPI_EXPORTED bool mlirTypeIsAF16(MlirType type)
Checks whether the given type is an f16 type.
MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsSigned(MlirType type)
Checks whether the given integer type is signed.
MLIR_CAPI_EXPORTED 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,...
MLIR_CAPI_EXPORTED 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.
MLIR_CAPI_EXPORTED MlirType mlirShapedTypeGetElementType(MlirType type)
Returns the element type of the shaped type.
MLIR_CAPI_EXPORTED intptr_t mlirFunctionTypeGetNumInputs(MlirType type)
Returns the number of input types.
MLIR_CAPI_EXPORTED 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,...
MLIR_CAPI_EXPORTED MlirType mlirNoneTypeGet(MlirContext ctx)
Creates a None type in the given context.
MLIR_CAPI_EXPORTED MlirType mlirComplexTypeGet(MlirType elementType)
Creates a complex type with the given element type in the same context as the element type.
MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueTypeGetDialectNamespace(MlirType type)
Returns the namespace of the dialect with which the given opaque type is associated.
MLIR_CAPI_EXPORTED bool mlirShapedTypeHasStaticShape(MlirType type)
Checks whether the given shaped type has a static shape.
MLIR_CAPI_EXPORTED MlirType mlirFloat8E4M3TypeGet(MlirContext ctx)
Creates an f8E4M3 type in the given context.
MLIR_CAPI_EXPORTED MlirType mlirBF16TypeGet(MlirContext ctx)
Creates a bf16 type in the given context.
MLIR_CAPI_EXPORTED MlirType mlirF32TypeGet(MlirContext ctx)
Creates an f32 type in the given context.
MLIR_CAPI_EXPORTED bool mlirShapedTypeHasRank(MlirType type)
Checks whether the given shaped type is ranked.
MLIR_CAPI_EXPORTED MlirLogicalResult mlirMemRefTypeGetStridesAndOffset(MlirType type, int64_t *strides, int64_t *offset)
Returns the strides of the MemRef if the layout map is in strided form.
MLIR_CAPI_EXPORTED bool mlirTypeIsAShaped(MlirType type)
Checks whether the given type is a Shaped type.
MLIR_CAPI_EXPORTED intptr_t mlirTupleTypeGetNumTypes(MlirType type)
Returns the number of types contained in a tuple.
MLIR_CAPI_EXPORTED 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...
MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeUnsignedGet(MlirContext ctx, unsigned bitwidth)
Creates an unsigned integer type of the given bitwidth in the context.
MLIR_CAPI_EXPORTED MlirType mlirFloat8E4M3FNTypeGet(MlirContext ctx)
Creates an f8E4M3FN type in the given context.
MLIR_CAPI_EXPORTED bool mlirTypeIsAF32(MlirType type)
Checks whether the given type is an f32 type.
MLIR_CAPI_EXPORTED 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.
MLIR_CAPI_EXPORTED bool mlirShapedTypeIsDynamicStrideOrOffset(int64_t val)
Checks whether the given value is used as a placeholder for dynamic strides and offsets in shaped typ...
MLIR_CAPI_EXPORTED MlirType mlirTupleTypeGetType(MlirType type, intptr_t pos)
Returns the pos-th type in the tuple type.
MLIR_CAPI_EXPORTED bool mlirVectorTypeIsDimScalable(MlirType type, intptr_t dim)
Checks whether the "dim"-th dimension of the given vector is scalable.
MLIR_CAPI_EXPORTED bool mlirShapedTypeIsDynamicDim(MlirType type, intptr_t dim)
Checks whether the dim-th dimension of the given shaped type is dynamic.
MLIR_CAPI_EXPORTED MlirType mlirFloat6E3M2FNTypeGet(MlirContext ctx)
Creates an f6E3M2FN type in the given context.
MLIR_CAPI_EXPORTED MlirType mlirUnrankedMemRefTypeGet(MlirType elementType, MlirAttribute memorySpace)
Creates an Unranked MemRef type with the given element type and in the given memory space.
MLIR_CAPI_EXPORTED 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,...
MLIR_CAPI_EXPORTED bool mlirTypeIsABF16(MlirType type)
Checks whether the given type is a bf16 type.
MLIR_CAPI_EXPORTED MlirType mlirOpaqueTypeGet(MlirContext ctx, MlirStringRef dialectNamespace, MlirStringRef typeData)
Creates an opaque type in the given context associated with the dialect identified by its namespace.
MLIR_CAPI_EXPORTED intptr_t mlirFunctionTypeGetNumResults(MlirType type)
Returns the number of result types.
MLIR_CAPI_EXPORTED bool mlirShapedTypeIsDynamicSize(int64_t size)
Checks whether the given value is used as a placeholder for dynamic sizes in shaped types.
MLIR_CAPI_EXPORTED MlirType mlirUnrankedMemRefTypeGetChecked(MlirLocation loc, MlirType elementType, MlirAttribute memorySpace)
Same as "mlirUnrankedMemRefTypeGet" but returns a nullptr wrapping MlirType on illegal arguments,...
MLIR_CAPI_EXPORTED bool mlirShapedTypeIsStaticSize(int64_t size)
Checks whether the given shaped type dimension value is statically-sized.
MLIR_CAPI_EXPORTED 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,...
MLIR_CAPI_EXPORTED MlirType mlirUnrankedTensorTypeGet(MlirType elementType)
Creates an unranked tensor type with the given element type in the same context as the element type.
MLIR_CAPI_EXPORTED bool mlirVectorTypeIsScalable(MlirType type)
Checks whether the given vector type is scalable, i.e., has at least one scalable dimension.
MLIR_CAPI_EXPORTED MlirType mlirComplexTypeGetElementType(MlirType type)
Returns the element type of the given complex type.
MLIR_CAPI_EXPORTED MlirAttribute mlirUnrankedMemrefGetMemorySpace(MlirType type)
Returns the memory spcae of the given Unranked MemRef type.
MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetDynamicStrideOrOffset(void)
Returns the value indicating a dynamic stride or offset in a shaped type.
MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetDynamicSize(void)
Returns the value indicating a dynamic size in a shaped type.
MLIR_CAPI_EXPORTED MlirAttribute mlirMemRefTypeGetLayout(MlirType type)
Returns the layout of the given MemRef type.
MLIR_CAPI_EXPORTED MlirType mlirFloat8E4M3B11FNUZTypeGet(MlirContext ctx)
Creates an f8E4M3B11FNUZ type in the given context.
MLIR_CAPI_EXPORTED MlirType mlirTupleTypeGet(MlirContext ctx, intptr_t numElements, MlirType const *elements)
Creates a tuple type that consists of the given list of elemental types.
MLIR_CAPI_EXPORTED MlirType mlirFloat8E4M3FNUZTypeGet(MlirContext ctx)
Creates an f8E4M3FNUZ type in the given context.
MLIR_CAPI_EXPORTED MlirType mlirFunctionTypeGetResult(MlirType type, intptr_t pos)
Returns the pos-th result type.
MLIR_CAPI_EXPORTED MlirType mlirTF32TypeGet(MlirContext ctx)
Creates a TF32 type in the given context.
MLIR_CAPI_EXPORTED MlirType mlirFloat4E2M1FNTypeGet(MlirContext ctx)
Creates an f4E2M1FN type in the given context.
MLIR_CAPI_EXPORTED MlirDynamicTypeDefinition mlirDynamicTypeGetTypeDef(MlirType type)
Get the type definition of the given dynamic type.
MLIR_CAPI_EXPORTED bool mlirDialectIsAExtensibleDialect(MlirDialect dialect)
Check if the given dialect is an extensible dialect.
MLIR_CAPI_EXPORTED MlirDialect mlirDynamicTypeDefinitionGetDialect(MlirDynamicTypeDefinition typeDef)
Get the dialect that the given dynamic type definition belongs to.
MLIR_CAPI_EXPORTED intptr_t mlirDynamicTypeGetNumParams(MlirType type)
Get the number of parameters in the given dynamic type.
MLIR_CAPI_EXPORTED MlirType mlirDynamicTypeGet(MlirDynamicTypeDefinition typeDef, MlirAttribute *attrs, intptr_t numAttrs)
Get a dynamic type by instantiating the given type definition with the provided attributes.
MLIR_CAPI_EXPORTED MlirDynamicTypeDefinition mlirExtensibleDialectLookupTypeDefinition(MlirDialect dialect, MlirStringRef typeName)
Look up a registered type definition by type name in the given dialect.
MLIR_CAPI_EXPORTED MlirTypeID mlirDynamicTypeDefinitionGetTypeID(MlirDynamicTypeDefinition typeDef)
Get the type ID of a dynamic type definition.
MLIR_CAPI_EXPORTED MlirAttribute mlirDynamicTypeGetParam(MlirType type, intptr_t index)
Get the parameter at the given index in the provided dynamic type.
MLIR_CAPI_EXPORTED MlirStringRef mlirDynamicTypeDefinitionGetName(MlirDynamicTypeDefinition typeDef)
Get the name of the given dynamic type definition.
MLIR_CAPI_EXPORTED MlirStringRef mlirDialectGetNamespace(MlirDialect dialect)
Returns the namespace of the given dialect.
Definition IR.cpp:136
static bool mlirTypeIsNull(MlirType type)
Checks whether a type is null.
Definition IR.h:1160
static bool mlirLogicalResultIsFailure(MlirLogicalResult res)
Checks if the given logical result represents a failure.
Definition Support.h:132
MLIR_PYTHON_API_EXPORTED void populateIRTypes(nanobind::module_ &m)
MLIR_PYTHON_API_EXPORTED int mlirTypeIsAIntegerOrFloat(MlirType type)
Definition IRTypes.cpp:31
MlirStringRef toMlirStringRef(const std::string &s)
Definition IRCore.h:1338
static MlirDynamicTypeDefinition getDynamicTypeDef(const std::string &fullTypeName, DefaultingPyMlirContext context)
Definition IRTypes.cpp:846
Include the generated interface declarations.
std::string join(const Ts &...args)
Helper function to concatenate arguments into a std::string.
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:78
const char * data
Pointer to the first symbol.
Definition Support.h:79
size_t length
Length of the fragment.
Definition Support.h:80
Custom exception that allows access to error diagnostic information.
Definition IRCore.h:1325
RAII object that captures any error diagnostics emitted to the provided context.
Definition IRCore.h:433
std::vector< PyDiagnostic::DiagnosticInfo > take()
Definition IRCore.h:443