[lldb] Add ability to hide the root name of a value
[llvm-project.git] / flang / lib / Optimizer / Transforms / AlgebraicSimplification.cpp
blobfd58375da618a9e72261573192013f4c4b8d0ca6
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 //===----------------------------------------------------------------------===//
14 #include "flang/Optimizer/Transforms/Passes.h"
15 #include "mlir/Dialect/Math/IR/Math.h"
16 #include "mlir/Dialect/Math/Transforms/Passes.h"
17 #include "mlir/Transforms/GreedyPatternRewriteDriver.h"
19 namespace fir {
20 #define GEN_PASS_DEF_ALGEBRAICSIMPLIFICATION
21 #include "flang/Optimizer/Transforms/Passes.h.inc"
22 } // namespace fir
24 using namespace mlir;
26 namespace {
27 struct AlgebraicSimplification
28 : public fir::impl::AlgebraicSimplificationBase<AlgebraicSimplification> {
29 AlgebraicSimplification(const GreedyRewriteConfig &rewriteConfig) {
30 config = rewriteConfig;
33 void runOnOperation() override;
35 mlir::GreedyRewriteConfig config;
37 } // namespace
39 void AlgebraicSimplification::runOnOperation() {
40 RewritePatternSet patterns(&getContext());
41 populateMathAlgebraicSimplificationPatterns(patterns);
42 (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns),
43 config);
46 std::unique_ptr<mlir::Pass> fir::createAlgebraicSimplificationPass() {
47 return std::make_unique<AlgebraicSimplification>(GreedyRewriteConfig());
50 std::unique_ptr<mlir::Pass> fir::createAlgebraicSimplificationPass(
51 const mlir::GreedyRewriteConfig &config) {
52 return std::make_unique<AlgebraicSimplification>(config);