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 
9 #include <string>
10 
12 #include "mlir-c/IR.h"
13 #include "mlir-c/Support.h"
16 
17 namespace nb = nanobind;
18 using namespace mlir;
19 using namespace mlir::python;
20 using namespace mlir::python::nanobind_adaptors;
21 
22 void populateDialectTransformSubmodule(const nb::module_ &m) {
23  //===-------------------------------------------------------------------===//
24  // AnyOpType
25  //===-------------------------------------------------------------------===//
26 
27  auto anyOpType =
30  anyOpType.def_classmethod(
31  "get",
32  [](nb::object cls, MlirContext ctx) {
33  return cls(mlirTransformAnyOpTypeGet(ctx));
34  },
35  "Get an instance of AnyOpType in the given context.", nb::arg("cls"),
36  nb::arg("context").none() = nb::none());
37 
38  //===-------------------------------------------------------------------===//
39  // AnyParamType
40  //===-------------------------------------------------------------------===//
41 
42  auto anyParamType =
45  anyParamType.def_classmethod(
46  "get",
47  [](nb::object cls, MlirContext ctx) {
48  return cls(mlirTransformAnyParamTypeGet(ctx));
49  },
50  "Get an instance of AnyParamType in the given context.", nb::arg("cls"),
51  nb::arg("context").none() = nb::none());
52 
53  //===-------------------------------------------------------------------===//
54  // AnyValueType
55  //===-------------------------------------------------------------------===//
56 
57  auto anyValueType =
60  anyValueType.def_classmethod(
61  "get",
62  [](nb::object cls, MlirContext ctx) {
63  return cls(mlirTransformAnyValueTypeGet(ctx));
64  },
65  "Get an instance of AnyValueType in the given context.", nb::arg("cls"),
66  nb::arg("context").none() = nb::none());
67 
68  //===-------------------------------------------------------------------===//
69  // OperationType
70  //===-------------------------------------------------------------------===//
71 
72  auto operationType =
75  operationType.def_classmethod(
76  "get",
77  [](nb::object cls, const std::string &operationName, MlirContext ctx) {
78  MlirStringRef cOperationName =
79  mlirStringRefCreate(operationName.data(), operationName.size());
80  return cls(mlirTransformOperationTypeGet(ctx, cOperationName));
81  },
82  "Get an instance of OperationType for the given kind in the given "
83  "context",
84  nb::arg("cls"), nb::arg("operation_name"),
85  nb::arg("context").none() = nb::none());
86  operationType.def_property_readonly(
87  "operation_name",
88  [](MlirType type) {
89  MlirStringRef operationName =
91  return nb::str(operationName.data, operationName.length);
92  },
93  "Get the name of the payload operation accepted by the handle.");
94 
95  //===-------------------------------------------------------------------===//
96  // ParamType
97  //===-------------------------------------------------------------------===//
98 
99  auto paramType =
102  paramType.def_classmethod(
103  "get",
104  [](nb::object cls, MlirType type, MlirContext ctx) {
105  return cls(mlirTransformParamTypeGet(ctx, type));
106  },
107  "Get an instance of ParamType for the given type in the given context.",
108  nb::arg("cls"), nb::arg("type"), nb::arg("context").none() = nb::none());
109  paramType.def_property_readonly(
110  "type",
111  [](MlirType type) {
112  MlirType paramType = mlirTransformParamTypeGetType(type);
113  return paramType;
114  },
115  "Get the type this ParamType is associated with.");
116 }
117 
118 NB_MODULE(_mlirDialectsTransform, m) {
119  m.doc() = "MLIR Transform dialect.";
121 }
NB_MODULE(_mlirDialectsTransform, m)
void populateDialectTransformSubmodule(const nb::module_ &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