1 //===- AlgebraicSimplification.cpp - Simplify algebraic expressions -------===// 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 // This file defines a pass that applies algebraic simplifications 9 // to operations of Math/Complex/etc. dialects that are used by Flang. 10 // It is done as a Flang specific pass, because we may want to tune 11 // the parameters of the patterns for Fortran programs. 12 //===----------------------------------------------------------------------===// 13 14 #include "PassDetail.h" 15 #include "flang/Optimizer/Transforms/Passes.h" 16 #include "mlir/Dialect/Math/Transforms/Passes.h" 17 #include "mlir/Transforms/GreedyPatternRewriteDriver.h" 18 19 using namespace mlir; 20 21 namespace { 22 struct AlgebraicSimplification 23 : public fir::AlgebraicSimplificationBase<AlgebraicSimplification> { 24 25 void runOnOperation() override; 26 }; 27 } // namespace 28 runOnOperation()29void AlgebraicSimplification::runOnOperation() { 30 RewritePatternSet patterns(&getContext()); 31 populateMathAlgebraicSimplificationPatterns(patterns); 32 (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)); 33 } 34 createAlgebraicSimplificationPass()35std::unique_ptr<mlir::Pass> fir::createAlgebraicSimplificationPass() { 36 return std::make_unique<AlgebraicSimplification>(); 37 } 38