MLIR  20.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 
10 #include "mlir-c/IR.h"
11 #include "mlir-c/Support.h"
13 #include <pybind11/cast.h>
14 #include <pybind11/detail/common.h>
15 #include <pybind11/pybind11.h>
16 #include <pybind11/pytypes.h>
17 #include <string>
18 
19 namespace py = pybind11;
20 using namespace mlir;
21 using namespace mlir::python;
22 using namespace mlir::python::adaptors;
23 
24 void populateDialectTransformSubmodule(const pybind11::module &m) {
25  //===-------------------------------------------------------------------===//
26  // AnyOpType
27  //===-------------------------------------------------------------------===//
28 
29  auto anyOpType =
32  anyOpType.def_classmethod(
33  "get",
34  [](py::object cls, MlirContext ctx) {
35  return cls(mlirTransformAnyOpTypeGet(ctx));
36  },
37  "Get an instance of AnyOpType in the given context.", py::arg("cls"),
38  py::arg("context") = py::none());
39 
40  //===-------------------------------------------------------------------===//
41  // AnyParamType
42  //===-------------------------------------------------------------------===//
43 
44  auto anyParamType =
47  anyParamType.def_classmethod(
48  "get",
49  [](py::object cls, MlirContext ctx) {
50  return cls(mlirTransformAnyParamTypeGet(ctx));
51  },
52  "Get an instance of AnyParamType in the given context.", py::arg("cls"),
53  py::arg("context") = py::none());
54 
55  //===-------------------------------------------------------------------===//
56  // AnyValueType
57  //===-------------------------------------------------------------------===//
58 
59  auto anyValueType =
62  anyValueType.def_classmethod(
63  "get",
64  [](py::object cls, MlirContext ctx) {
65  return cls(mlirTransformAnyValueTypeGet(ctx));
66  },
67  "Get an instance of AnyValueType in the given context.", py::arg("cls"),
68  py::arg("context") = py::none());
69 
70  //===-------------------------------------------------------------------===//
71  // OperationType
72  //===-------------------------------------------------------------------===//
73 
74  auto operationType =
77  operationType.def_classmethod(
78  "get",
79  [](py::object cls, const std::string &operationName, MlirContext ctx) {
80  MlirStringRef cOperationName =
81  mlirStringRefCreate(operationName.data(), operationName.size());
82  return cls(mlirTransformOperationTypeGet(ctx, cOperationName));
83  },
84  "Get an instance of OperationType for the given kind in the given "
85  "context",
86  py::arg("cls"), py::arg("operation_name"),
87  py::arg("context") = py::none());
88  operationType.def_property_readonly(
89  "operation_name",
90  [](MlirType type) {
91  MlirStringRef operationName =
93  return py::str(operationName.data, operationName.length);
94  },
95  "Get the name of the payload operation accepted by the handle.");
96 
97  //===-------------------------------------------------------------------===//
98  // ParamType
99  //===-------------------------------------------------------------------===//
100 
101  auto paramType =
104  paramType.def_classmethod(
105  "get",
106  [](py::object cls, MlirType type, MlirContext ctx) {
107  return cls(mlirTransformParamTypeGet(ctx, type));
108  },
109  "Get an instance of ParamType for the given type in the given context.",
110  py::arg("cls"), py::arg("type"), py::arg("context") = py::none());
111  paramType.def_property_readonly(
112  "type",
113  [](MlirType type) {
114  MlirType paramType = mlirTransformParamTypeGetType(type);
115  return paramType;
116  },
117  "Get the type this ParamType is associated with.");
118 }
119 
120 PYBIND11_MODULE(_mlirDialectsTransform, m) {
121  m.doc() = "MLIR Transform dialect.";
123 }
void populateDialectTransformSubmodule(const pybind11::module &m)
PYBIND11_MODULE(_mlirDialectsTransform, m)
MLIR_CAPI_EXPORTED MlirType mlirTransformAnyOpTypeGet(MlirContext ctx)
Definition: Transform.cpp:32
MLIR_CAPI_EXPORTED MlirTypeID mlirTransformAnyParamTypeGetTypeID(void)
Definition: Transform.cpp:44
MLIR_CAPI_EXPORTED bool mlirTypeIsATransformAnyValueType(MlirType type)
Definition: Transform.cpp:56
MLIR_CAPI_EXPORTED bool mlirTypeIsATransformOperationType(MlirType type)
Definition: Transform.cpp:72
MLIR_CAPI_EXPORTED bool mlirTypeIsATransformAnyParamType(MlirType type)
Definition: Transform.cpp:40
MLIR_CAPI_EXPORTED MlirTypeID mlirTransformAnyValueTypeGetTypeID(void)
Definition: Transform.cpp:60
MLIR_CAPI_EXPORTED MlirTypeID mlirTransformParamTypeGetTypeID(void)
Definition: Transform.cpp:98
MLIR_CAPI_EXPORTED bool mlirTypeIsATransformAnyOpType(MlirType type)
MLIR_CAPI_EXPORTED MlirType mlirTransformOperationTypeGet(MlirContext ctx, MlirStringRef operationName)
Definition: Transform.cpp:80
MLIR_CAPI_EXPORTED bool mlirTypeIsATransformParamType(MlirType type)
Definition: Transform.cpp:94
MLIR_CAPI_EXPORTED MlirType mlirTransformParamTypeGet(MlirContext ctx, MlirType type)
Definition: Transform.cpp:102
MLIR_CAPI_EXPORTED MlirTypeID mlirTransformOperationTypeGetTypeID(void)
Definition: Transform.cpp:76
MLIR_CAPI_EXPORTED MlirType mlirTransformAnyValueTypeGet(MlirContext ctx)
Definition: Transform.cpp:64
MLIR_CAPI_EXPORTED MlirType mlirTransformAnyParamTypeGet(MlirContext ctx)
Definition: Transform.cpp:48
MLIR_CAPI_EXPORTED MlirType mlirTransformParamTypeGetType(MlirType type)
Definition: Transform.cpp:106
MLIR_CAPI_EXPORTED MlirStringRef mlirTransformOperationTypeGetOperationName(MlirType type)
Definition: Transform.cpp:86
MLIR_CAPI_EXPORTED MlirTypeID mlirTransformAnyOpTypeGetTypeID(void)
Definition: Transform.cpp:28
Creates a custom subclass of mlir.ir.Type, implementing a casting constructor and type checking metho...
static MlirStringRef mlirStringRefCreate(const char *str, size_t length)
Constructs a string reference from the pointer and length.
Definition: Support.h:82
Include the generated interface declarations.
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition: Support.h:73
const char * data
Pointer to the first symbol.
Definition: Support.h:74
size_t length
Length of the fragment.
Definition: Support.h:75