[Mlir-commits] [mlir] [mlir] expose transform interpreter to Python (PR #82365)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Wed Feb 21 01:27:49 PST 2024
================
@@ -0,0 +1,90 @@
+//===- TransformInterpreter.cpp -------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Pybind classes for the transform dialect interpreter.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir-c/Dialect/Transform/Interpreter.h"
+#include "mlir-c/IR.h"
+#include "mlir-c/Support.h"
+#include "mlir/Bindings/Python/PybindAdaptors.h"
+
+#include <pybind11/detail/common.h>
+#include <pybind11/pybind11.h>
+
+namespace py = pybind11;
+
+namespace {
+struct PyMlirTransformOptions {
+ PyMlirTransformOptions() { options = mlirTransformOptionsCreate(); };
+ PyMlirTransformOptions(PyMlirTransformOptions &&other) {
+ options = other.options;
+ other.options.ptr = nullptr;
+ }
+ PyMlirTransformOptions(const PyMlirTransformOptions &) = delete;
+
+ ~PyMlirTransformOptions() { mlirTransformOptionsDestroy(options); }
+
+ MlirTransformOptions options;
+};
+} // namespace
+
+static void populateTransformInterpreterSubmodule(py::module &m) {
+ py::class_<PyMlirTransformOptions>(m, "TransformOptions", py::module_local())
+ .def(py::init())
+ .def_property(
+ "expensive_checks",
+ [](const PyMlirTransformOptions &self) {
+ return mlirTransformOptionsGetExpensiveChecksEnabled(self.options);
+ },
+ [](PyMlirTransformOptions &self, bool value) {
+ mlirTransformOptionsEnableExpensiveChecks(self.options, value);
+ })
+ .def_property(
+ "enforce_single_top_level_transform_op",
+ [](const PyMlirTransformOptions &self) {
+ return mlirTransformOptionsGetEnforceSingleTopLevelTransformOp(
+ self.options);
+ },
+ [](PyMlirTransformOptions &self, bool value) {
+ mlirTransformOptionsEnforceSingleTopLevelTransformOp(self.options,
+ value);
+ });
+
+ m.def(
+ "apply_named_sequence",
+ [](MlirOperation payloadRoot, MlirOperation transformRoot,
+ MlirOperation transformModule, const PyMlirTransformOptions &options) {
----------------
ftynse wrote:
Let's have it in a follow-up.
https://github.com/llvm/llvm-project/pull/82365
More information about the Mlir-commits
mailing list