1//===- TransformInterfaces.td - Transform Op interfaces ----*- 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 declares the interfaces for transformation-related-ops. 10// 11//===----------------------------------------------------------------------===// 12 13#ifndef MLIR_DIALECT_TRANSFORM_IR_TRANSFORM_INTERFACES_TD 14#define MLIR_DIALECT_TRANSFORM_IR_TRANSFORM_INTERFACES_TD 15 16include "mlir/IR/OpBase.td" 17 18def TransformOpInterface : OpInterface<"TransformOpInterface"> { 19 let description = [{ 20 This interface is to be implemented by operations that identify 21 transformations to be performed on other operations. The former are referred 22 to as transform IR operations. The latter are referred to as payload IR 23 operations. Such transform IR operations provide a fine-grain control 24 mechanism over how transformations are applied by using and defining 25 transform IR values, referred to as handles, that correspond to sets of 26 operations in the payload IR. Transformations are applied starting from the 27 operations identified by handles, but may affect other operations as well. 28 Further restrictions may be imposed by flows that rely on transform IR 29 operations to control transformations. 30 }]; 31 32 let cppNamespace = "::mlir::transform"; 33 34 let methods = [ 35 InterfaceMethod< 36 /*desc=*/[{ 37 Applies the transformation represented by the current operation. This 38 accepts as arguments the object that must be populated with results of 39 the current transformation and a transformation state object that can be 40 used for queries, e.g., to obtain the list of operations on which the 41 transformation represented by the current op is targeted. Returns a 42 special status object indicating whether the transformation succeeded 43 or failed, and, if it failed, whether the failure is recoverable or not. 44 }], 45 /*returnType=*/"::mlir::DiagnosedSilenceableFailure", 46 /*name=*/"apply", 47 /*arguments=*/(ins 48 "::mlir::transform::TransformResults &":$transformResults, 49 "::mlir::transform::TransformState &":$state 50 )>, 51 ]; 52 53 let extraSharedClassDeclaration = [{ 54 /// Emits a generic transform error for the current transform operation 55 /// targeting the given Payload IR operation and returns failure. Should 56 /// be only used as a last resort when the transformation itself provides 57 /// no further indication as to the reason of the failure. 58 ::mlir::LogicalResult reportUnknownTransformError( 59 ::mlir::Operation *target) { 60 ::mlir::InFlightDiagnostic diag = $_op->emitError() << "failed to apply"; 61 diag.attachNote(target->getLoc()) << "attempted to apply to this op"; 62 return diag; 63 } 64 65 /// Creates the silenceable failure object with a diagnostic located at the 66 /// current operation. 67 DiagnosedSilenceableFailure emitSilenceableError() { 68 Diagnostic diag($_op->getLoc(), DiagnosticSeverity::Error); 69 return DiagnosedSilenceableFailure::silenceableFailure(std::move(diag)); 70 } 71 72 /// Creates the default silenceable failure for a transform op that failed 73 /// to properly apply to a target. 74 DiagnosedSilenceableFailure emitDefaultSilenceableFailure( 75 Operation *target) { 76 Diagnostic diag($_op->getLoc(), DiagnosticSeverity::Error); 77 diag << $_op->getName() << " failed to apply"; 78 diag.attachNote(target->getLoc()) << "when applied to this op"; 79 return DiagnosedSilenceableFailure::silenceableFailure(std::move(diag)); 80 } 81 }]; 82} 83 84def FunctionalStyleTransformOpTrait 85 : NativeOpTrait<"FunctionalStyleTransformOpTrait"> { 86 let cppNamespace = "::mlir::transform"; 87} 88 89def TransformEachOpTrait : NativeOpTrait<"TransformEachOpTrait"> { 90 let cppNamespace = "::mlir::transform"; 91} 92 93def NavigationTransformOpTrait : NativeOpTrait<"NavigationTransformOpTrait"> { 94 let cppNamespace = "::mlir::transform"; 95} 96 97#endif // MLIR_DIALECT_TRANSFORM_IR_TRANSFORM_INTERFACES_TD 98