26 static int mlirTypeIsAIntegerOrFloat(MlirType type) {
34 static constexpr
const char *pyClassName =
"IntegerType";
37 static void bindDerived(ClassTy &c) {
42 return PyIntegerType(context->getRef(), t);
44 py::arg(
"width"), py::arg(
"context") = py::none(),
45 "Create a signless integer type");
50 return PyIntegerType(context->getRef(), t);
52 py::arg(
"width"), py::arg(
"context") = py::none(),
53 "Create a signed integer type");
58 return PyIntegerType(context->getRef(), t);
60 py::arg(
"width"), py::arg(
"context") = py::none(),
61 "Create an unsigned integer type");
62 c.def_property_readonly(
65 "Returns the width of the integer type");
66 c.def_property_readonly(
68 [](PyIntegerType &
self) ->
bool {
71 "Returns whether this is a signless integer");
72 c.def_property_readonly(
74 [](PyIntegerType &
self) ->
bool {
77 "Returns whether this is a signed integer");
78 c.def_property_readonly(
80 [](PyIntegerType &
self) ->
bool {
83 "Returns whether this is an unsigned integer");
91 static constexpr
const char *pyClassName =
"IndexType";
94 static void bindDerived(ClassTy &c) {
99 return PyIndexType(context->getRef(), t);
101 py::arg(
"context") = py::none(),
"Create a index type.");
109 static constexpr
const char *pyClassName =
"BF16Type";
112 static void bindDerived(ClassTy &c) {
117 return PyBF16Type(context->getRef(), t);
119 py::arg(
"context") = py::none(),
"Create a bf16 type.");
127 static constexpr
const char *pyClassName =
"F16Type";
130 static void bindDerived(ClassTy &c) {
135 return PyF16Type(context->getRef(), t);
137 py::arg(
"context") = py::none(),
"Create a f16 type.");
145 static constexpr
const char *pyClassName =
"F32Type";
148 static void bindDerived(ClassTy &c) {
153 return PyF32Type(context->getRef(), t);
155 py::arg(
"context") = py::none(),
"Create a f32 type.");
163 static constexpr
const char *pyClassName =
"F64Type";
166 static void bindDerived(ClassTy &c) {
171 return PyF64Type(context->getRef(), t);
173 py::arg(
"context") = py::none(),
"Create a f64 type.");
181 static constexpr
const char *pyClassName =
"NoneType";
184 static void bindDerived(ClassTy &c) {
189 return PyNoneType(context->getRef(), t);
191 py::arg(
"context") = py::none(),
"Create a none type.");
199 static constexpr
const char *pyClassName =
"ComplexType";
202 static void bindDerived(ClassTy &c) {
207 if (mlirTypeIsAIntegerOrFloat(elementType)) {
209 return PyComplexType(elementType.
getContext(), t);
214 py::repr(py::cast(elementType)).cast<std::string>() +
215 "' and expected floating point or integer type.");
217 "Create a complex type");
218 c.def_property_readonly(
220 [](PyComplexType &
self) ->
PyType {
222 return PyType(
self.getContext(), t);
224 "Returns element type.");
231 static constexpr
const char *pyClassName =
"ShapedType";
234 static void bindDerived(ClassTy &c) {
235 c.def_property_readonly(
237 [](PyShapedType &
self) {
239 return PyType(
self.getContext(), t);
241 "Returns the element type of the shaped type.");
242 c.def_property_readonly(
245 "Returns whether the given shaped type is ranked.");
246 c.def_property_readonly(
248 [](PyShapedType &
self) {
249 self.requireHasRank();
252 "Returns the rank of the given ranked shaped type.");
253 c.def_property_readonly(
255 [](PyShapedType &
self) ->
bool {
258 "Returns whether the given shaped type has a static shape.");
261 [](PyShapedType &
self, intptr_t dim) ->
bool {
262 self.requireHasRank();
266 "Returns whether the dim-th dimension of the given shaped type is " 270 [](PyShapedType &
self, intptr_t dim) {
271 self.requireHasRank();
275 "Returns the dim-th dimension of the given ranked shaped type.");
280 "Returns whether the given dimension size indicates a dynamic " 283 "is_dynamic_stride_or_offset",
284 [](PyShapedType &
self, int64_t val) ->
bool {
285 self.requireHasRank();
289 "Returns whether the given value is used as a placeholder for dynamic " 290 "strides and offsets in shaped types.");
291 c.def_property_readonly(
293 [](PyShapedType &
self) {
294 self.requireHasRank();
296 std::vector<int64_t> shape;
299 for (int64_t i = 0; i < rank; ++i)
303 "Returns the shape of the ranked shaped type as a list of integers.");
306 "Returns the value used to indicate dynamic dimensions in shaped " 309 "_get_dynamic_stride_or_offset",
311 "Returns the value used to indicate dynamic strides or offsets in " 316 void requireHasRank() {
320 "calling this method requires that the type has a rank.");
326 class PyVectorType :
public PyConcreteType<PyVectorType, PyShapedType> {
329 static constexpr
const char *pyClassName =
"VectorType";
332 static void bindDerived(ClassTy &c) {
335 [](std::vector<int64_t> shape,
PyType &elementType,
345 py::repr(py::cast(elementType)).cast<std::string>() +
346 "' and expected floating point or integer type.");
348 return PyVectorType(elementType.
getContext(), t);
350 py::arg(
"shape"), py::arg(
"elementType"), py::arg(
"loc") = py::none(),
351 "Create a vector type");
356 class PyRankedTensorType
360 static constexpr
const char *pyClassName =
"RankedTensorType";
363 static void bindDerived(ClassTy &c) {
366 [](std::vector<int64_t> shape,
PyType &elementType,
370 loc, shape.size(), shape.data(), elementType,
378 py::repr(py::cast(elementType)).cast<std::string>() +
379 "' and expected floating point, integer, vector or " 383 return PyRankedTensorType(elementType.
getContext(), t);
385 py::arg(
"shape"), py::arg(
"element_type"),
386 py::arg(
"encoding") = py::none(), py::arg(
"loc") = py::none(),
387 "Create a ranked tensor type");
388 c.def_property_readonly(
400 class PyUnrankedTensorType
404 static constexpr
const char *pyClassName =
"UnrankedTensorType";
407 static void bindDerived(ClassTy &c) {
418 py::repr(py::cast(elementType)).cast<std::string>() +
419 "' and expected floating point, integer, vector or " 423 return PyUnrankedTensorType(elementType.
getContext(), t);
425 py::arg(
"element_type"), py::arg(
"loc") = py::none(),
426 "Create a unranked tensor type");
431 class PyMemRefType :
public PyConcreteType<PyMemRefType, PyShapedType> {
434 static constexpr
const char *pyClassName =
"MemRefType";
437 static void bindDerived(ClassTy &c) {
440 [](std::vector<int64_t> shape,
PyType &elementType,
444 MlirAttribute memSpaceAttr =
448 shape.data(), layoutAttr, memSpaceAttr);
455 py::repr(py::cast(elementType)).cast<std::string>() +
456 "' and expected floating point, integer, vector or " 460 return PyMemRefType(elementType.
getContext(), t);
462 py::arg(
"shape"), py::arg(
"element_type"),
463 py::arg(
"layout") = py::none(), py::arg(
"memory_space") = py::none(),
464 py::arg(
"loc") = py::none(),
"Create a memref type")
465 .def_property_readonly(
471 "The layout of the MemRef type.")
472 .def_property_readonly(
478 "The layout of the MemRef type as an affine map.")
479 .def_property_readonly(
485 "Returns the memory space of the given MemRef type.");
490 class PyUnrankedMemRefType
494 static constexpr
const char *pyClassName =
"UnrankedMemRefType";
497 static void bindDerived(ClassTy &c) {
502 MlirAttribute memSpaceAttr = {};
504 memSpaceAttr = *memorySpace;
514 py::repr(py::cast(elementType)).cast<std::string>() +
515 "' and expected floating point, integer, vector or " 519 return PyUnrankedMemRefType(elementType.
getContext(), t);
521 py::arg(
"element_type"), py::arg(
"memory_space"),
522 py::arg(
"loc") = py::none(),
"Create a unranked memref type")
523 .def_property_readonly(
529 "Returns the memory space of the given Unranked MemRef type.");
537 static constexpr
const char *pyClassName =
"TupleType";
540 static void bindDerived(ClassTy &c) {
544 intptr_t num = py::len(elementList);
547 for (
auto element : elementList)
548 elements.push_back(element.cast<
PyType>());
550 return PyTupleType(context->getRef(), t);
552 py::arg(
"elements"), py::arg(
"context") = py::none(),
553 "Create a tuple type");
556 [](PyTupleType &
self, intptr_t pos) ->
PyType {
558 return PyType(
self.getContext(), t);
560 py::arg(
"pos"),
"Returns the pos-th type in the tuple type.");
561 c.def_property_readonly(
563 [](PyTupleType &
self) -> intptr_t {
566 "Returns the number of types contained in a tuple.");
574 static constexpr
const char *pyClassName =
"FunctionType";
577 static void bindDerived(ClassTy &c) {
580 [](std::vector<PyType> inputs, std::vector<PyType> results,
585 inputsRaw.data(), resultsRaw.size(),
587 return PyFunctionType(context->getRef(), t);
589 py::arg(
"inputs"), py::arg(
"results"), py::arg(
"context") = py::none(),
590 "Gets a FunctionType from a list of input and result types");
591 c.def_property_readonly(
593 [](PyFunctionType &
self) {
595 auto contextRef =
self.getContext();
603 "Returns the list of input types in the FunctionType.");
604 c.def_property_readonly(
606 [](PyFunctionType &
self) {
607 auto contextRef =
self.getContext();
616 "Returns the list of result types in the FunctionType.");
628 static constexpr
const char *pyClassName =
"OpaqueType";
631 static void bindDerived(ClassTy &c) {
634 [](std::string dialectNamespace, std::string typeData,
639 return PyOpaqueType(context->getRef(), type);
641 py::arg(
"dialect_namespace"), py::arg(
"buffer"),
642 py::arg(
"context") = py::none(),
643 "Create an unregistered (opaque) dialect type.");
644 c.def_property_readonly(
646 [](PyOpaqueType &
self) {
648 return py::str(stringRef.
data, stringRef.
length);
650 "Returns the dialect namespace for the Opaque type as a string.");
651 c.def_property_readonly(
653 [](PyOpaqueType &
self) {
655 return py::str(stringRef.
data, stringRef.
length);
657 "Returns the data for the Opaque type as a string.");
664 PyIntegerType::bind(m);
665 PyIndexType::bind(m);
671 PyComplexType::bind(m);
672 PyShapedType::bind(m);
673 PyVectorType::bind(m);
674 PyRankedTensorType::bind(m);
675 PyUnrankedTensorType::bind(m);
676 PyMemRefType::bind(m);
677 PyUnrankedMemRefType::bind(m);
678 PyTupleType::bind(m);
679 PyFunctionType::bind(m);
680 PyOpaqueType::bind(m);
static MlirStringRef toMlirStringRef(const std::string &s)
MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueTypeGetData(MlirType type)
Returns the raw data as a string reference.
Include the generated interface declarations.
MLIR_CAPI_EXPORTED bool mlirTypeIsAUnrankedMemRef(MlirType type)
Checks whether the given type is an UnrankedMemRef type.
const char * data
Pointer to the first symbol.
MLIR_CAPI_EXPORTED MlirType mlirComplexTypeGetElementType(MlirType type)
Returns the element type of the given complex type.
MLIR_CAPI_EXPORTED intptr_t mlirFunctionTypeGetNumInputs(MlirType type)
Returns the number of input types.
MLIR_CAPI_EXPORTED bool mlirTypeIsAMemRef(MlirType type)
Checks whether the given type is a MemRef type.
static bool mlirAttributeIsNull(MlirAttribute attr)
Checks whether an attribute is null.
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, emitting appropriate diagnostics.
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 bool mlirShapedTypeHasRank(MlirType type)
Checks whether the given shaped type is ranked.
Used in function arguments when None should resolve to the current context manager set instance...
MLIR_CAPI_EXPORTED MlirType mlirUnrankedTensorTypeGetChecked(MlirLocation loc, MlirType elementType)
Same as "mlirUnrankedTensorTypeGet" but returns a nullptr wrapping MlirType on illegal arguments...
ReferrentTy * get() const
MLIR_CAPI_EXPORTED bool mlirTypeIsAF32(MlirType type)
Checks whether the given type is an f32 type.
MLIR_CAPI_EXPORTED bool mlirTypeIsAShaped(MlirType type)
Checks whether the given type is a Shaped 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 bool mlirTypeIsAFunction(MlirType type)
Checks whether the given type is a function type.
MLIR_CAPI_EXPORTED bool mlirTypeIsAInteger(MlirType type)
Checks whether the given type is an integer type.
MLIR_CAPI_EXPORTED bool mlirTypeIsAUnrankedTensor(MlirType type)
Checks whether the given type is an unranked tensor type.
MLIR_CAPI_EXPORTED MlirType mlirF32TypeGet(MlirContext ctx)
Creates an f32 type in the given context.
Used in function arguments when None should resolve to the current context manager set instance...
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 mlirNoneTypeGet(MlirContext ctx)
Creates a None type in the given context.
MLIR_CAPI_EXPORTED bool mlirTypeIsAOpaque(MlirType type)
Checks whether the given type is an opaque type.
MLIR_CAPI_EXPORTED MlirAffineMap mlirMemRefTypeGetAffineMap(MlirType type)
Returns the affine map of the given MemRef type.
MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetDynamicStrideOrOffset()
Returns the value indicating a dynamic stride or offset in a shaped type.
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 bool mlirTypeIsAComplex(MlirType type)
Checks whether the given type is a Complex type.
MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsSigned(MlirType type)
Checks whether the given integer type is signed.
MLIR_CAPI_EXPORTED MlirType mlirF64TypeGet(MlirContext ctx)
Creates a f64 type in the given context.
Wrapper around the generic MlirType.
void populateIRTypes(pybind11::module &m)
MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeSignedGet(MlirContext ctx, unsigned bitwidth)
Creates a signed integer type of the given bitwidth in the context.
MLIR_CAPI_EXPORTED unsigned mlirIntegerTypeGetWidth(MlirType type)
Returns the bitwidth of an integer type.
MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsUnsigned(MlirType type)
Checks whether the given integer type is unsigned.
CRTP base classes for Python types that subclass Type and should be castable from it (i...
MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetRank(MlirType type)
Returns the rank of the given ranked shaped type.
pybind11::error_already_set SetPyError(PyObject *excClass, const llvm::Twine &message)
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 MlirType mlirComplexTypeGet(MlirType elementType)
Creates a complex type with the given element type in the same context as the element type...
Wrapper around the generic MlirAttribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirMemRefTypeGetMemorySpace(MlirType type)
Returns the memory space of the given MemRef type.
size_t length
Length of the fragment.
MLIR_CAPI_EXPORTED MlirType mlirF16TypeGet(MlirContext ctx)
Creates an f16 type in the given context.
MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueTypeGetDialectNamespace(MlirType type)
Returns the namespace of the dialect with which the given opaque type is associated.
MLIR_CAPI_EXPORTED MlirType mlirBF16TypeGet(MlirContext ctx)
Creates a bf16 type in the given context.
MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeUnsignedGet(MlirContext ctx, unsigned bitwidth)
Creates an unsigned integer type of the given bitwidth in the context.
static MlirStringRef mlirStringRefCreate(const char *str, size_t length)
Constructs a string reference from the pointer and length.
MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeGetNull()
Returns an empty attribute.
A pointer to a sized fragment of a string, not necessarily null-terminated.
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...
PyMlirContextRef & getContext()
Accesses the context reference.
MLIR_CAPI_EXPORTED bool mlirTypeIsARankedTensor(MlirType type)
Checks whether the given type is a ranked tensor type.
MLIR_CAPI_EXPORTED MlirAttribute mlirMemRefTypeGetLayout(MlirType type)
Returns the layout of the given MemRef type.
MLIR_CAPI_EXPORTED MlirType mlirIndexTypeGet(MlirContext ctx)
Creates an index type in the given context.
MLIR_CAPI_EXPORTED bool mlirTypeIsATuple(MlirType type)
Checks whether the given type is a tuple type.
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, emitting appropriate diagnostics.
MLIR_CAPI_EXPORTED bool mlirTypeIsAIndex(MlirType type)
Checks whether the given type is an index type.
MLIR_CAPI_EXPORTED intptr_t mlirFunctionTypeGetNumResults(MlirType type)
Returns the number of result types.
MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetDynamicSize()
Returns the value indicating a dynamic size in a shaped type.
MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsSignless(MlirType type)
Checks whether the given integer type is signless.
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 MlirType mlirTupleTypeGetType(MlirType type, intptr_t pos)
Returns the pos-th type in the tuple type.
MLIR_CAPI_EXPORTED MlirType mlirShapedTypeGetElementType(MlirType type)
Returns the element type of the shaped type.
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 MlirAttribute mlirRankedTensorTypeGetEncoding(MlirType type)
Gets the 'encoding' attribute from the ranked tensor type, returning a null attribute if none...
MLIR_CAPI_EXPORTED MlirType mlirFunctionTypeGetInput(MlirType type, intptr_t pos)
Returns the pos-th input type.
MLIR_CAPI_EXPORTED bool mlirTypeIsANone(MlirType type)
Checks whether the given type is a None type.
MLIR_CAPI_EXPORTED intptr_t mlirTupleTypeGetNumTypes(MlirType type)
Returns the number of types contained in a tuple.
MLIR_CAPI_EXPORTED bool mlirTypeIsAF64(MlirType type)
Checks whether the given type is an f64 type.
MLIR_CAPI_EXPORTED bool mlirTypeIsAVector(MlirType type)
Checks whether the given type is a Vector type.
MLIR_CAPI_EXPORTED bool mlirShapedTypeIsDynamicDim(MlirType type, intptr_t dim)
Checks wither the dim-th dimension of the given shaped type is dynamic.
MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeGet(MlirContext ctx, unsigned bitwidth)
Creates a signless integer type of the given bitwidth in the context.
MLIR_CAPI_EXPORTED bool mlirShapedTypeHasStaticShape(MlirType type)
Checks whether the given shaped type has a static shape.
MLIR_CAPI_EXPORTED bool mlirTypeIsAF16(MlirType type)
Checks whether the given type is an f16 type.
static bool mlirTypeIsNull(MlirType type)
Checks whether a type is null.
MLIR_CAPI_EXPORTED MlirType mlirFunctionTypeGetResult(MlirType type, intptr_t pos)
Returns the pos-th result type.
MLIR_CAPI_EXPORTED bool mlirTypeIsABF16(MlirType type)
Checks whether the given type is a bf16 type.