//===- HomomorphismSimplification.h -----------------------------*- C++ -*-===// // // 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 // //===----------------------------------------------------------------------===// #ifndef MLIR_TRANSFORMS_SIMPLIFY_HOMOMORPHISM_H_ #define MLIR_TRANSFORMS_SIMPLIFY_HOMOMORPHISM_H_ #include "mlir/IR/IRMapping.h" #include "mlir/IR/PatternMatch.h" #include "mlir/IR/Value.h" #include "mlir/Support/LLVM.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Casting.h" #include <iterator> #include <optional> #include <type_traits> #include <utility> namespace mlir { // If `h` is an homomorphism with respect to the source algebraic structure // induced by function `s` and the target algebraic structure induced by // function `t`, transforms `s(h(x1), h(x2) ..., h(xn))` into // `h(t(x1, x2, ..., xn))`. // // Functors: // --------- // `GetHomomorphismOpOperandFn`: `(Operation*) -> OpOperand*` // Returns the operand relevant to the homomorphism. // There may be other operands that are not relevant. // // `GetHomomorphismOpResultFn`: `(Operation*) -> OpResult` // Returns the result relevant to the homomorphism. // // `GetSourceAlgebraicOpOperandsFn`: `(Operation*, SmallVector<OpOperand*>&) -> // void` Populates into the vector the operands relevant to the homomorphism. // // `GetSourceAlgebraicOpResultFn`: `(Operation*) -> OpResult` // Return the result of the source algebraic operation relevant to the // homomorphism. // // `GetTargetAlgebraicOpResultFn`: `(Operation*) -> OpResult` // Return the result of the target algebraic operation relevant to the // homomorphism. // // `IsHomomorphismOpFn`: `(Operation*, std::optional<Operation*>) -> bool` // Check if the operation is an homomorphism of the required type. // Additionally if the optional is present checks if the operations are // compatible homomorphisms. // // `IsSourceAlgebraicOpFn`: `(Operation*) -> bool` // Check if the operation is an operation of the algebraic structure. // // `CreateTargetAlgebraicOpFn`: `(Operation*, IRMapping& operandsRemapping, // PatternRewriter &rewriter) -> Operation*` template <typename GetHomomorphismOpOperandFn, typename GetHomomorphismOpResultFn, typename GetSourceAlgebraicOpOperandsFn, typename GetSourceAlgebraicOpResultFn, typename GetTargetAlgebraicOpResultFn, typename IsHomomorphismOpFn, typename IsSourceAlgebraicOpFn, typename CreateTargetAlgebraicOpFn> struct HomomorphismSimplification : public RewritePattern { … }; } // namespace mlir #endif // MLIR_TRANSFORMS_SIMPLIFY_HOMOMORPHISM_H_