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