1//===- TransformTransforms.cpp - C Interface for Transform dialect --------===//
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// C interface to transforms for the transform dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#include "mlir-c/Dialect/Transform/Interpreter.h"
14#include "mlir-c/Support.h"
15#include "mlir/CAPI/IR.h"
16#include "mlir/CAPI/Support.h"
17#include "mlir/CAPI/Wrap.h"
18#include "mlir/Dialect/Transform/IR/Utils.h"
19#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
20#include "mlir/Dialect/Transform/Transforms/TransformInterpreterUtils.h"
21
22using namespace mlir;
23
24DEFINE_C_API_PTR_METHODS(MlirTransformOptions, transform::TransformOptions)
25
26extern "C" {
27
28MlirTransformOptions mlirTransformOptionsCreate() {
29 return wrap(cpp: new transform::TransformOptions);
30}
31
32void mlirTransformOptionsEnableExpensiveChecks(
33 MlirTransformOptions transformOptions, bool enable) {
34 unwrap(c: transformOptions)->enableExpensiveChecks(enable);
35}
36
37bool mlirTransformOptionsGetExpensiveChecksEnabled(
38 MlirTransformOptions transformOptions) {
39 return unwrap(c: transformOptions)->getExpensiveChecksEnabled();
40}
41
42void mlirTransformOptionsEnforceSingleTopLevelTransformOp(
43 MlirTransformOptions transformOptions, bool enable) {
44 unwrap(c: transformOptions)->enableEnforceSingleToplevelTransformOp(enable);
45}
46
47bool mlirTransformOptionsGetEnforceSingleTopLevelTransformOp(
48 MlirTransformOptions transformOptions) {
49 return unwrap(c: transformOptions)->getEnforceSingleToplevelTransformOp();
50}
51
52void mlirTransformOptionsDestroy(MlirTransformOptions transformOptions) {
53 delete unwrap(c: transformOptions);
54}
55
56MlirLogicalResult mlirTransformApplyNamedSequence(
57 MlirOperation payload, MlirOperation transformRoot,
58 MlirOperation transformModule, MlirTransformOptions transformOptions) {
59 Operation *transformRootOp = unwrap(c: transformRoot);
60 Operation *transformModuleOp = unwrap(c: transformModule);
61 if (!isa<transform::TransformOpInterface>(Val: transformRootOp)) {
62 transformRootOp->emitError()
63 << "must implement TransformOpInterface to be used as transform root";
64 return mlirLogicalResultFailure();
65 }
66 if (!isa<ModuleOp>(Val: transformModuleOp)) {
67 transformModuleOp->emitError()
68 << "must be a " << ModuleOp::getOperationName();
69 return mlirLogicalResultFailure();
70 }
71 return wrap(transform::applyTransformNamedSequence(
72 unwrap(c: payload), unwrap(c: transformRoot),
73 cast<ModuleOp>(unwrap(c: transformModule)), *unwrap(c: transformOptions)));
74}
75
76MlirLogicalResult mlirMergeSymbolsIntoFromClone(MlirOperation target,
77 MlirOperation other) {
78 OwningOpRef<Operation *> otherOwning(unwrap(c: other)->clone());
79 LogicalResult result = transform::detail::mergeSymbolsInto(
80 target: unwrap(c: target), other: std::move(otherOwning));
81 return wrap(res: result);
82}
83}
84

source code of mlir/lib/CAPI/Dialect/TransformInterpreter.cpp