MLIR 22.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;
16using namespace llvm;
18
19namespace mlir {
20namespace python {
22namespace pdl {
23
24//===-------------------------------------------------------------------===//
25// PDLType
26//===-------------------------------------------------------------------===//
27
28struct PDLType : PyConcreteType<PDLType> {
30 static constexpr const char *pyClassName = "PDLType";
31 using Base::Base;
32
33 static void bindDerived(ClassTy &c) {}
34};
35
36//===-------------------------------------------------------------------===//
37// AttributeType
38//===-------------------------------------------------------------------===//
39
40struct AttributeType : PyConcreteType<AttributeType> {
44 static constexpr const char *pyClassName = "AttributeType";
46 using Base::Base;
47
48 static void bindDerived(ClassTy &c) {
49 c.def_static(
50 "get",
51 [](DefaultingPyMlirContext context) {
52 return AttributeType(context->getRef(),
53 mlirPDLAttributeTypeGet(context.get()->get()));
54 },
55 "Get an instance of AttributeType in given context.",
56 nb::arg("context").none() = nb::none());
57 }
58};
59
60//===-------------------------------------------------------------------===//
61// OperationType
62//===-------------------------------------------------------------------===//
63
64struct OperationType : PyConcreteType<OperationType> {
68 static constexpr const char *pyClassName = "OperationType";
70 using Base::Base;
71
72 static void bindDerived(ClassTy &c) {
73 c.def_static(
74 "get",
75 [](DefaultingPyMlirContext context) {
76 return OperationType(context->getRef(),
77 mlirPDLOperationTypeGet(context.get()->get()));
78 },
79 "Get an instance of OperationType in given context.",
80 nb::arg("context").none() = nb::none());
81 }
82};
83
84//===-------------------------------------------------------------------===//
85// RangeType
86//===-------------------------------------------------------------------===//
87
88struct RangeType : PyConcreteType<RangeType> {
92 static constexpr const char *pyClassName = "RangeType";
94 using Base::Base;
95
96 static void bindDerived(ClassTy &c) {
97 c.def_static(
98 "get",
99 [](const PyType &elementType, DefaultingPyMlirContext context) {
100 return RangeType(context->getRef(), mlirPDLRangeTypeGet(elementType));
101 },
102 "Gets an instance of RangeType in the same context as the provided "
103 "element type.",
104 nb::arg("element_type"), nb::arg("context").none() = nb::none());
105 c.def_prop_ro(
106 "element_type",
107 [](RangeType &type) {
108 return PyType(type.getContext(), mlirPDLRangeTypeGetElementType(type))
109 .maybeDownCast();
110 },
111 "Get the element type.");
112 }
113};
114
115//===-------------------------------------------------------------------===//
116// TypeType
117//===-------------------------------------------------------------------===//
118
119struct TypeType : PyConcreteType<TypeType> {
123 static constexpr const char *pyClassName = "TypeType";
125 using Base::Base;
126
127 static void bindDerived(ClassTy &c) {
128 c.def_static(
129 "get",
130 [](DefaultingPyMlirContext context) {
131 return TypeType(context->getRef(),
132 mlirPDLTypeTypeGet(context.get()->get()));
133 },
134 "Get an instance of TypeType in given context.",
135 nb::arg("context").none() = nb::none());
136 }
137};
138
139//===-------------------------------------------------------------------===//
140// ValueType
141//===-------------------------------------------------------------------===//
142
143struct ValueType : PyConcreteType<ValueType> {
147 static constexpr const char *pyClassName = "ValueType";
149 using Base::Base;
150
151 static void bindDerived(ClassTy &c) {
152 c.def_static(
153 "get",
154 [](DefaultingPyMlirContext context) {
155 return ValueType(context->getRef(),
156 mlirPDLValueTypeGet(context.get()->get()));
157 },
158 "Get an instance of TypeType in given context.",
159 nb::arg("context").none() = nb::none());
160 }
161};
162
163static void populateDialectPDLSubmodule(nanobind::module_ &m) {
164 PDLType::bind(m);
170}
171} // namespace pdl
172} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
173} // namespace python
174} // namespace mlir
175
176NB_MODULE(_mlirDialectsPDL, m) {
177 m.doc() = "MLIR PDL dialect.";
179 m);
180}
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:280
PyType(PyMlirContextRef contextRef, MlirType type)
Definition IRCore.h:878
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
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
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:75
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static constexpr GetTypeIDFunctionTy getTypeIdFunction