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"
13
14namespace nb = nanobind;
15using namespace llvm;
16using namespace mlir;
17using namespace mlir::python;
19
20static 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 [](const 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") = nb::none());
40
41 //===-------------------------------------------------------------------===//
42 // OperationType
43 //===-------------------------------------------------------------------===//
44
45 auto operationType =
47 operationType.def_classmethod(
48 "get",
49 [](const 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") = nb::none());
54
55 //===-------------------------------------------------------------------===//
56 // RangeType
57 //===-------------------------------------------------------------------===//
58
59 auto rangeType = mlir_type_subclass(m, "RangeType", mlirTypeIsAPDLRangeType);
60 rangeType.def_classmethod(
61 "get",
62 [](const 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 nb::sig(
72 "def element_type(self) -> " MAKE_MLIR_PYTHON_QUALNAME("ir.Type")),
73 "Get the element type.");
74
75 //===-------------------------------------------------------------------===//
76 // TypeType
77 //===-------------------------------------------------------------------===//
78
79 auto typeType = mlir_type_subclass(m, "TypeType", mlirTypeIsAPDLTypeType);
80 typeType.def_classmethod(
81 "get",
82 [](const nb::object &cls, MlirContext ctx) {
83 return cls(mlirPDLTypeTypeGet(ctx));
84 },
85 "Get an instance of TypeType in given context.", nb::arg("cls"),
86 nb::arg("context") = nb::none());
87
88 //===-------------------------------------------------------------------===//
89 // ValueType
90 //===-------------------------------------------------------------------===//
91
92 auto valueType = mlir_type_subclass(m, "ValueType", mlirTypeIsAPDLValueType);
93 valueType.def_classmethod(
94 "get",
95 [](const nb::object &cls, MlirContext ctx) {
96 return cls(mlirPDLValueTypeGet(ctx));
97 },
98 "Get an instance of TypeType in given context.", nb::arg("cls"),
99 nb::arg("context") = nb::none());
100}
101
102NB_MODULE(_mlirDialectsPDL, m) {
103 m.doc() = "MLIR PDL dialect.";
105}
NB_MODULE(_mlirDialectsPDL, m)
static void populateDialectPDLSubmodule(const nanobind::module_ &m)
#define MAKE_MLIR_PYTHON_QUALNAME(local)
Definition Interop.h:57
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.