diff --git a/flang/include/flang/Optimizer/Transforms/Passes.h b/flang/include/flang/Optimizer/Transforms/Passes.h --- a/flang/include/flang/Optimizer/Transforms/Passes.h +++ b/flang/include/flang/Optimizer/Transforms/Passes.h @@ -15,6 +15,7 @@ namespace mlir { class BlockAndValueMapping; +class GreedyRewriteConfig; class Operation; class Pass; class Region; @@ -42,6 +43,8 @@ std::unique_ptr createAnnotateConstantOperandsPass(); std::unique_ptr createSimplifyRegionLitePass(); std::unique_ptr createAlgebraicSimplificationPass(); +std::unique_ptr +createAlgebraicSimplificationPass(const mlir::GreedyRewriteConfig &config); // declarative passes #define GEN_PASS_REGISTRATION diff --git a/flang/include/flang/Tools/CLOptions.inc b/flang/include/flang/Tools/CLOptions.inc --- a/flang/include/flang/Tools/CLOptions.inc +++ b/flang/include/flang/Tools/CLOptions.inc @@ -167,7 +167,7 @@ pm.addPass(fir::createSimplifyRegionLitePass()); // Algebraic simplifications may increase code size. if (optLevel.isOptimizingForSpeed()) - pm.addPass(fir::createAlgebraicSimplificationPass()); + pm.addPass(fir::createAlgebraicSimplificationPass(config)); pm.addPass(mlir::createCSEPass()); fir::addMemoryAllocationOpt(pm); diff --git a/flang/lib/Optimizer/Transforms/AlgebraicSimplification.cpp b/flang/lib/Optimizer/Transforms/AlgebraicSimplification.cpp --- a/flang/lib/Optimizer/Transforms/AlgebraicSimplification.cpp +++ b/flang/lib/Optimizer/Transforms/AlgebraicSimplification.cpp @@ -21,17 +21,28 @@ namespace { struct AlgebraicSimplification : public fir::AlgebraicSimplificationBase { + AlgebraicSimplification(const GreedyRewriteConfig &rewriteConfig) { + config = rewriteConfig; + } void runOnOperation() override; + + mlir::GreedyRewriteConfig config; }; } // namespace void AlgebraicSimplification::runOnOperation() { RewritePatternSet patterns(&getContext()); populateMathAlgebraicSimplificationPatterns(patterns); - (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)); + (void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns), + config); } std::unique_ptr fir::createAlgebraicSimplificationPass() { - return std::make_unique(); + return std::make_unique(GreedyRewriteConfig()); +} + +std::unique_ptr fir::createAlgebraicSimplificationPass( + const mlir::GreedyRewriteConfig &config) { + return std::make_unique(config); }