MLIR 23.0.0git
DialectPDL.cpp
Go to the documentation of this file.
1//===- DialectPDL.cpp - 'pdl' dialect submodule ---------------------------===//
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
10#include "mlir-c/IR.h"
14
15namespace nb = nanobind;
17
18namespace mlir {
19namespace python {
21namespace pdl {
22
23//===-------------------------------------------------------------------===//
24// PDLType
25//===-------------------------------------------------------------------===//
26
27struct PDLType : PyConcreteType<PDLType> {
29 static constexpr const char *pyClassName = "PDLType";
30 using Base::Base;
31
32 static void bindDerived(ClassTy &c) {}
33};
34
35//===-------------------------------------------------------------------===//
36// AttributeType
37//===-------------------------------------------------------------------===//
38
39struct AttributeType : PyConcreteType<AttributeType> {
43 static constexpr const char *pyClassName = "AttributeType";
45 using Base::Base;
46
47 static void bindDerived(ClassTy &c) {
48 c.def_static(
49 "get",
50 [](DefaultingPyMlirContext context) {
51 return AttributeType(context->getRef(),
52 mlirPDLAttributeTypeGet(context.get()->get()));
53 },
54 "Get an instance of AttributeType in given context.",
55 nb::arg("context").none() = nb::none());
56 }
57};
58
59//===-------------------------------------------------------------------===//
60// OperationType
61//===-------------------------------------------------------------------===//
62
63struct OperationType : PyConcreteType<OperationType> {
67 static constexpr const char *pyClassName = "OperationType";
69 using Base::Base;
70
71 static void bindDerived(ClassTy &c) {
72 c.def_static(
73 "get",
74 [](DefaultingPyMlirContext context) {
75 return OperationType(context->getRef(),
76 mlirPDLOperationTypeGet(context.get()->get()));
77 },
78 "Get an instance of OperationType in given context.",
79 nb::arg("context").none() = nb::none());
80 }
81};
82
83//===-------------------------------------------------------------------===//
84// RangeType
85//===-------------------------------------------------------------------===//
86
87struct RangeType : PyConcreteType<RangeType> {
91 static constexpr const char *pyClassName = "RangeType";
93 using Base::Base;
94
95 static void bindDerived(ClassTy &c) {
96 c.def_static(
97 "get",
98 [](const PyType &elementType, DefaultingPyMlirContext context) {
99 return RangeType(context->getRef(), mlirPDLRangeTypeGet(elementType));
100 },
101 "Gets an instance of RangeType in the same context as the provided "
102 "element type.",
103 nb::arg("element_type"), nb::arg("context").none() = nb::none());
104 c.def_prop_ro(
105 "element_type",
106 [](RangeType &type) {
107 return PyType(type.getContext(), mlirPDLRangeTypeGetElementType(type))
108 .maybeDownCast();
109 },
110 "Get the element type.");
111 }
112};
113
114//===-------------------------------------------------------------------===//
115// TypeType
116//===-------------------------------------------------------------------===//
117
118struct TypeType : PyConcreteType<TypeType> {
122 static constexpr const char *pyClassName = "TypeType";
124 using Base::Base;
125
126 static void bindDerived(ClassTy &c) {
127 c.def_static(
128 "get",
129 [](DefaultingPyMlirContext context) {
130 return TypeType(context->getRef(),
131 mlirPDLTypeTypeGet(context.get()->get()));
132 },
133 "Get an instance of TypeType in given context.",
134 nb::arg("context").none() = nb::none());
135 }
136};
137
138//===-------------------------------------------------------------------===//
139// ValueType
140//===-------------------------------------------------------------------===//
141
142struct ValueType : PyConcreteType<ValueType> {
146 static constexpr const char *pyClassName = "ValueType";
148 using Base::Base;
149
150 static void bindDerived(ClassTy &c) {
151 c.def_static(
152 "get",
153 [](DefaultingPyMlirContext context) {
154 return ValueType(context->getRef(),
155 mlirPDLValueTypeGet(context.get()->get()));
156 },
157 "Get an instance of TypeType in given context.",
158 nb::arg("context").none() = nb::none());
159 }
160};
161
162static void populateDialectPDLSubmodule(nanobind::module_ &m) {
163 PDLType::bind(m);
169}
170} // namespace pdl
171} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
172} // namespace python
173} // namespace mlir
174
175NB_MODULE(_mlirDialectsPDL, m) {
176 m.doc() = "MLIR PDL dialect.";
178 m);
179}
NB_MODULE(_mlirDialectsPDL, m)
ReferrentTy * get() const
Used in function arguments when None should resolve to the current context manager set instance.
Definition IRCore.h:278
PyType(PyMlirContextRef contextRef, MlirType type)
Definition IRCore.h:876
MLIR_CAPI_EXPORTED MlirTypeID mlirPDLTypeTypeGetTypeID(void)
Definition PDL.cpp:99
MLIR_CAPI_EXPORTED MlirType mlirPDLOperationTypeGet(MlirContext ctx)
Definition PDL.cpp:59
MLIR_CAPI_EXPORTED MlirTypeID mlirPDLAttributeTypeGetTypeID(void)
Definition PDL.cpp:35
MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLRangeType(MlirType type)
Definition PDL.cpp:71
MLIR_CAPI_EXPORTED MlirType mlirPDLAttributeTypeGet(MlirContext ctx)
Definition PDL.cpp:39
MLIR_CAPI_EXPORTED MlirStringRef mlirPDLOperationTypeGetName(void)
Definition PDL.cpp:63
MLIR_CAPI_EXPORTED MlirType mlirPDLValueTypeGet(MlirContext ctx)
Definition PDL.cpp:121
MLIR_CAPI_EXPORTED MlirStringRef mlirPDLValueTypeGetName(void)
Definition PDL.cpp:125
MLIR_CAPI_EXPORTED MlirStringRef mlirPDLTypeTypeGetName(void)
Definition PDL.cpp:107
MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLAttributeType(MlirType type)
Definition PDL.cpp:31
MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLOperationType(MlirType type)
Definition PDL.cpp:51
MLIR_CAPI_EXPORTED MlirTypeID mlirPDLOperationTypeGetTypeID(void)
Definition PDL.cpp:55
MLIR_CAPI_EXPORTED MlirTypeID mlirPDLValueTypeGetTypeID(void)
Definition PDL.cpp:117
MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLType(MlirType type)
Definition PDL.cpp:23
MLIR_CAPI_EXPORTED MlirType mlirPDLRangeTypeGetElementType(MlirType type)
Definition PDL.cpp:87
MLIR_CAPI_EXPORTED MlirStringRef mlirPDLAttributeTypeGetName(void)
Definition PDL.cpp:43
MLIR_CAPI_EXPORTED MlirType mlirPDLTypeTypeGet(MlirContext ctx)
Definition PDL.cpp:103
MLIR_CAPI_EXPORTED MlirType mlirPDLRangeTypeGet(MlirType elementType)
Definition PDL.cpp:79
MLIR_CAPI_EXPORTED MlirTypeID mlirPDLRangeTypeGetTypeID(void)
Definition PDL.cpp:75
MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLValueType(MlirType type)
Definition PDL.cpp:113
MLIR_CAPI_EXPORTED MlirStringRef mlirPDLRangeTypeGetName(void)
Definition PDL.cpp:83
MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLTypeType(MlirType type)
Definition PDL.cpp:95
static void populateDialectPDLSubmodule(nanobind::module_ &m)
Include the generated interface declarations.
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:78
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static constexpr GetTypeIDFunctionTy getTypeIdFunction