brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · fab1f02 Raw
53 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8// This file defines a pass that applies algebraic simplifications9// 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 tune11// the parameters of the patterns for Fortran programs.12//===----------------------------------------------------------------------===//13 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"18 19namespace fir {20#define GEN_PASS_DEF_ALGEBRAICSIMPLIFICATION21#include "flang/Optimizer/Transforms/Passes.h.inc"22} // namespace fir23 24using namespace mlir;25 26namespace {27struct AlgebraicSimplification28    : public fir::impl::AlgebraicSimplificationBase<AlgebraicSimplification> {29  AlgebraicSimplification(const GreedyRewriteConfig &rewriteConfig) {30    config = rewriteConfig;31  }32 33  void runOnOperation() override;34 35  mlir::GreedyRewriteConfig config;36};37} // namespace38 39void AlgebraicSimplification::runOnOperation() {40  RewritePatternSet patterns(&getContext());41  populateMathAlgebraicSimplificationPatterns(patterns);42  (void)applyPatternsGreedily(getOperation(), std::move(patterns), config);43}44 45std::unique_ptr<mlir::Pass> fir::createAlgebraicSimplificationPass() {46  return std::make_unique<AlgebraicSimplification>(GreedyRewriteConfig());47}48 49std::unique_ptr<mlir::Pass> fir::createAlgebraicSimplificationPass(50    const mlir::GreedyRewriteConfig &config) {51  return std::make_unique<AlgebraicSimplification>(config);52}53