xref: /llvm-project/mlir/examples/transform/Ch2/include/MyExtension.td (revision 5a9bdd85ee4d8527e2cedf44f3ce26ff414f9b6a)
1//===-- MyExtension.td - Transform dialect tutorial --------*- tablegen -*-===//
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// This file defines Transform dialect extension operations used in the
10// Chapter 2 of the Transform dialect tutorial.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MY_EXTENSION
15#define MY_EXTENSION
16
17include "mlir/Dialect/Transform/IR/TransformDialect.td"
18include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.td"
19include "mlir/IR/OpBase.td"
20include "mlir/Interfaces/SideEffectInterfaces.td"
21
22// Define the new operation. By convention, prefix its name with the name of the dialect
23// extension, "my.". The full operation name will be further prefixed with "transform.".
24def ChangeCallTargetOp : Op<Transform_Dialect, "my.change_call_target",
25    // Indicate that the operation implements the required TransformOpInterface and
26    // MemoryEffectsOpInterface.
27    [DeclareOpInterfaceMethods<TransformOpInterface>,
28     DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> {
29  // Provide a brief and a full description. It is recommended that the latter describes
30  // the effects on the operands and how the operation processes various failure modes.
31  let summary = "Changes the callee of a call operation to the specified one";
32  let description = [{
33    For each `func.call` payload operation associated with the handle, changes its
34    callee to be the symbol whose name is provided as an attribute to this operation.
35
36    Generates a silenceable failure if the operand is associated with payload operations
37    that are not `func.call`.
38    Only reads the operand.
39  }];
40
41  // The arguments include the handle to the payload operations and the attribute that
42  // specifies the new callee. The handle must implement TransformHandleTypeInterface.
43  // We use a string attribute as the symbol may not exist in the transform IR so the
44  // verification may fail.
45  let arguments = (ins
46    TransformHandleTypeInterface:$call,
47    StrAttr:$new_target);
48
49  // The results are empty as the transformation does not produce any new payload.
50  let results = (outs);
51
52  // Provide nice syntax.
53  let assemblyFormat = "$call `,` $new_target attr-dict `:` type($call)";
54}
55
56#endif // MY_EXTENSION
57