brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.7 KiB · 150c699 Raw
123 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include <string>10 11#include "mlir-c/Dialect/Transform.h"12#include "mlir-c/IR.h"13#include "mlir-c/Support.h"14#include "mlir/Bindings/Python/Nanobind.h"15#include "mlir/Bindings/Python/NanobindAdaptors.h"16 17namespace nb = nanobind;18using namespace mlir;19using namespace mlir::python;20using namespace mlir::python::nanobind_adaptors;21 22static void populateDialectTransformSubmodule(const nb::module_ &m) {23  //===-------------------------------------------------------------------===//24  // AnyOpType25  //===-------------------------------------------------------------------===//26 27  auto anyOpType =28      mlir_type_subclass(m, "AnyOpType", mlirTypeIsATransformAnyOpType,29                         mlirTransformAnyOpTypeGetTypeID);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  // AnyParamType40  //===-------------------------------------------------------------------===//41 42  auto anyParamType =43      mlir_type_subclass(m, "AnyParamType", mlirTypeIsATransformAnyParamType,44                         mlirTransformAnyParamTypeGetTypeID);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  // AnyValueType55  //===-------------------------------------------------------------------===//56 57  auto anyValueType =58      mlir_type_subclass(m, "AnyValueType", mlirTypeIsATransformAnyValueType,59                         mlirTransformAnyValueTypeGetTypeID);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  // OperationType70  //===-------------------------------------------------------------------===//71 72  auto operationType =73      mlir_type_subclass(m, "OperationType", mlirTypeIsATransformOperationType,74                         mlirTransformOperationTypeGetTypeID);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 =91            mlirTransformOperationTypeGetOperationName(type);92        return nb::str(operationName.data, operationName.length);93      },94      "Get the name of the payload operation accepted by the handle.");95 96  //===-------------------------------------------------------------------===//97  // ParamType98  //===-------------------------------------------------------------------===//99 100  auto paramType =101      mlir_type_subclass(m, "ParamType", mlirTypeIsATransformParamType,102                         mlirTransformParamTypeGetTypeID);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 119NB_MODULE(_mlirDialectsTransform, m) {120  m.doc() = "MLIR Transform dialect.";121  populateDialectTransformSubmodule(m);122}123