168ae0d78SAlex Zinenko//===-- MyExtension.td - Transform dialect tutorial --------*- tablegen -*-===// 268ae0d78SAlex Zinenko// 368ae0d78SAlex Zinenko// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 468ae0d78SAlex Zinenko// See https://llvm.org/LICENSE.txt for license information. 568ae0d78SAlex Zinenko// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 668ae0d78SAlex Zinenko// 768ae0d78SAlex Zinenko//===----------------------------------------------------------------------===// 868ae0d78SAlex Zinenko// 968ae0d78SAlex Zinenko// This file defines Transform dialect extension operations used in the 1068ae0d78SAlex Zinenko// Chapter 2 of the Transform dialect tutorial. 1168ae0d78SAlex Zinenko// 1268ae0d78SAlex Zinenko//===----------------------------------------------------------------------===// 1368ae0d78SAlex Zinenko 1468ae0d78SAlex Zinenko#ifndef MY_EXTENSION 1568ae0d78SAlex Zinenko#define MY_EXTENSION 1668ae0d78SAlex Zinenko 1768ae0d78SAlex Zinenkoinclude "mlir/Dialect/Transform/IR/TransformDialect.td" 18*5a9bdd85SOleksandr "Alex" Zinenkoinclude "mlir/Dialect/Transform/Interfaces/TransformInterfaces.td" 1968ae0d78SAlex Zinenkoinclude "mlir/IR/OpBase.td" 2068ae0d78SAlex Zinenkoinclude "mlir/Interfaces/SideEffectInterfaces.td" 2168ae0d78SAlex Zinenko 2268ae0d78SAlex Zinenko// Define the new operation. By convention, prefix its name with the name of the dialect 2368ae0d78SAlex Zinenko// extension, "my.". The full operation name will be further prefixed with "transform.". 2468ae0d78SAlex Zinenkodef ChangeCallTargetOp : Op<Transform_Dialect, "my.change_call_target", 2568ae0d78SAlex Zinenko // Indicate that the operation implements the required TransformOpInterface and 2668ae0d78SAlex Zinenko // MemoryEffectsOpInterface. 2768ae0d78SAlex Zinenko [DeclareOpInterfaceMethods<TransformOpInterface>, 2868ae0d78SAlex Zinenko DeclareOpInterfaceMethods<MemoryEffectsOpInterface>]> { 2968ae0d78SAlex Zinenko // Provide a brief and a full description. It is recommended that the latter describes 3068ae0d78SAlex Zinenko // the effects on the operands and how the operation processes various failure modes. 3168ae0d78SAlex Zinenko let summary = "Changes the callee of a call operation to the specified one"; 3268ae0d78SAlex Zinenko let description = [{ 3368ae0d78SAlex Zinenko For each `func.call` payload operation associated with the handle, changes its 3468ae0d78SAlex Zinenko callee to be the symbol whose name is provided as an attribute to this operation. 3568ae0d78SAlex Zinenko 3668ae0d78SAlex Zinenko Generates a silenceable failure if the operand is associated with payload operations 3768ae0d78SAlex Zinenko that are not `func.call`. 3868ae0d78SAlex Zinenko Only reads the operand. 3968ae0d78SAlex Zinenko }]; 4068ae0d78SAlex Zinenko 4168ae0d78SAlex Zinenko // The arguments include the handle to the payload operations and the attribute that 4268ae0d78SAlex Zinenko // specifies the new callee. The handle must implement TransformHandleTypeInterface. 4368ae0d78SAlex Zinenko // We use a string attribute as the symbol may not exist in the transform IR so the 4468ae0d78SAlex Zinenko // verification may fail. 4568ae0d78SAlex Zinenko let arguments = (ins 4668ae0d78SAlex Zinenko TransformHandleTypeInterface:$call, 4768ae0d78SAlex Zinenko StrAttr:$new_target); 4868ae0d78SAlex Zinenko 4968ae0d78SAlex Zinenko // The results are empty as the transformation does not produce any new payload. 5068ae0d78SAlex Zinenko let results = (outs); 5168ae0d78SAlex Zinenko 5268ae0d78SAlex Zinenko // Provide nice syntax. 5368ae0d78SAlex Zinenko let assemblyFormat = "$call `,` $new_target attr-dict `:` type($call)"; 5468ae0d78SAlex Zinenko} 5568ae0d78SAlex Zinenko 5668ae0d78SAlex Zinenko#endif // MY_EXTENSION 57