MLIR  16.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 
13 namespace py = pybind11;
14 using namespace llvm;
15 using namespace mlir;
16 using namespace mlir::python;
17 using namespace mlir::python::adaptors;
18 
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 =
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 =
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 
99 PYBIND11_MODULE(_mlirDialectsPDL, m) {
100  m.doc() = "MLIR PDL dialect.";
102 }
Include the generated interface declarations.
MLIR_CAPI_EXPORTED MlirType mlirPDLRangeTypeGetElementType(MlirType type)
Definition: PDL.cpp:63
Creates a custom subclass of mlir.ir.Type, implementing a casting constructor and type checking metho...
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:221
MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLOperationType(MlirType type)
Definition: PDL.cpp:43
MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLRangeType(MlirType type)
Definition: PDL.cpp:55
MLIR_CAPI_EXPORTED MlirType mlirPDLValueTypeGet(MlirContext ctx)
Definition: PDL.cpp:87
MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLTypeType(MlirType type)
Definition: PDL.cpp:71
MLIR_CAPI_EXPORTED MlirType mlirPDLTypeTypeGet(MlirContext ctx)
Definition: PDL.cpp:75
MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLType(MlirType type)
Definition: PDL.cpp:23
MLIR_CAPI_EXPORTED MlirType mlirPDLOperationTypeGet(MlirContext ctx)
Definition: PDL.cpp:47
MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLAttributeType(MlirType type)
Definition: PDL.cpp:31
PYBIND11_MODULE(_mlirDialectsPDL, m)
Definition: DialectPDL.cpp:99
MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLValueType(MlirType type)
Definition: PDL.cpp:83
MLIR_CAPI_EXPORTED MlirType mlirPDLRangeTypeGet(MlirType elementType)
Definition: PDL.cpp:59
MLIR_CAPI_EXPORTED MlirType mlirPDLAttributeTypeGet(MlirContext ctx)
Definition: PDL.cpp:35
void populateDialectPDLSubmodule(const pybind11::module &m)
Definition: DialectPDL.cpp:19