13e1f6d02SAlex Zinenko //===- DialectTransform.cpp - 'transform' dialect submodule ---------------===// 23e1f6d02SAlex Zinenko // 33e1f6d02SAlex Zinenko // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 43e1f6d02SAlex Zinenko // See https://llvm.org/LICENSE.txt for license information. 53e1f6d02SAlex Zinenko // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 63e1f6d02SAlex Zinenko // 73e1f6d02SAlex Zinenko //===----------------------------------------------------------------------===// 83e1f6d02SAlex Zinenko 9*5cd42747SPeter Hawkins #include <string> 10*5cd42747SPeter Hawkins 113e1f6d02SAlex Zinenko #include "mlir-c/Dialect/Transform.h" 123e1f6d02SAlex Zinenko #include "mlir-c/IR.h" 133e1f6d02SAlex Zinenko #include "mlir-c/Support.h" 14*5cd42747SPeter Hawkins #include "mlir/Bindings/Python/NanobindAdaptors.h" 15*5cd42747SPeter Hawkins #include "mlir/Bindings/Python/Nanobind.h" 163e1f6d02SAlex Zinenko 17*5cd42747SPeter Hawkins namespace nb = nanobind; 183e1f6d02SAlex Zinenko using namespace mlir; 193e1f6d02SAlex Zinenko using namespace mlir::python; 20*5cd42747SPeter Hawkins using namespace mlir::python::nanobind_adaptors; 213e1f6d02SAlex Zinenko 22*5cd42747SPeter Hawkins void populateDialectTransformSubmodule(const nb::module_ &m) { 233e1f6d02SAlex Zinenko //===-------------------------------------------------------------------===// 243e1f6d02SAlex Zinenko // AnyOpType 253e1f6d02SAlex Zinenko //===-------------------------------------------------------------------===// 263e1f6d02SAlex Zinenko 273e1f6d02SAlex Zinenko auto anyOpType = 28681eacc1Smartin-luecke mlir_type_subclass(m, "AnyOpType", mlirTypeIsATransformAnyOpType, 29681eacc1Smartin-luecke mlirTransformAnyOpTypeGetTypeID); 303e1f6d02SAlex Zinenko anyOpType.def_classmethod( 313e1f6d02SAlex Zinenko "get", 32*5cd42747SPeter Hawkins [](nb::object cls, MlirContext ctx) { 333e1f6d02SAlex Zinenko return cls(mlirTransformAnyOpTypeGet(ctx)); 343e1f6d02SAlex Zinenko }, 35*5cd42747SPeter Hawkins "Get an instance of AnyOpType in the given context.", nb::arg("cls"), 36*5cd42747SPeter Hawkins nb::arg("context").none() = nb::none()); 373e1f6d02SAlex Zinenko 383e1f6d02SAlex Zinenko //===-------------------------------------------------------------------===// 3997f9f1a0Smartin-luecke // AnyParamType 4097f9f1a0Smartin-luecke //===-------------------------------------------------------------------===// 4197f9f1a0Smartin-luecke 4297f9f1a0Smartin-luecke auto anyParamType = 43681eacc1Smartin-luecke mlir_type_subclass(m, "AnyParamType", mlirTypeIsATransformAnyParamType, 44681eacc1Smartin-luecke mlirTransformAnyParamTypeGetTypeID); 4597f9f1a0Smartin-luecke anyParamType.def_classmethod( 4697f9f1a0Smartin-luecke "get", 47*5cd42747SPeter Hawkins [](nb::object cls, MlirContext ctx) { 4897f9f1a0Smartin-luecke return cls(mlirTransformAnyParamTypeGet(ctx)); 4997f9f1a0Smartin-luecke }, 50*5cd42747SPeter Hawkins "Get an instance of AnyParamType in the given context.", nb::arg("cls"), 51*5cd42747SPeter Hawkins nb::arg("context").none() = nb::none()); 5297f9f1a0Smartin-luecke 5397f9f1a0Smartin-luecke //===-------------------------------------------------------------------===// 548b134d0bSIngo Müller // AnyValueType 558b134d0bSIngo Müller //===-------------------------------------------------------------------===// 568b134d0bSIngo Müller 578b134d0bSIngo Müller auto anyValueType = 58681eacc1Smartin-luecke mlir_type_subclass(m, "AnyValueType", mlirTypeIsATransformAnyValueType, 59681eacc1Smartin-luecke mlirTransformAnyValueTypeGetTypeID); 608b134d0bSIngo Müller anyValueType.def_classmethod( 618b134d0bSIngo Müller "get", 62*5cd42747SPeter Hawkins [](nb::object cls, MlirContext ctx) { 638b134d0bSIngo Müller return cls(mlirTransformAnyValueTypeGet(ctx)); 648b134d0bSIngo Müller }, 65*5cd42747SPeter Hawkins "Get an instance of AnyValueType in the given context.", nb::arg("cls"), 66*5cd42747SPeter Hawkins nb::arg("context").none() = nb::none()); 678b134d0bSIngo Müller 688b134d0bSIngo Müller //===-------------------------------------------------------------------===// 693e1f6d02SAlex Zinenko // OperationType 703e1f6d02SAlex Zinenko //===-------------------------------------------------------------------===// 713e1f6d02SAlex Zinenko 723e1f6d02SAlex Zinenko auto operationType = 73bfb1ba75Smax mlir_type_subclass(m, "OperationType", mlirTypeIsATransformOperationType, 74bfb1ba75Smax mlirTransformOperationTypeGetTypeID); 753e1f6d02SAlex Zinenko operationType.def_classmethod( 763e1f6d02SAlex Zinenko "get", 77*5cd42747SPeter Hawkins [](nb::object cls, const std::string &operationName, MlirContext ctx) { 783e1f6d02SAlex Zinenko MlirStringRef cOperationName = 793e1f6d02SAlex Zinenko mlirStringRefCreate(operationName.data(), operationName.size()); 803e1f6d02SAlex Zinenko return cls(mlirTransformOperationTypeGet(ctx, cOperationName)); 813e1f6d02SAlex Zinenko }, 823e1f6d02SAlex Zinenko "Get an instance of OperationType for the given kind in the given " 833e1f6d02SAlex Zinenko "context", 84*5cd42747SPeter Hawkins nb::arg("cls"), nb::arg("operation_name"), 85*5cd42747SPeter Hawkins nb::arg("context").none() = nb::none()); 863e1f6d02SAlex Zinenko operationType.def_property_readonly( 873e1f6d02SAlex Zinenko "operation_name", 883e1f6d02SAlex Zinenko [](MlirType type) { 893e1f6d02SAlex Zinenko MlirStringRef operationName = 903e1f6d02SAlex Zinenko mlirTransformOperationTypeGetOperationName(type); 91*5cd42747SPeter Hawkins return nb::str(operationName.data, operationName.length); 923e1f6d02SAlex Zinenko }, 933e1f6d02SAlex Zinenko "Get the name of the payload operation accepted by the handle."); 9497f9f1a0Smartin-luecke 9597f9f1a0Smartin-luecke //===-------------------------------------------------------------------===// 9697f9f1a0Smartin-luecke // ParamType 9797f9f1a0Smartin-luecke //===-------------------------------------------------------------------===// 9897f9f1a0Smartin-luecke 9997f9f1a0Smartin-luecke auto paramType = 100681eacc1Smartin-luecke mlir_type_subclass(m, "ParamType", mlirTypeIsATransformParamType, 101681eacc1Smartin-luecke mlirTransformParamTypeGetTypeID); 10297f9f1a0Smartin-luecke paramType.def_classmethod( 10397f9f1a0Smartin-luecke "get", 104*5cd42747SPeter Hawkins [](nb::object cls, MlirType type, MlirContext ctx) { 10597f9f1a0Smartin-luecke return cls(mlirTransformParamTypeGet(ctx, type)); 10697f9f1a0Smartin-luecke }, 10797f9f1a0Smartin-luecke "Get an instance of ParamType for the given type in the given context.", 108*5cd42747SPeter Hawkins nb::arg("cls"), nb::arg("type"), nb::arg("context").none() = nb::none()); 10997f9f1a0Smartin-luecke paramType.def_property_readonly( 11097f9f1a0Smartin-luecke "type", 11197f9f1a0Smartin-luecke [](MlirType type) { 11297f9f1a0Smartin-luecke MlirType paramType = mlirTransformParamTypeGetType(type); 11397f9f1a0Smartin-luecke return paramType; 11497f9f1a0Smartin-luecke }, 11597f9f1a0Smartin-luecke "Get the type this ParamType is associated with."); 1163e1f6d02SAlex Zinenko } 1173e1f6d02SAlex Zinenko 118*5cd42747SPeter Hawkins NB_MODULE(_mlirDialectsTransform, m) { 1193e1f6d02SAlex Zinenko m.doc() = "MLIR Transform dialect."; 1203e1f6d02SAlex Zinenko populateDialectTransformSubmodule(m); 1213e1f6d02SAlex Zinenko } 122