Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[flang] Run algebraic simplification optimization pass.
Try 2 to merge 4fbd1d6. 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
- Loading branch information
Showing
14 changed files
with
237 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
flang/lib/Optimizer/Transforms/AlgebraicSimplification.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//===- 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>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
! Test the MLIR pass pipeline | ||
|
||
! RUN: bbc --mlir-pass-statistics --mlir-pass-statistics-display=pipeline %s 2>&1 | FileCheck %s | ||
end program | ||
|
||
! CHECK: Pass statistics report | ||
|
||
! CHECK: Fortran::lower::VerifierPass | ||
! CHECK-NEXT: CSE | ||
! Ideally, we need an output with only the pass names, but | ||
! there is currently no way to get that, so in order to | ||
! guarantee that the passes are in the expected order | ||
! (i.e. use -NEXT) we have to check the statistics output as well. | ||
! CHECK-NEXT: (S) 0 num-cse'd - Number of operations CSE'd | ||
! CHECK-NEXT: (S) 0 num-dce'd - Number of operations DCE'd | ||
|
||
! CHECK-NEXT: 'func.func' Pipeline | ||
! CHECK-NEXT: ArrayValueCopy | ||
! CHECK-NEXT: CharacterConversion | ||
|
||
! CHECK-NEXT: Canonicalizer | ||
! CHECK-NEXT: SimplifyRegionLite | ||
! CHECK-NEXT: AlgebraicSimplification | ||
! CHECK-NEXT: CSE | ||
! CHECK-NEXT: (S) 0 num-cse'd - Number of operations CSE'd | ||
! CHECK-NEXT: (S) 0 num-dce'd - Number of operations DCE'd | ||
|
||
! CHECK-NEXT: 'func.func' Pipeline | ||
! CHECK-NEXT: MemoryAllocationOpt | ||
|
||
! CHECK-NEXT: Inliner | ||
! CHECK-NEXT: CSE | ||
! CHECK-NEXT: (S) 0 num-cse'd - Number of operations CSE'd | ||
! CHECK-NEXT: (S) 0 num-dce'd - Number of operations DCE'd | ||
|
||
! CHECK-NEXT: 'func.func' Pipeline | ||
! CHECK-NEXT: CFGConversion | ||
|
||
! CHECK-NEXT: SCFToControlFlow | ||
! CHECK-NEXT: Canonicalizer | ||
! CHECK-NEXT: SimplifyRegionLite | ||
! CHECK-NEXT: CSE | ||
! CHECK-NEXT: (S) 0 num-cse'd - Number of operations CSE'd | ||
! CHECK-NEXT: (S) 0 num-dce'd - Number of operations DCE'd | ||
! CHECK-NOT: LLVMIRLoweringPass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,61 @@ | ||
! Test the MLIR pass pipeline | ||
|
||
! RUN: %flang_fc1 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -o - 2>&1 | FileCheck %s | ||
! RUN: %flang_fc1 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline -o /dev/null %s 2>&1 | FileCheck --check-prefixes=ALL %s | ||
! -O0 is the default: | ||
! RUN: %flang_fc1 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -O0 -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL %s | ||
! RUN: %flang_fc1 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -O2 -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,O2 %s | ||
|
||
! REQUIRES: asserts | ||
|
||
end program | ||
|
||
! CHECK: Pass statistics report | ||
|
||
! CHECK: CSE | ||
! CHECK-LABEL: 'func.func' Pipeline | ||
! CHECK: ArrayValueCopy | ||
! CHECK: CharacterConversion | ||
! CHECK: Canonicalizer | ||
! CHECK: SimplifyRegionLite | ||
! CHECK: CSE | ||
|
||
! CHECK-LABEL: 'func.func' Pipeline | ||
! CHECK: MemoryAllocationOpt | ||
! CHECK: Inliner | ||
! CHECK: CSE | ||
|
||
! CHECK-LABEL: 'func.func' Pipeline | ||
! CHECK: CFGConversion | ||
! CHECK: SCFToControlFlow | ||
! CHECK: Canonicalizer | ||
! CHECK: SimplifyRegionLite | ||
! CHECK: CSE | ||
! CHECK: BoxedProcedurePass | ||
|
||
! CHECK-LABEL: 'func.func' Pipeline | ||
! CHECK: AbstractResultOpt | ||
! CHECK: CodeGenRewrite | ||
! CHECK: TargetRewrite | ||
! CHECK: ExternalNameConversion | ||
! CHECK: FIRToLLVMLowering | ||
! CHECK-NOT: LLVMIRLoweringPass | ||
! ALL: Pass statistics report | ||
|
||
! ALL: Fortran::lower::VerifierPass | ||
! ALL-NEXT: CSE | ||
! Ideally, we need an output with only the pass names, but | ||
! there is currently no way to get that, so in order to | ||
! guarantee that the passes are in the expected order | ||
! (i.e. use -NEXT) we have to check the statistics output as well. | ||
! ALL-NEXT: (S) 0 num-cse'd - Number of operations CSE'd | ||
! ALL-NEXT: (S) 0 num-dce'd - Number of operations DCE'd | ||
|
||
! ALL-NEXT: 'func.func' Pipeline | ||
! ALL-NEXT: ArrayValueCopy | ||
! ALL-NEXT: CharacterConversion | ||
|
||
! ALL-NEXT: Canonicalizer | ||
! ALL-NEXT: SimplifyRegionLite | ||
! O2-NEXT: AlgebraicSimplification | ||
! ALL-NEXT: CSE | ||
! ALL-NEXT: (S) 0 num-cse'd - Number of operations CSE'd | ||
! ALL-NEXT: (S) 0 num-dce'd - Number of operations DCE'd | ||
|
||
! ALL-NEXT: 'func.func' Pipeline | ||
! ALL-NEXT: MemoryAllocationOpt | ||
|
||
! ALL-NEXT: Inliner | ||
! ALL-NEXT: CSE | ||
! ALL-NEXT: (S) 0 num-cse'd - Number of operations CSE'd | ||
! ALL-NEXT: (S) 0 num-dce'd - Number of operations DCE'd | ||
|
||
! ALL-NEXT: 'func.func' Pipeline | ||
! ALL-NEXT: CFGConversion | ||
|
||
! ALL-NEXT: SCFToControlFlow | ||
! ALL-NEXT: Canonicalizer | ||
! ALL-NEXT: SimplifyRegionLite | ||
! ALL-NEXT: CSE | ||
! ALL-NEXT: (S) 0 num-cse'd - Number of operations CSE'd | ||
! ALL-NEXT: (S) 0 num-dce'd - Number of operations DCE'd | ||
! ALL-NEXT: BoxedProcedurePass | ||
|
||
! ALL-NEXT: 'func.func' Pipeline | ||
! ALL-NEXT: AbstractResultOpt | ||
|
||
! ALL-NEXT: CodeGenRewrite | ||
! ALL-NEXT: (S) 0 num-dce'd - Number of operations eliminated | ||
! ALL-NEXT: TargetRewrite | ||
! ALL-NEXT: ExternalNameConversion | ||
! ALL-NEXT: FIRToLLVMLowering | ||
! ALL-NOT: LLVMIRLoweringPass |
Oops, something went wrong.