//===- AlgebraicSimplification.cpp - Simplify algebraic expressions -------===// // // 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 implements rewrites based on the basic rules of algebra // (Commutativity, associativity, etc...) and strength reductions for math // operations. // //===----------------------------------------------------------------------===// #include "mlir/Dialect/Arith/IR/Arith.h" #include "mlir/Dialect/Math/IR/Math.h" #include "mlir/Dialect/Math/Transforms/Passes.h" #include "mlir/Dialect/Vector/IR/VectorOps.h" #include "mlir/IR/Builders.h" #include "mlir/IR/Matchers.h" #include "mlir/IR/TypeUtilities.h" #include <climits> usingnamespacemlir; //----------------------------------------------------------------------------// // PowFOp strength reduction. //----------------------------------------------------------------------------// namespace { struct PowFStrengthReduction : public OpRewritePattern<math::PowFOp> { … }; } // namespace LogicalResult PowFStrengthReduction::matchAndRewrite(math::PowFOp op, PatternRewriter &rewriter) const { … } //----------------------------------------------------------------------------// // FPowIOp/IPowIOp strength reduction. //----------------------------------------------------------------------------// namespace { template <typename PowIOpTy, typename DivOpTy, typename MulOpTy> struct PowIStrengthReduction : public OpRewritePattern<PowIOpTy> { … }; } // namespace template <typename PowIOpTy, typename DivOpTy, typename MulOpTy> LogicalResult PowIStrengthReduction<PowIOpTy, DivOpTy, MulOpTy>::matchAndRewrite( PowIOpTy op, PatternRewriter &rewriter) const { … } //----------------------------------------------------------------------------// void mlir::populateMathAlgebraicSimplificationPatterns( RewritePatternSet &patterns) { … }