MLIR 23.0.0git
DialectTransform.cpp
Go to the documentation of this file.
1//===- DialectTransform.cpp - 'transform' 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 <string>
10
12#include "mlir-c/IR.h"
13#include "mlir-c/Support.h"
17
18namespace nb = nanobind;
20
21namespace mlir {
22namespace python {
24namespace transform {
25//===-------------------------------------------------------------------===//
26// AnyOpType
27//===-------------------------------------------------------------------===//
28
29struct AnyOpType : PyConcreteType<AnyOpType> {
33 static constexpr const char *pyClassName = "AnyOpType";
35 using Base::Base;
36
37 static void bindDerived(ClassTy &c) {
38 c.def_static(
39 "get",
40 [](DefaultingPyMlirContext context) {
41 return AnyOpType(context->getRef(),
42 mlirTransformAnyOpTypeGet(context.get()->get()));
43 },
44 "Get an instance of AnyOpType in the given context.",
45 nb::arg("context").none() = nb::none());
46 }
47};
48
49//===-------------------------------------------------------------------===//
50// AnyParamType
51//===-------------------------------------------------------------------===//
52
53struct AnyParamType : PyConcreteType<AnyParamType> {
57 static constexpr const char *pyClassName = "AnyParamType";
59 using Base::Base;
60
61 static void bindDerived(ClassTy &c) {
62 c.def_static(
63 "get",
64 [](DefaultingPyMlirContext context) {
65 return AnyParamType(context->getRef(), mlirTransformAnyParamTypeGet(
66 context.get()->get()));
67 },
68 "Get an instance of AnyParamType in the given context.",
69 nb::arg("context").none() = nb::none());
70 }
71};
72
73//===-------------------------------------------------------------------===//
74// AnyValueType
75//===-------------------------------------------------------------------===//
76
77struct AnyValueType : PyConcreteType<AnyValueType> {
81 static constexpr const char *pyClassName = "AnyValueType";
83 using Base::Base;
84
85 static void bindDerived(ClassTy &c) {
86 c.def_static(
87 "get",
88 [](DefaultingPyMlirContext context) {
89 return AnyValueType(context->getRef(), mlirTransformAnyValueTypeGet(
90 context.get()->get()));
91 },
92 "Get an instance of AnyValueType in the given context.",
93 nb::arg("context").none() = nb::none());
94 }
95};
96
97//===-------------------------------------------------------------------===//
98// OperationType
99//===-------------------------------------------------------------------===//
100
101struct OperationType : PyConcreteType<OperationType> {
102 static constexpr IsAFunctionTy isaFunction =
106 static constexpr const char *pyClassName = "OperationType";
108 using Base::Base;
109
110 static void bindDerived(ClassTy &c) {
111 c.def_static(
112 "get",
113 [](const std::string &operationName, DefaultingPyMlirContext context) {
114 MlirStringRef cOperationName =
115 mlirStringRefCreate(operationName.data(), operationName.size());
116 return OperationType(context->getRef(),
118 context.get()->get(), cOperationName));
119 },
120 "Get an instance of OperationType for the given kind in the given "
121 "context",
122 nb::arg("operation_name"), nb::arg("context").none() = nb::none());
123 c.def_prop_ro(
124 "operation_name",
125 [](const OperationType &type) {
126 MlirStringRef operationName =
128 return nb::str(operationName.data, operationName.length);
129 },
130 "Get the name of the payload operation accepted by the handle.");
131 }
132};
133
134//===-------------------------------------------------------------------===//
135// ParamType
136//===-------------------------------------------------------------------===//
137
138struct ParamType : PyConcreteType<ParamType> {
142 static constexpr const char *pyClassName = "ParamType";
144 using Base::Base;
145
146 static void bindDerived(ClassTy &c) {
147 c.def_static(
148 "get",
149 [](const PyType &type, DefaultingPyMlirContext context) {
150 return ParamType(context->getRef(), mlirTransformParamTypeGet(
151 context.get()->get(), type));
152 },
153 "Get an instance of ParamType for the given type in the given context.",
154 nb::arg("type"), nb::arg("context").none() = nb::none());
155 c.def_prop_ro(
156 "type",
157 [](ParamType type) {
158 return PyType(type.getContext(), mlirTransformParamTypeGetType(type))
159 .maybeDownCast();
160 },
161 "Get the type this ParamType is associated with.");
162 }
163};
164
172} // namespace transform
173} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
174} // namespace python
175} // namespace mlir
176
177NB_MODULE(_mlirDialectsTransform, m) {
178 m.doc() = "MLIR Transform dialect.";
181}
NB_MODULE(_mlirDialectsTransform, m)
MLIR_CAPI_EXPORTED MlirType mlirTransformAnyOpTypeGet(MlirContext ctx)
Definition Transform.cpp:32
MLIR_CAPI_EXPORTED MlirTypeID mlirTransformAnyParamTypeGetTypeID(void)
Definition Transform.cpp:48
MLIR_CAPI_EXPORTED MlirStringRef mlirTransformParamTypeGetName(void)
MLIR_CAPI_EXPORTED bool mlirTypeIsATransformAnyValueType(MlirType type)
Definition Transform.cpp:64
MLIR_CAPI_EXPORTED bool mlirTypeIsATransformOperationType(MlirType type)
Definition Transform.cpp:84
MLIR_CAPI_EXPORTED bool mlirTypeIsATransformAnyParamType(MlirType type)
Definition Transform.cpp:44
MLIR_CAPI_EXPORTED MlirTypeID mlirTransformAnyValueTypeGetTypeID(void)
Definition Transform.cpp:68
MLIR_CAPI_EXPORTED MlirTypeID mlirTransformParamTypeGetTypeID(void)
MLIR_CAPI_EXPORTED bool mlirTypeIsATransformAnyOpType(MlirType type)
MLIR_CAPI_EXPORTED MlirType mlirTransformOperationTypeGet(MlirContext ctx, MlirStringRef operationName)
Definition Transform.cpp:92
MLIR_CAPI_EXPORTED MlirStringRef mlirTransformOperationTypeGetName(void)
Definition Transform.cpp:98
MLIR_CAPI_EXPORTED bool mlirTypeIsATransformParamType(MlirType type)
MLIR_CAPI_EXPORTED MlirType mlirTransformParamTypeGet(MlirContext ctx, MlirType type)
MLIR_CAPI_EXPORTED MlirTypeID mlirTransformOperationTypeGetTypeID(void)
Definition Transform.cpp:88
MLIR_CAPI_EXPORTED MlirStringRef mlirTransformAnyValueTypeGetName(void)
Definition Transform.cpp:76
MLIR_CAPI_EXPORTED MlirType mlirTransformAnyValueTypeGet(MlirContext ctx)
Definition Transform.cpp:72
MLIR_CAPI_EXPORTED MlirType mlirTransformAnyParamTypeGet(MlirContext ctx)
Definition Transform.cpp:52
MLIR_CAPI_EXPORTED MlirType mlirTransformParamTypeGetType(MlirType type)
MLIR_CAPI_EXPORTED MlirStringRef mlirTransformOperationTypeGetOperationName(MlirType type)
MLIR_CAPI_EXPORTED MlirStringRef mlirTransformAnyOpTypeGetName(void)
Definition Transform.cpp:36
MLIR_CAPI_EXPORTED MlirStringRef mlirTransformAnyParamTypeGetName(void)
Definition Transform.cpp:56
MLIR_CAPI_EXPORTED MlirTypeID mlirTransformAnyOpTypeGetTypeID(void)
Definition Transform.cpp:28
ReferrentTy * get() const
Used in function arguments when None should resolve to the current context manager set instance.
Definition IRCore.h:280
PyType(PyMlirContextRef contextRef, MlirType type)
Definition IRCore.h:878
static MlirStringRef mlirStringRefCreate(const char *str, size_t length)
Constructs a string reference from the pointer and length.
Definition Support.h:84
Include the generated interface declarations.
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:75
const char * data
Pointer to the first symbol.
Definition Support.h:76
size_t length
Length of the fragment.
Definition Support.h:77