MLIR  19.0.0git
TransformInterpreter.cpp
Go to the documentation of this file.
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 
14 #include "mlir-c/Support.h"
15 #include "mlir/CAPI/IR.h"
16 #include "mlir/CAPI/Support.h"
17 #include "mlir/CAPI/Wrap.h"
21 
22 using namespace mlir;
23 
25 
26 extern "C" {
27 
28 MlirTransformOptions mlirTransformOptionsCreate() {
30 }
31 
33  MlirTransformOptions transformOptions, bool enable) {
34  unwrap(transformOptions)->enableExpensiveChecks(enable);
35 }
36 
38  MlirTransformOptions transformOptions) {
39  return unwrap(transformOptions)->getExpensiveChecksEnabled();
40 }
41 
43  MlirTransformOptions transformOptions, bool enable) {
44  unwrap(transformOptions)->enableEnforceSingleToplevelTransformOp(enable);
45 }
46 
48  MlirTransformOptions transformOptions) {
49  return unwrap(transformOptions)->getEnforceSingleToplevelTransformOp();
50 }
51 
52 void mlirTransformOptionsDestroy(MlirTransformOptions transformOptions) {
53  delete unwrap(transformOptions);
54 }
55 
57  MlirOperation payload, MlirOperation transformRoot,
58  MlirOperation transformModule, MlirTransformOptions transformOptions) {
59  Operation *transformRootOp = unwrap(transformRoot);
60  Operation *transformModuleOp = unwrap(transformModule);
61  if (!isa<transform::TransformOpInterface>(transformRootOp)) {
62  transformRootOp->emitError()
63  << "must implement TransformOpInterface to be used as transform root";
64  return mlirLogicalResultFailure();
65  }
66  if (!isa<ModuleOp>(transformModuleOp)) {
67  transformModuleOp->emitError()
68  << "must be a " << ModuleOp::getOperationName();
69  return mlirLogicalResultFailure();
70  }
72  unwrap(payload), unwrap(transformRoot),
73  cast<ModuleOp>(unwrap(transformModule)), *unwrap(transformOptions)));
74 }
75 
77  MlirOperation other) {
78  OwningOpRef<Operation *> otherOwning(unwrap(other)->clone());
79  LogicalResult result = transform::detail::mergeSymbolsInto(
80  unwrap(target), std::move(otherOwning));
81  return wrap(result);
82 }
83 }
void mlirTransformOptionsEnableExpensiveChecks(MlirTransformOptions transformOptions, bool enable)
Enables or disables expensive checks in transform options.
MlirLogicalResult mlirMergeSymbolsIntoFromClone(MlirOperation target, MlirOperation other)
Merge the symbols from other into target, potentially renaming them to avoid conflicts.
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...
void mlirTransformOptionsDestroy(MlirTransformOptions transformOptions)
Destroys a transform options object previously created by mlirTransformOptionsCreate.
bool mlirTransformOptionsGetExpensiveChecksEnabled(MlirTransformOptions transformOptions)
Returns true if expensive checks are enabled in transform options.
void mlirTransformOptionsEnforceSingleTopLevelTransformOp(MlirTransformOptions transformOptions, bool enable)
Enables or disables the enforcement of the top-level transform op being single in transform options.
MlirTransformOptions mlirTransformOptionsCreate()
Creates a default-initialized transform options object.
bool mlirTransformOptionsGetEnforceSingleTopLevelTransformOp(MlirTransformOptions transformOptions)
Returns true if the enforcement of the top-level transform op being single is enabled in transform op...
#define DEFINE_C_API_PTR_METHODS(name, cpptype)
Definition: Wrap.h:25
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
Definition: Operation.cpp:268
This class acts as an owning reference to an op, and will automatically destroy the held op on destru...
Definition: OwningOpRef.h:29
Options controlling the application of transform operations by the TransformState.
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
Definition: Diagnostics.h:19
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Definition: Diagnostics.h:24
static MlirLogicalResult mlirLogicalResultFailure(void)
Creates a logical result representing a failure.
Definition: Support.h:138
InFlightDiagnostic mergeSymbolsInto(Operation *target, OwningOpRef< Operation * > other)
Merge all symbols from other into target.
Definition: Utils.cpp:79
LogicalResult applyTransformNamedSequence(Operation *payload, Operation *transformRoot, ModuleOp transformModule, const TransformOptions &options)
Standalone util to apply the named sequence transformRoot to payload IR.
Include the generated interface declarations.
Operation * clone(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)
A logical result value, essentially a boolean with named states.
Definition: Support.h:116