//===-- MyExtension.cpp - Transform dialect tutorial ----------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines Transform dialect extension operations used in the // Chapter 4 of the Transform dialect tutorial. // //===----------------------------------------------------------------------===// #include "MyExtension.h" #include "mlir/Dialect/Transform/IR/TransformDialect.h" #include "llvm/Support/Debug.h" #define DEBUG_TYPE_MATCHER … #define DBGS_MATCHER() … #define DEBUG_MATCHER(x) … #define GET_OP_CLASSES #include "MyExtension.cpp.inc" //===---------------------------------------------------------------------===// // MyExtension //===---------------------------------------------------------------------===// // Define a new transform dialect extension. This uses the CRTP idiom to // identify extensions. class MyExtension : public ::mlir::transform::TransformDialectExtension<MyExtension> { … }; void MyExtension::init() { … } //===---------------------------------------------------------------------===// // HasOperandSatisfyingOp //===---------------------------------------------------------------------===// /// Returns `true` if both types implement one of the interfaces provided as /// template parameters. template <typename... Tys> static bool implementSameInterface(mlir::Type t1, mlir::Type t2) { … } /// Returns `true` if both types implement one of the transform dialect /// interfaces. static bool implementSameTransformInterface(mlir::Type t1, mlir::Type t2) { … } // Matcher ops implement `apply` similarly to other transform ops. They are not // expected to modify payload, but use the tri-state result to signal failure or // success to match, as well as potential irrecoverable errors. mlir::DiagnosedSilenceableFailure mlir::transform::HasOperandSatisfyingOp::apply( mlir::transform::TransformRewriter &rewriter, mlir::transform::TransformResults &results, mlir::transform::TransformState &state) { … } // By convention, operations implementing MatchOpInterface must not modify // payload IR and must therefore specify that they only read operand handles and // payload as their effects. void mlir::transform::HasOperandSatisfyingOp::getEffects( llvm::SmallVectorImpl<mlir::MemoryEffects::EffectInstance> &effects) { … } // Verify well-formedness of the operation and emit diagnostics if it is // ill-formed. llvm::LogicalResult mlir::transform::HasOperandSatisfyingOp::verify() { … } void registerMyExtension(::mlir::DialectRegistry ®istry) { … }