MLIR  22.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 static void populateDialectTransformSubmodule(const nb::module_ &m) {
23  //===-------------------------------------------------------------------===//
24  // AnyOpType
25  //===-------------------------------------------------------------------===//
26 
27  auto anyOpType =
30  anyOpType.def_classmethod(
31  "get",
32  [](const 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") = nb::none());
37 
38  //===-------------------------------------------------------------------===//
39  // AnyParamType
40  //===-------------------------------------------------------------------===//
41 
42  auto anyParamType =
45  anyParamType.def_classmethod(
46  "get",
47  [](const 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") = nb::none());
52 
53  //===-------------------------------------------------------------------===//
54  // AnyValueType
55  //===-------------------------------------------------------------------===//
56 
57  auto anyValueType =
60  anyValueType.def_classmethod(
61  "get",
62  [](const 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") = nb::none());
67 
68  //===-------------------------------------------------------------------===//
69  // OperationType
70  //===-------------------------------------------------------------------===//
71 
72  auto operationType =
75  operationType.def_classmethod(
76  "get",
77  [](const nb::object &cls, const std::string &operationName,
78  MlirContext ctx) {
79  MlirStringRef cOperationName =
80  mlirStringRefCreate(operationName.data(), operationName.size());
81  return cls(mlirTransformOperationTypeGet(ctx, cOperationName));
82  },
83  "Get an instance of OperationType for the given kind in the given "
84  "context",
85  nb::arg("cls"), nb::arg("operation_name"),
86  nb::arg("context") = nb::none());
87  operationType.def_property_readonly(
88  "operation_name",
89  [](MlirType type) {
90  MlirStringRef operationName =
92  return nb::str(operationName.data, operationName.length);
93  },
94  "Get the name of the payload operation accepted by the handle.");
95 
96  //===-------------------------------------------------------------------===//
97  // ParamType
98  //===-------------------------------------------------------------------===//
99 
100  auto paramType =
103  paramType.def_classmethod(
104  "get",
105  [](const nb::object &cls, MlirType type, MlirContext ctx) {
106  return cls(mlirTransformParamTypeGet(ctx, type));
107  },
108  "Get an instance of ParamType for the given type in the given context.",
109  nb::arg("cls"), nb::arg("type"), nb::arg("context") = nb::none());
110  paramType.def_property_readonly(
111  "type",
112  [](MlirType type) {
113  MlirType paramType = mlirTransformParamTypeGetType(type);
114  return paramType;
115  },
116  "Get the type this ParamType is associated with.");
117 }
118 
119 NB_MODULE(_mlirDialectsTransform, m) {
120  m.doc() = "MLIR Transform dialect.";
122 }
static void populateDialectTransformSubmodule(const nb::module_ &m)
NB_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