1 //===-- MyExtension.td - Transform dialect tutorial --------*- tablegen -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines Transform dialect extension operations used in the
10 // Chapter 3 of the Transform dialect tutorial.
12 //===----------------------------------------------------------------------===//
17 include "MyExtensionTypes.td"
18 include "mlir/Dialect/Transform/IR/TransformDialect.td"
19 include "mlir/Dialect/Transform/IR/TransformInterfaces.td"
20 include "mlir/Dialect/Transform/IR/TransformTypes.td"
21 include "mlir/IR/OpBase.td"
22 include "mlir/Interfaces/SideEffectInterfaces.td"
24 // Define the new operation. By convention, prefix its name with the name of the dialect
25 // extension, "my.". The full operation name will be further prefixed with "transform.".
26 def ChangeCallTargetOp : Op<Transform_Dialect, "my.change_call_target",
27 // Indicate that the operation implements the required TransformOpInterface and
28 // MemoryEffectsOpInterface. Use the TransformEach trait to provide the
29 // implementation for TransformOpInterface.
30 [TransformOpInterface, TransformEachOpTrait,
31 DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
32 // Provide a brief and a full description. It is recommended that the latter describes
33 // the effects on the operands and how the operation processes various failure modes.
34 let summary = "Changes the callee of a call operation to the specified one";
36 For each `func.call` payload operation associated with the handle, changes its
37 callee to be the symbol whose name is provided as an attribute to this operation.
39 Generates a silenceable failure if the operand is associated with payload operations
40 that are not `func.call`.
41 Only reads the operand.
44 // The arguments include the handle to the payload operations and the attribute that
45 // specifies the new callee. The handle must implement TransformHandleTypeInterface.
46 // We use a string attribute as the symbol may not exist in the transform IR so the
47 // verification may fail.
49 // Specify the type constraint on the input accepting only `func.call` payload
51 Transform_ConcreteOpType<"func.call">:$call,
54 // The results are empty as the transformation does not produce any new payload.
57 // Provide nice syntax.
58 let assemblyFormat = "$call `,` $new_target attr-dict `:` qualified(type($call))";
60 // Declare the function implementing the interface for a single payload operation.
61 let extraClassDeclaration = [{
62 ::mlir::DiagnosedSilenceableFailure applyToOne(
63 ::mlir::transform::TransformRewriter &rewriter,
64 ::mlir::func::CallOp call,
65 ::mlir::transform::ApplyToEachResultList &results,
66 ::mlir::transform::TransformState &state);
70 // Define another transform operation.
71 def CallToOp : Op<Transform_Dialect, "my.call_to_op",
72 // Indicate that the operation implements the required TransformOpInterface.
73 // Use the TransformEach trait to provide implementation of this interface.
74 [TransformOpInterface, TransformEachOpTrait,
75 // Indicate that the operation implements the required MemoryEffectsOpInterface.
76 // Use the FunctionalStyle trait to provide the implementation for this interface.
77 MemoryEffectsOpInterface, FunctionalStyleTransformOpTrait]> {
78 // Summary and description omitted for brevity.
80 // The argument is the handle to the payload operations.
81 let arguments = (ins CallOpInterfaceHandle:$call);
83 // The result is the handle to the payload operations produced during the
85 let results = (outs TransformHandleTypeInterface:$transformed);
87 // Provide nice syntax.
88 let assemblyFormat = "$call attr-dict `:` functional-type(operands, results)";
90 // Declare the function implementing the interface for a single payload operation.
91 let extraClassDeclaration = [{
92 ::mlir::DiagnosedSilenceableFailure applyToOne(
93 ::mlir::transform::TransformRewriter &rewriter,
94 ::mlir::CallOpInterface call,
95 ::mlir::transform::ApplyToEachResultList &results,
96 ::mlir::transform::TransformState &state);
100 #endif // MY_EXTENSION