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