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
9 #include "mlir-c/Dialect/PDL.h"
10 #include "mlir-c/IR.h"
11 #include "mlir/Bindings/Python/PybindAdaptors.h"
12
13 namespace py = pybind11;
14 using namespace llvm;
15 using namespace mlir;
16 using namespace mlir::python;
17 using namespace mlir::python::adaptors;
18
populateDialectPDLSubmodule(const pybind11::module & m)19 void populateDialectPDLSubmodule(const pybind11::module &m) {
20 //===-------------------------------------------------------------------===//
21 // PDLType
22 //===-------------------------------------------------------------------===//
23
24 auto pdlType = mlir_type_subclass(m, "PDLType", mlirTypeIsAPDLType);
25
26 //===-------------------------------------------------------------------===//
27 // AttributeType
28 //===-------------------------------------------------------------------===//
29
30 auto attributeType =
31 mlir_type_subclass(m, "AttributeType", mlirTypeIsAPDLAttributeType);
32 attributeType.def_classmethod(
33 "get",
34 [](py::object cls, MlirContext ctx) {
35 return cls(mlirPDLAttributeTypeGet(ctx));
36 },
37 "Get an instance of AttributeType in given context.", py::arg("cls"),
38 py::arg("context") = py::none());
39
40 //===-------------------------------------------------------------------===//
41 // OperationType
42 //===-------------------------------------------------------------------===//
43
44 auto operationType =
45 mlir_type_subclass(m, "OperationType", mlirTypeIsAPDLOperationType);
46 operationType.def_classmethod(
47 "get",
48 [](py::object cls, MlirContext ctx) {
49 return cls(mlirPDLOperationTypeGet(ctx));
50 },
51 "Get an instance of OperationType in given context.", py::arg("cls"),
52 py::arg("context") = py::none());
53
54 //===-------------------------------------------------------------------===//
55 // RangeType
56 //===-------------------------------------------------------------------===//
57
58 auto rangeType = mlir_type_subclass(m, "RangeType", mlirTypeIsAPDLRangeType);
59 rangeType.def_classmethod(
60 "get",
61 [](py::object cls, MlirType elementType) {
62 return cls(mlirPDLRangeTypeGet(elementType));
63 },
64 "Gets an instance of RangeType in the same context as the provided "
65 "element type.",
66 py::arg("cls"), py::arg("element_type"));
67 rangeType.def_property_readonly(
68 "element_type",
69 [](MlirType type) { return mlirPDLRangeTypeGetElementType(type); },
70 "Get the element type.");
71
72 //===-------------------------------------------------------------------===//
73 // TypeType
74 //===-------------------------------------------------------------------===//
75
76 auto typeType = mlir_type_subclass(m, "TypeType", mlirTypeIsAPDLTypeType);
77 typeType.def_classmethod(
78 "get",
79 [](py::object cls, MlirContext ctx) {
80 return cls(mlirPDLTypeTypeGet(ctx));
81 },
82 "Get an instance of TypeType in given context.", py::arg("cls"),
83 py::arg("context") = py::none());
84
85 //===-------------------------------------------------------------------===//
86 // ValueType
87 //===-------------------------------------------------------------------===//
88
89 auto valueType = mlir_type_subclass(m, "ValueType", mlirTypeIsAPDLValueType);
90 valueType.def_classmethod(
91 "get",
92 [](py::object cls, MlirContext ctx) {
93 return cls(mlirPDLValueTypeGet(ctx));
94 },
95 "Get an instance of TypeType in given context.", py::arg("cls"),
96 py::arg("context") = py::none());
97 }
98
PYBIND11_MODULE(_mlirDialectsPDL,m)99 PYBIND11_MODULE(_mlirDialectsPDL, m) {
100 m.doc() = "MLIR PDL dialect.";
101 populateDialectPDLSubmodule(m);
102 }
103