MLIR 24.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 = mlirFloat8E5M3FNUTypeGet(context->get());
247 return PyFloat8E5M3FNUType(context->getRef(), t);
248 },
249 nb::arg("context") = nb::none(), "Create a float8_e5m3fnu type.");
250}
251
253 c.def_static(
254 "get",
255 [](DefaultingPyMlirContext context) {
256 MlirType t = mlirBF16TypeGet(context->get());
257 return PyBF16Type(context->getRef(), t);
258 },
259 nb::arg("context") = nb::none(), "Create a bf16 type.");
260}
261
263 c.def_static(
264 "get",
265 [](DefaultingPyMlirContext context) {
266 MlirType t = mlirF16TypeGet(context->get());
267 return PyF16Type(context->getRef(), t);
268 },
269 nb::arg("context") = nb::none(), "Create a f16 type.");
270}
271
273 c.def_static(
274 "get",
275 [](DefaultingPyMlirContext context) {
276 MlirType t = mlirTF32TypeGet(context->get());
277 return PyTF32Type(context->getRef(), t);
278 },
279 nb::arg("context") = nb::none(), "Create a tf32 type.");
280}
281
283 c.def_static(
284 "get",
285 [](DefaultingPyMlirContext context) {
286 MlirType t = mlirF32TypeGet(context->get());
287 return PyF32Type(context->getRef(), t);
288 },
289 nb::arg("context") = nb::none(), "Create a f32 type.");
290}
291
293 c.def_static(
294 "get",
295 [](DefaultingPyMlirContext context) {
296 MlirType t = mlirF64TypeGet(context->get());
297 return PyF64Type(context->getRef(), t);
298 },
299 nb::arg("context") = nb::none(), "Create a f64 type.");
300}
301
303 c.def_static(
304 "get",
305 [](DefaultingPyMlirContext context) {
306 MlirType t = mlirNoneTypeGet(context->get());
307 return PyNoneType(context->getRef(), t);
308 },
309 nb::arg("context") = nb::none(), "Create a none type.");
310}
311
313 c.def_static(
314 "get",
315 [](PyType &elementType) {
316 // The element must be a floating point or integer scalar type.
317 if (mlirTypeIsAIntegerOrFloat(elementType)) {
318 MlirType t = mlirComplexTypeGet(elementType);
319 return PyComplexType(elementType.getContext(), t);
320 }
321 throw nb::value_error(
323 "invalid '",
324 nb::cast<std::string>(nb::repr(nb::cast(elementType))),
325 "' and expected floating point or integer type.")
326 .c_str());
327 },
328 "Create a complex type");
329 c.def_prop_ro(
330 "element_type",
331 [](PyComplexType &self) -> nb::typed<nb::object, PyType> {
333 .maybeDownCast();
334 },
335 "Returns element type.");
336}
337
338// Shaped Type Interface - ShapedType
340 c.def_prop_ro(
341 "element_type",
342 [](PyShapedType &self) -> nb::typed<nb::object, PyType> {
344 .maybeDownCast();
345 },
346 "Returns the element type of the shaped type.");
347 c.def_prop_ro(
348 "has_rank",
349 [](PyShapedType &self) -> bool { return mlirShapedTypeHasRank(self); },
350 "Returns whether the given shaped type is ranked.");
351 c.def_prop_ro(
352 "rank",
353 [](PyShapedType &self) {
354 self.requireHasRank();
355 return mlirShapedTypeGetRank(self);
356 },
357 "Returns the rank of the given ranked shaped type.");
358 c.def_prop_ro(
359 "has_static_shape",
360 [](PyShapedType &self) -> bool {
361 return mlirShapedTypeHasStaticShape(self);
362 },
363 "Returns whether the given shaped type has a static shape.");
364 c.def(
365 "is_dynamic_dim",
366 [](PyShapedType &self, intptr_t dim) -> bool {
367 self.requireHasRank();
368 return mlirShapedTypeIsDynamicDim(self, dim);
369 },
370 nb::arg("dim"),
371 "Returns whether the dim-th dimension of the given shaped type is "
372 "dynamic.");
373 c.def(
374 "is_static_dim",
375 [](PyShapedType &self, intptr_t dim) -> bool {
376 self.requireHasRank();
377 return mlirShapedTypeIsStaticDim(self, dim);
378 },
379 nb::arg("dim"),
380 "Returns whether the dim-th dimension of the given shaped type is "
381 "static.");
382 c.def(
383 "get_dim_size",
384 [](PyShapedType &self, intptr_t dim) {
385 self.requireHasRank();
386 return mlirShapedTypeGetDimSize(self, dim);
387 },
388 nb::arg("dim"),
389 "Returns the dim-th dimension of the given ranked shaped type.");
390 c.def_static(
391 "is_dynamic_size",
392 [](int64_t size) -> bool { return mlirShapedTypeIsDynamicSize(size); },
393 nb::arg("dim_size"),
394 "Returns whether the given dimension size indicates a dynamic "
395 "dimension.");
396 c.def_static(
397 "is_static_size",
398 [](int64_t size) -> bool { return mlirShapedTypeIsStaticSize(size); },
399 nb::arg("dim_size"),
400 "Returns whether the given dimension size indicates a static "
401 "dimension.");
402 c.def(
403 "is_dynamic_stride_or_offset",
404 [](PyShapedType &self, int64_t val) -> bool {
405 self.requireHasRank();
407 },
408 nb::arg("dim_size"),
409 "Returns whether the given value is used as a placeholder for dynamic "
410 "strides and offsets in shaped types.");
411 c.def(
412 "is_static_stride_or_offset",
413 [](PyShapedType &self, int64_t val) -> bool {
414 self.requireHasRank();
416 },
417 nb::arg("dim_size"),
418 "Returns whether the given shaped type stride or offset value is "
419 "statically-sized.");
420 c.def_prop_ro(
421 "shape",
422 [](PyShapedType &self) {
423 self.requireHasRank();
424
425 std::vector<int64_t> shape;
426 int64_t rank = mlirShapedTypeGetRank(self);
427 shape.reserve(rank);
428 for (int64_t i = 0; i < rank; ++i)
429 shape.push_back(mlirShapedTypeGetDimSize(self, i));
430 return shape;
431 },
432 "Returns the shape of the ranked shaped type as a list of integers.");
433 c.def_static(
434 "get_dynamic_size", []() { return mlirShapedTypeGetDynamicSize(); },
435 "Returns the value used to indicate dynamic dimensions in shaped "
436 "types.");
437 c.def_static(
438 "get_dynamic_stride_or_offset",
440 "Returns the value used to indicate dynamic strides or offsets in "
441 "shaped types.");
442}
443
444void PyShapedType::requireHasRank() {
445 if (!mlirShapedTypeHasRank(*this)) {
446 throw nb::value_error(
447 "calling this method requires that the type has a rank.");
448 }
449}
450
452
454 c.def_static("get", &PyVectorType::getChecked, nb::arg("shape"),
455 nb::arg("element_type"), nb::kw_only(),
456 nb::arg("scalable") = nb::none(),
457 nb::arg("scalable_dims") = nb::none(),
458 nb::arg("loc") = nb::none(), "Create a vector type")
459 .def_static("get_unchecked", &PyVectorType::get, nb::arg("shape"),
460 nb::arg("element_type"), nb::kw_only(),
461 nb::arg("scalable") = nb::none(),
462 nb::arg("scalable_dims") = nb::none(),
463 nb::arg("context") = nb::none(), "Create a vector type")
464 .def_prop_ro("scalable",
465 [](PyType self) { return mlirVectorTypeIsScalable(self); })
466 .def_prop_ro("scalable_dims", [](PyType self) {
467 std::vector<bool> scalableDims;
468 size_t rank = static_cast<size_t>(mlirShapedTypeGetRank(self));
469 scalableDims.reserve(rank);
470 for (size_t i = 0; i < rank; ++i)
471 scalableDims.push_back(mlirVectorTypeIsDimScalable(self, i));
472 return scalableDims;
473 });
474}
475
477PyVectorType::getChecked(std::vector<int64_t> shape, PyType &elementType,
478 std::optional<nb::sequence> scalable,
479 std::optional<std::vector<int64_t>> scalableDims,
481 if (scalable && scalableDims) {
482 throw nb::value_error("'scalable' and 'scalable_dims' kwargs "
483 "are mutually exclusive.");
484 }
485
486 PyMlirContext::ErrorCapture errors(loc->getContext());
487 MlirType type;
488 if (scalable) {
489 if (nb::len(*scalable) != shape.size())
490 throw nb::value_error("Expected len(scalable) == len(shape).");
491
492 std::vector<char> scalableDimFlags;
493 scalableDimFlags.reserve(nb::len(*scalable));
494 for (const nb::handle &h : *scalable) {
495 scalableDimFlags.push_back(nb::cast<bool>(h) ? 1 : 0);
496 }
498 loc, shape.size(), shape.data(),
499 reinterpret_cast<const bool *>(scalableDimFlags.data()), elementType);
500 } else if (scalableDims) {
501 std::vector<char> scalableDimFlags(shape.size(), 0);
502 for (int64_t dim : *scalableDims) {
503 if (static_cast<size_t>(dim) >= scalableDimFlags.size() || dim < 0)
504 throw nb::value_error("Scalable dimension index out of bounds.");
505 scalableDimFlags[dim] = 1;
506 }
508 loc, shape.size(), shape.data(),
509 reinterpret_cast<const bool *>(scalableDimFlags.data()), elementType);
510 } else {
511 type =
512 mlirVectorTypeGetChecked(loc, shape.size(), shape.data(), elementType);
513 }
514 if (mlirTypeIsNull(type))
515 throw MLIRError("Invalid type", errors.take());
516 return PyVectorType(elementType.getContext(), type);
517}
518
519PyVectorType PyVectorType::get(std::vector<int64_t> shape, PyType &elementType,
520 std::optional<nb::sequence> scalable,
521 std::optional<std::vector<int64_t>> scalableDims,
522 DefaultingPyMlirContext context) {
523 if (scalable && scalableDims) {
524 throw nb::value_error("'scalable' and 'scalable_dims' kwargs "
525 "are mutually exclusive.");
526 }
527
528 PyMlirContext::ErrorCapture errors(context->getRef());
529 MlirType type;
530 if (scalable) {
531 if (nb::len(*scalable) != shape.size())
532 throw nb::value_error("Expected len(scalable) == len(shape).");
533
534 std::vector<char> scalableDimFlags;
535 scalableDimFlags.reserve(nb::len(*scalable));
536 for (const nb::handle &h : *scalable) {
537 scalableDimFlags.push_back(nb::cast<bool>(h) ? 1 : 0);
538 }
540 shape.size(), shape.data(),
541 reinterpret_cast<const bool *>(scalableDimFlags.data()), elementType);
542 } else if (scalableDims) {
543 std::vector<char> scalableDimFlags(shape.size(), 0);
544 for (int64_t dim : *scalableDims) {
545 if (static_cast<size_t>(dim) >= scalableDimFlags.size() || dim < 0)
546 throw nb::value_error("Scalable dimension index out of bounds.");
547 scalableDimFlags[dim] = 1;
548 }
550 shape.size(), shape.data(),
551 reinterpret_cast<const bool *>(scalableDimFlags.data()), elementType);
552 } else {
553 type = mlirVectorTypeGet(shape.size(), shape.data(), elementType);
554 }
555 if (mlirTypeIsNull(type))
556 throw MLIRError("Invalid type", errors.take());
557 return PyVectorType(elementType.getContext(), type);
558}
559
561 c.def_static(
562 "get",
563 [](std::vector<int64_t> shape, PyType &elementType,
564 std::optional<PyAttribute> &encodingAttr, DefaultingPyLocation loc) {
565 PyMlirContext::ErrorCapture errors(loc->getContext());
567 loc, shape.size(), shape.data(), elementType,
568 encodingAttr ? encodingAttr->get() : mlirAttributeGetNull());
569 if (mlirTypeIsNull(t))
570 throw MLIRError("Invalid type", errors.take());
571 return PyRankedTensorType(elementType.getContext(), t);
572 },
573 nb::arg("shape"), nb::arg("element_type"),
574 nb::arg("encoding") = nb::none(), nb::arg("loc") = nb::none(),
575 "Create a ranked tensor type");
576 c.def_static(
577 "get_unchecked",
578 [](std::vector<int64_t> shape, PyType &elementType,
579 std::optional<PyAttribute> &encodingAttr,
580 DefaultingPyMlirContext context) {
581 PyMlirContext::ErrorCapture errors(context->getRef());
582 MlirType t = mlirRankedTensorTypeGet(
583 shape.size(), shape.data(), elementType,
584 encodingAttr ? encodingAttr->get() : mlirAttributeGetNull());
585 if (mlirTypeIsNull(t))
586 throw MLIRError("Invalid type", errors.take());
587 return PyRankedTensorType(elementType.getContext(), t);
588 },
589 nb::arg("shape"), nb::arg("element_type"),
590 nb::arg("encoding") = nb::none(), nb::arg("context") = nb::none(),
591 "Create a ranked tensor type");
592 c.def_prop_ro(
593 "encoding",
594 [](PyRankedTensorType &self)
595 -> std::optional<nb::typed<nb::object, PyAttribute>> {
596 MlirAttribute encoding = mlirRankedTensorTypeGetEncoding(self.get());
597 if (mlirAttributeIsNull(encoding))
598 return std::nullopt;
599 return PyAttribute(self.getContext(), encoding).maybeDownCast();
600 });
601}
602
604 c.def_static(
605 "get",
606 [](PyType &elementType, DefaultingPyLocation loc) {
607 PyMlirContext::ErrorCapture errors(loc->getContext());
608 MlirType t = mlirUnrankedTensorTypeGetChecked(loc, elementType);
609 if (mlirTypeIsNull(t))
610 throw MLIRError("Invalid type", errors.take());
611 return PyUnrankedTensorType(elementType.getContext(), t);
612 },
613 nb::arg("element_type"), nb::arg("loc") = nb::none(),
614 "Create a unranked tensor type");
615 c.def_static(
616 "get_unchecked",
617 [](PyType &elementType, DefaultingPyMlirContext context) {
618 PyMlirContext::ErrorCapture errors(context->getRef());
619 MlirType t = mlirUnrankedTensorTypeGet(elementType);
620 if (mlirTypeIsNull(t))
621 throw MLIRError("Invalid type", errors.take());
622 return PyUnrankedTensorType(elementType.getContext(), t);
623 },
624 nb::arg("element_type"), nb::arg("context") = nb::none(),
625 "Create a unranked tensor type");
626}
627
629 c.def_static(
630 "get",
631 [](std::vector<int64_t> shape, PyType &elementType, PyAttribute *layout,
632 PyAttribute *memorySpace, DefaultingPyLocation loc) {
633 PyMlirContext::ErrorCapture errors(loc->getContext());
634 MlirAttribute layoutAttr = layout ? *layout : mlirAttributeGetNull();
635 MlirAttribute memSpaceAttr =
636 memorySpace ? *memorySpace : mlirAttributeGetNull();
637 MlirType t =
638 mlirMemRefTypeGetChecked(loc, elementType, shape.size(),
639 shape.data(), layoutAttr, memSpaceAttr);
640 if (mlirTypeIsNull(t))
641 throw MLIRError("Invalid type", errors.take());
642 return PyMemRefType(elementType.getContext(), t);
643 },
644 nb::arg("shape"), nb::arg("element_type"),
645 nb::arg("layout") = nb::none(), nb::arg("memory_space") = nb::none(),
646 nb::arg("loc") = nb::none(), "Create a memref type")
647 .def_static(
648 "get_unchecked",
649 [](std::vector<int64_t> shape, PyType &elementType,
650 PyAttribute *layout, PyAttribute *memorySpace,
651 DefaultingPyMlirContext context) {
652 PyMlirContext::ErrorCapture errors(context->getRef());
653 MlirAttribute layoutAttr =
654 layout ? *layout : mlirAttributeGetNull();
655 MlirAttribute memSpaceAttr =
656 memorySpace ? *memorySpace : mlirAttributeGetNull();
657 MlirType t =
658 mlirMemRefTypeGet(elementType, shape.size(), shape.data(),
659 layoutAttr, memSpaceAttr);
660 if (mlirTypeIsNull(t))
661 throw MLIRError("Invalid type", errors.take());
662 return PyMemRefType(elementType.getContext(), t);
663 },
664 nb::arg("shape"), nb::arg("element_type"),
665 nb::arg("layout") = nb::none(), nb::arg("memory_space") = nb::none(),
666 nb::arg("context") = nb::none(), "Create a memref type")
667 .def_prop_ro(
668 "layout",
669 [](PyMemRefType &self) -> nb::typed<nb::object, PyAttribute> {
671 .maybeDownCast();
672 },
673 "The layout of the MemRef type.")
674 .def(
675 "get_strides_and_offset",
676 [](PyMemRefType &self) -> std::pair<std::vector<int64_t>, int64_t> {
677 std::vector<int64_t> strides(mlirShapedTypeGetRank(self));
678 int64_t offset;
680 self, strides.data(), &offset)))
681 throw std::runtime_error(
682 "Failed to extract strides and offset from memref.");
683 return {strides, offset};
684 },
685 "The strides and offset of the MemRef type.")
686 .def_prop_ro(
687 "affine_map",
688 [](PyMemRefType &self) -> PyAffineMap {
689 MlirAffineMap map = mlirMemRefTypeGetAffineMap(self);
690 return PyAffineMap(self.getContext(), map);
691 },
692 "The layout of the MemRef type as an affine map.")
693 .def_prop_ro(
694 "memory_space",
695 [](PyMemRefType &self)
696 -> std::optional<nb::typed<nb::object, PyAttribute>> {
697 MlirAttribute a = mlirMemRefTypeGetMemorySpace(self);
698 if (mlirAttributeIsNull(a))
699 return std::nullopt;
700 return PyAttribute(self.getContext(), a).maybeDownCast();
701 },
702 "Returns the memory space of the given MemRef type.");
703}
704
706 c.def_static(
707 "get",
708 [](PyType &elementType, PyAttribute *memorySpace,
710 PyMlirContext::ErrorCapture errors(loc->getContext());
711 MlirAttribute memSpaceAttr = {};
712 if (memorySpace)
713 memSpaceAttr = *memorySpace;
714
715 MlirType t =
716 mlirUnrankedMemRefTypeGetChecked(loc, elementType, memSpaceAttr);
717 if (mlirTypeIsNull(t))
718 throw MLIRError("Invalid type", errors.take());
719 return PyUnrankedMemRefType(elementType.getContext(), t);
720 },
721 nb::arg("element_type"), nb::arg("memory_space").none(),
722 nb::arg("loc") = nb::none(), "Create a unranked memref type")
723 .def_static(
724 "get_unchecked",
725 [](PyType &elementType, PyAttribute *memorySpace,
726 DefaultingPyMlirContext context) {
727 PyMlirContext::ErrorCapture errors(context->getRef());
728 MlirAttribute memSpaceAttr = {};
729 if (memorySpace)
730 memSpaceAttr = *memorySpace;
731
732 MlirType t = mlirUnrankedMemRefTypeGet(elementType, memSpaceAttr);
733 if (mlirTypeIsNull(t))
734 throw MLIRError("Invalid type", errors.take());
735 return PyUnrankedMemRefType(elementType.getContext(), t);
736 },
737 nb::arg("element_type"), nb::arg("memory_space").none(),
738 nb::arg("context") = nb::none(), "Create a unranked memref type")
739 .def_prop_ro(
740 "memory_space",
741 [](PyUnrankedMemRefType &self)
742 -> std::optional<nb::typed<nb::object, PyAttribute>> {
743 MlirAttribute a = mlirUnrankedMemrefGetMemorySpace(self);
744 if (mlirAttributeIsNull(a))
745 return std::nullopt;
746 return PyAttribute(self.getContext(), a).maybeDownCast();
747 },
748 "Returns the memory space of the given Unranked MemRef type.");
749}
750
752 c.def_static(
753 "get_tuple",
754 [](const std::vector<PyType> &elements, DefaultingPyMlirContext context) {
755 std::vector<MlirType> mlirElements;
756 mlirElements.reserve(elements.size());
757 for (const auto &element : elements)
758 mlirElements.push_back(element.get());
759 MlirType t = mlirTupleTypeGet(context->get(), elements.size(),
760 mlirElements.data());
761 return PyTupleType(context->getRef(), t);
762 },
763 nb::arg("elements"), nb::arg("context") = nb::none(),
764 "Create a tuple type");
765 c.def(
766 "get_type",
767 [](PyTupleType &self, intptr_t pos) -> nb::typed<nb::object, PyType> {
768 return PyType(self.getContext(), mlirTupleTypeGetType(self, pos))
769 .maybeDownCast();
770 },
771 nb::arg("pos"), "Returns the pos-th type in the tuple type.");
772 c.def_prop_ro(
773 "num_types",
774 [](PyTupleType &self) -> intptr_t {
775 return mlirTupleTypeGetNumTypes(self);
776 },
777 "Returns the number of types contained in a tuple.");
778}
779
781 c.def_static(
782 "get",
783 [](std::vector<PyType> inputs, std::vector<PyType> results,
784 DefaultingPyMlirContext context) {
785 std::vector<MlirType> mlirInputs;
786 mlirInputs.reserve(inputs.size());
787 for (const auto &input : inputs)
788 mlirInputs.push_back(input.get());
789 std::vector<MlirType> mlirResults;
790 mlirResults.reserve(results.size());
791 for (const auto &result : results)
792 mlirResults.push_back(result.get());
793
794 MlirType t = mlirFunctionTypeGet(context->get(), inputs.size(),
795 mlirInputs.data(), results.size(),
796 mlirResults.data());
797 return PyFunctionType(context->getRef(), t);
798 },
799 nb::arg("inputs"), nb::arg("results"), nb::arg("context") = nb::none(),
800 "Gets a FunctionType from a list of input and result types");
801 c.def_prop_ro(
802 "inputs",
803 [](PyFunctionType &self) -> nb::typed<nb::list, PyType> {
804 MlirType t = self;
805 nb::list types;
806 for (intptr_t i = 0, e = mlirFunctionTypeGetNumInputs(self); i < e;
807 ++i) {
808 types.append(mlirFunctionTypeGetInput(t, i));
809 }
810 return types;
811 },
812 "Returns the list of input types in the FunctionType.");
813 c.def_prop_ro(
814 "results",
815 [](PyFunctionType &self) -> nb::typed<nb::list, PyType> {
816 nb::list types;
817 for (intptr_t i = 0, e = mlirFunctionTypeGetNumResults(self); i < e;
818 ++i) {
819 types.append(mlirFunctionTypeGetResult(self, i));
820 }
821 return types;
822 },
823 "Returns the list of result types in the FunctionType.");
824}
825
827 c.def_static(
828 "get",
829 [](const std::string &dialectNamespace, const std::string &typeData,
830 DefaultingPyMlirContext context) {
831 MlirType type =
832 mlirOpaqueTypeGet(context->get(), toMlirStringRef(dialectNamespace),
833 toMlirStringRef(typeData));
834 return PyOpaqueType(context->getRef(), type);
835 },
836 nb::arg("dialect_namespace"), nb::arg("buffer"),
837 nb::arg("context") = nb::none(),
838 "Create an unregistered (opaque) dialect type.");
839 c.def_prop_ro(
840 "dialect_namespace",
841 [](PyOpaqueType &self) {
843 return nb::str(stringRef.data, stringRef.length);
844 },
845 "Returns the dialect namespace for the Opaque type as a string.");
846 c.def_prop_ro(
847 "data",
848 [](PyOpaqueType &self) {
849 MlirStringRef stringRef = mlirOpaqueTypeGetData(self);
850 return nb::str(stringRef.data, stringRef.length);
851 },
852 "Returns the data for the Opaque type as a string.");
853}
854
855static MlirDynamicTypeDefinition
856getDynamicTypeDef(const std::string &fullTypeName,
857 DefaultingPyMlirContext context) {
858 size_t dotPos = fullTypeName.find('.');
859 if (dotPos == std::string::npos) {
860 throw nb::value_error("Expected full type name to be in the format "
861 "'<dialectName>.<typeName>'.");
862 }
863
864 std::string dialectName = fullTypeName.substr(0, dotPos);
865 std::string typeName = fullTypeName.substr(dotPos + 1);
866 PyDialects dialects(context->getRef());
867 MlirDialect dialect = dialects.getDialectForKey(dialectName, false);
869 throw nb::value_error(
870 ("Dialect '" + dialectName + "' is not an extensible dialect.")
871 .c_str());
872
873 MlirDynamicTypeDefinition typeDef = mlirExtensibleDialectLookupTypeDefinition(
874 dialect, toMlirStringRef(typeName));
875 if (typeDef.ptr == nullptr) {
876 throw nb::value_error(("Dialect '" + dialectName +
877 "' does not contain a type named '" + typeName +
878 "'.")
879 .c_str());
880 }
881
882 return typeDef;
883}
884
886 c.def_static(
887 "get",
888 [](const std::string &fullTypeName, const std::vector<PyAttribute> &attrs,
889 DefaultingPyMlirContext context) {
890 MlirDynamicTypeDefinition typeDef =
891 getDynamicTypeDef(fullTypeName, context);
892
893 std::vector<MlirAttribute> mlirAttrs;
894 mlirAttrs.reserve(attrs.size());
895 for (const auto &attr : attrs)
896 mlirAttrs.push_back(attr.get());
897 MlirType t =
898 mlirDynamicTypeGet(typeDef, mlirAttrs.data(), mlirAttrs.size());
899 return PyDynamicType(context->getRef(), t);
900 },
901 nb::arg("full_type_name"), nb::arg("attributes"),
902 nb::arg("context") = nb::none(), "Create a dynamic type.");
903 c.def_prop_ro(
904 "params",
905 [](PyDynamicType &self) {
906 size_t numParams = mlirDynamicTypeGetNumParams(self);
907 std::vector<PyAttribute> params;
908 params.reserve(numParams);
909 for (size_t i = 0; i < numParams; ++i)
910 params.emplace_back(self.getContext(),
911 mlirDynamicTypeGetParam(self, i));
912 return params;
913 },
914 "Returns the parameters of the dynamic type as a list of attributes.");
915 c.def_prop_ro("type_name", [](PyDynamicType &self) {
916 MlirDynamicTypeDefinition typeDef = mlirDynamicTypeGetTypeDef(self);
918 MlirDialect dialect = mlirDynamicTypeDefinitionGetDialect(typeDef);
919 MlirStringRef dialectNamespace = mlirDialectGetNamespace(dialect);
920 return std::string(dialectNamespace.data, dialectNamespace.length) + "." +
921 std::string(name.data, name.length);
922 });
923 c.def_static(
924 "lookup_typeid",
925 [](const std::string &fullTypeName, DefaultingPyMlirContext context) {
926 MlirDynamicTypeDefinition typeDef =
927 getDynamicTypeDef(fullTypeName, context);
929 },
930 nb::arg("full_type_name"), nb::arg("context") = nb::none(),
931 "Look up the TypeID for the given dynamic type name.");
932}
933
968} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
969} // namespace python
970} // namespace mlir
ReferrentTy * get() const
PyMlirContextRef & getContext()
Accesses the context reference.
Definition IRCore.h:310
Used in function arguments when None should resolve to the current context manager set instance.
Definition IRCore.h:541
Used in function arguments when None should resolve to the current context manager set instance.
Definition IRCore.h:291
Wrapper around the generic MlirAttribute.
Definition IRCore.h:1018
nanobind::typed< nanobind::object, PyAttribute > maybeDownCast()
Definition IRCore.cpp:1872
Floating Point Type subclass - BF16Type.
Definition IRTypes.h:229
Complex Type subclass - ComplexType.
Definition IRTypes.h:312
User-level object for accessing dialects with dotted syntax such as: ctx.dialect.std.
Definition IRCore.h:490
MlirDialect getDialectForKey(const std::string &key, bool attrError)
Definition IRCore.cpp:795
Floating Point Type subclass - F16Type.
Definition IRTypes.h:243
Floating Point Type subclass - F32Type.
Definition IRTypes.h:271
Floating Point Type subclass - F64Type.
Definition IRTypes.h:285
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 - Float8E5M3FNUType.
Definition IRTypes.h:216
Floating Point Type subclass - Float8E8M0FNUType.
Definition IRTypes.h:202
Ranked MemRef Type subclass - MemRefType.
Definition IRTypes.h:394
Ranked Tensor Type subclass - RankedTensorType.
Definition IRTypes.h:366
Shaped Type Interface - ShapedType.
Definition IRTypes.h:326
Floating Point Type subclass - TF32Type.
Definition IRTypes.h:257
A TypeID provides an efficient and unique identifier for a specific C++ type.
Definition IRCore.h:917
Wrapper around the generic MlirType.
Definition IRCore.h:891
PyType(PyMlirContextRef contextRef, MlirType type)
Definition IRCore.h:893
Unranked MemRef Type subclass - UnrankedMemRefType.
Definition IRTypes.h:408
Unranked Tensor Type subclass - UnrankedTensorType.
Definition IRTypes.h:380
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 MlirType mlirFloat8E5M3FNUTypeGet(MlirContext ctx)
Creates an f8E5M3FNU type in the given context.
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:142
static bool mlirTypeIsNull(MlirType type)
Checks whether a type is null.
Definition IR.h:1231
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:1477
static MlirDynamicTypeDefinition getDynamicTypeDef(const std::string &fullTypeName, DefaultingPyMlirContext context)
Definition IRTypes.cpp:856
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:1459
RAII object that captures any error diagnostics emitted to the provided context.
Definition IRCore.h:450
std::vector< PyDiagnostic::DiagnosticInfo > take()
Definition IRCore.h:460