101 lines · plain
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file defines Transform dialect extension operations used in the10// Chapter 3 of the Transform dialect tutorial.11//12//===----------------------------------------------------------------------===//13 14#ifndef MY_EXTENSION15#define MY_EXTENSION16 17include "MyExtensionTypes.td"18include "mlir/Dialect/Transform/IR/TransformDialect.td"19include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.td"20include "mlir/Dialect/Transform/IR/TransformTypes.td"21include "mlir/IR/OpBase.td"22include "mlir/Interfaces/SideEffectInterfaces.td"23 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.".26def ChangeCallTargetOp : Op<Transform_Dialect, "my.change_call_target",27 // Indicate that the operation implements the required TransformOpInterface and28 // 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";35 let description = [{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.38 39 Generates a silenceable failure if the operand is associated with payload operations 40 that are not `func.call`.41 Only reads the operand.42 }];43 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. 48 let arguments = (ins49 // Allow the handle to be to concrete func.call ops as well as any op implementing50 // the CallOpInterface.51 AnyTypeOf<[Transform_ConcreteOpType<"func.call">, CallOpInterfaceHandle]>:$call,52 StrAttr:$new_target);53 54 // The results are empty as the transformation does not produce any new payload.55 let results = (outs);56 57 // Provide nice syntax.58 let assemblyFormat = "$call `,` $new_target attr-dict `:` qualified(type($call))";59 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);67 }];68}69 70// Define another transform operation.71def 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.79 80 // The argument is the handle to the payload operations.81 let arguments = (ins CallOpInterfaceHandle:$call);82 83 // The result is the handle to the payload operations produced during the 84 // transformation.85 let results = (outs TransformHandleTypeInterface:$transformed);86 87 // Provide nice syntax.88 let assemblyFormat = "$call attr-dict `:` functional-type(operands, results)";89 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);97 }];98}99 100#endif // MY_EXTENSION101