Try 2 to merge 4fbd1d6c87.
Flang algebraic simplification pass will run algebraic simplification
rewrite patterns for Math/Complex/etc. dialects. It is enabled
under opt-for-speed optimization levels (i.e. for O1/O2/O3; Os/Oz will not
enable it).
With this change the FIR/MLIR optimization pipeline becomes affected
by the -O* optimization level switches. Until now these switches
only affected the middle-end and back-end.
Differential Revision: https://reviews.llvm.org/D130035
38 lines
1.4 KiB
C++
38 lines
1.4 KiB
C++
//===- 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 defines a pass that applies algebraic simplifications
|
|
// to operations of Math/Complex/etc. dialects that are used by Flang.
|
|
// It is done as a Flang specific pass, because we may want to tune
|
|
// the parameters of the patterns for Fortran programs.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "PassDetail.h"
|
|
#include "flang/Optimizer/Transforms/Passes.h"
|
|
#include "mlir/Dialect/Math/Transforms/Passes.h"
|
|
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
|
|
|
|
using namespace mlir;
|
|
|
|
namespace {
|
|
struct AlgebraicSimplification
|
|
: public fir::AlgebraicSimplificationBase<AlgebraicSimplification> {
|
|
|
|
void runOnOperation() override;
|
|
};
|
|
} // namespace
|
|
|
|
void AlgebraicSimplification::runOnOperation() {
|
|
RewritePatternSet patterns(&getContext());
|
|
populateMathAlgebraicSimplificationPatterns(patterns);
|
|
(void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns));
|
|
}
|
|
|
|
std::unique_ptr<mlir::Pass> fir::createAlgebraicSimplificationPass() {
|
|
return std::make_unique<AlgebraicSimplification>();
|
|
}
|