[flang-commits] [flang] 4dece40 - [flang] Pass the pipeline config to the pass

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Tue Aug 9 07:05:39 PDT 2022


Author: Valentin Clement
Date: 2022-08-09T16:05:34+02:00
New Revision: 4dece4007cc2fb261f29d14287836e28a355810a

URL: https://github.com/llvm/llvm-project/commit/4dece4007cc2fb261f29d14287836e28a355810a
DIFF: https://github.com/llvm/llvm-project/commit/4dece4007cc2fb261f29d14287836e28a355810a.diff

LOG: [flang] Pass the pipeline config to the pass

The newly added AlgebraicSimplification pass is triggering the
greedy pattern rewriter. Since we define a specific config in the
flang pipeline, this patch adds the ability to pass the config
to the pass directly.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D131474

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Transforms/Passes.h
    flang/include/flang/Tools/CLOptions.inc
    flang/lib/Optimizer/Transforms/AlgebraicSimplification.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Transforms/Passes.h b/flang/include/flang/Optimizer/Transforms/Passes.h
index e6e2bbbda83e..2835f3e310cd 100644
--- 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 @@ createMemoryAllocationPass(bool dynOnHeap, std::size_t maxStackSize);
 std::unique_ptr<mlir::Pass> createAnnotateConstantOperandsPass();
 std::unique_ptr<mlir::Pass> createSimplifyRegionLitePass();
 std::unique_ptr<mlir::Pass> createAlgebraicSimplificationPass();
+std::unique_ptr<mlir::Pass>
+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
index fd770fe542f4..97bdddbfc38a 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -167,7 +167,7 @@ inline void createDefaultFIROptimizerPassPipeline(
   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
index 25a6a8d47f27..607ba590316c 100644
--- a/flang/lib/Optimizer/Transforms/AlgebraicSimplification.cpp
+++ b/flang/lib/Optimizer/Transforms/AlgebraicSimplification.cpp
@@ -21,17 +21,28 @@ using namespace mlir;
 namespace {
 struct AlgebraicSimplification
     : public fir::AlgebraicSimplificationBase<AlgebraicSimplification> {
+  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<mlir::Pass> fir::createAlgebraicSimplificationPass() {
-  return std::make_unique<AlgebraicSimplification>();
+  return std::make_unique<AlgebraicSimplification>(GreedyRewriteConfig());
+}
+
+std::unique_ptr<mlir::Pass> fir::createAlgebraicSimplificationPass(
+    const mlir::GreedyRewriteConfig &config) {
+  return std::make_unique<AlgebraicSimplification>(config);
 }


        


More information about the flang-commits mailing list