MLIR 23.0.0git
TransformInterpreter.cpp
Go to the documentation of this file.
1//===- TransformInterpreter.cpp -------------------------------------------===//
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// Pybind classes for the transform dialect interpreter.
10//
11//===----------------------------------------------------------------------===//
12
14#include "mlir-c/IR.h"
15#include "mlir-c/Support.h"
20
21namespace nb = nanobind;
22
23namespace mlir {
24namespace python {
30 options = other.options;
31 other.options.ptr = nullptr;
32 }
34
36
37 MlirTransformOptions options;
38};
39} // namespace transform_interpreter
40} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
41} // namespace python
42} // namespace mlir
43
44static void populateTransformInterpreterSubmodule(nb::module_ &m) {
46 using namespace transform_interpreter;
47 nb::class_<PyTransformOptions>(m, "TransformOptions")
48 .def(nb::init<>())
49 .def_prop_rw(
50 "expensive_checks",
51 [](const PyTransformOptions &self) {
53 },
54 [](PyTransformOptions &self, bool value) {
56 })
57 .def_prop_rw(
58 "enforce_single_top_level_transform_op",
59 [](const PyTransformOptions &self) {
61 self.options);
62 },
63 [](PyTransformOptions &self, bool value) {
65 value);
66 });
67
68 m.def(
69 "apply_named_sequence",
70 [](PyOperationBase &payloadRoot, PyOperationBase &transformRoot,
71 PyOperationBase &transformModule, const PyTransformOptions &options) {
73 mlirOperationGetContext(transformRoot.getOperation()));
75 payloadRoot.getOperation(), transformRoot.getOperation(),
76 transformModule.getOperation(), options.options);
78 // Even in cases of success, we might have diagnostics to report:
79 std::string msg;
80 if ((msg = scope.takeMessage()).size() > 0) {
81 fprintf(stderr,
82 "Diagnostic generated while applying "
83 "transform.named_sequence:\n%s",
84 msg.data());
85 }
86 return;
87 }
88
89 throw nb::value_error(
90 ("Failed to apply named transform sequence.\nDiagnostic message " +
91 scope.takeMessage())
92 .c_str());
93 },
94 nb::arg("payload_root"), nb::arg("transform_root"),
95 nb::arg("transform_module"),
96 nb::arg("transform_options") = PyTransformOptions());
97
98 m.def(
99 "copy_symbols_and_merge_into",
102 mlirOperationGetContext(target.getOperation()));
103
105 target.getOperation(), other.getOperation());
107 throw nb::value_error(
108 ("Failed to merge symbols.\nDiagnostic message " +
109 scope.takeMessage())
110 .c_str());
111 }
112 },
113 nb::arg("target"), nb::arg("other"));
114}
115
116NB_MODULE(_mlirTransformInterpreter, m) {
117 m.doc() = "MLIR Transform dialect interpreter functionality.";
119}
static void populateTransformInterpreterSubmodule(nb::module_ &m)
NB_MODULE(_mlirTransformInterpreter, m)
MlirContext mlirOperationGetContext(MlirOperation op)
Definition IR.cpp:651
MLIR_CAPI_EXPORTED MlirLogicalResult mlirTransformApplyNamedSequence(MlirOperation payload, MlirOperation transformRoot, MlirOperation transformModule, MlirTransformOptions transformOptions)
Applies the transformation script starting at the given transform root operation to the given payload...
MLIR_CAPI_EXPORTED bool mlirTransformOptionsGetEnforceSingleTopLevelTransformOp(MlirTransformOptions transformOptions)
Returns true if the enforcement of the top-level transform op being single is enabled in transform op...
MLIR_CAPI_EXPORTED void mlirTransformOptionsEnableExpensiveChecks(MlirTransformOptions transformOptions, bool enable)
Enables or disables expensive checks in transform options.
MLIR_CAPI_EXPORTED void mlirTransformOptionsDestroy(MlirTransformOptions transformOptions)
Destroys a transform options object previously created by mlirTransformOptionsCreate.
MLIR_CAPI_EXPORTED void mlirTransformOptionsEnforceSingleTopLevelTransformOp(MlirTransformOptions transformOptions, bool enable)
Enables or disables the enforcement of the top-level transform op being single in transform options.
MLIR_CAPI_EXPORTED MlirTransformOptions mlirTransformOptionsCreate(void)
Creates a default-initialized transform options object.
MLIR_CAPI_EXPORTED MlirLogicalResult mlirMergeSymbolsIntoFromClone(MlirOperation target, MlirOperation other)
Merge the symbols from other into target, potentially renaming them to avoid conflicts.
MLIR_CAPI_EXPORTED bool mlirTransformOptionsGetExpensiveChecksEnabled(MlirTransformOptions transformOptions)
Returns true if expensive checks are enabled in transform options.
static llvm::ManagedStatic< PassManagerOptions > options
RAII scope intercepting all diagnostics into a string.
Definition Diagnostics.h:25
Base class for PyOperation and PyOpView which exposes the primary, user visible methods for manipulat...
Definition IRCore.h:579
virtual PyOperation & getOperation()=0
Each must provide access to the raw Operation.
static bool mlirLogicalResultIsSuccess(MlirLogicalResult res)
Checks if the given logical result represents a success.
Definition Support.h:124
static bool mlirLogicalResultIsFailure(MlirLogicalResult res)
Checks if the given logical result represents a failure.
Definition Support.h:129
Include the generated interface declarations.
A logical result value, essentially a boolean with named states.
Definition Support.h:118