[flang-commits] [flang] 0ea0ecd - [flang][driver] apply mlir pass options immediately after lowering (#106099)

via flang-commits flang-commits at lists.llvm.org
Tue Aug 27 02:05:17 PDT 2024


Author: jeanPerier
Date: 2024-08-27T11:05:13+02:00
New Revision: 0ea0ecd64f54e307670b860b309d2e869c1de3d1

URL: https://github.com/llvm/llvm-project/commit/0ea0ecd64f54e307670b860b309d2e869c1de3d1
DIFF: https://github.com/llvm/llvm-project/commit/0ea0ecd64f54e307670b860b309d2e869c1de3d1.diff

LOG: [flang][driver] apply mlir pass options immediately after lowering (#106099)

The verification pass is run right after lowering with its own pass
manager by flang driver, but the mlir command line options were not
applied to this pass manager.

This prevented options like `-mmlir
--mlir-pass-pipeline-crash-reproducer="crash.fir"` or `-mmlir
--mlir-print-ir-after-failure` to work when a verifier error was hit
right after lowering, while these options are useful to
investigate/reproduce internal errors.

Note that the change in the pipeline tests is not showing a new pass
being run: the pass was already run, but `-mmlir --mlir-pass-statistics`
was not applied when the initial verification pass was run.

Note that when we deal with compiler performance, we will probably want
to run the verification pass only once after the initial lowering (this
patch shows that it is called twice in a raw: once after the initial
lowering, once at the beginning of FIR to LLVM IR lowering).

Added: 
    flang/test/Driver/mmlir-opts-vs-opts.f90

Modified: 
    flang/lib/Frontend/FrontendActions.cpp
    flang/test/Driver/mlir-debug-pass-pipeline.f90
    flang/test/Driver/mlir-pass-pipeline.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 5c86bd947ce73f..c9991ff18d1754 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -323,6 +323,7 @@ bool CodeGenAction::beginSourceFileAction() {
   // run the default passes.
   mlir::PassManager pm((*mlirModule)->getName(),
                        mlir::OpPassManager::Nesting::Implicit);
+  (void)mlir::applyPassManagerCLOptions(pm);
   // Add OpenMP-related passes
   // WARNING: These passes must be run immediately after the lowering to ensure
   // that the FIR is correct with respect to OpenMP operations/attributes.

diff  --git a/flang/test/Driver/mlir-debug-pass-pipeline.f90 b/flang/test/Driver/mlir-debug-pass-pipeline.f90
index a6316ee7c83123..e44f4e62a7148b 100644
--- a/flang/test/Driver/mlir-debug-pass-pipeline.f90
+++ b/flang/test/Driver/mlir-debug-pass-pipeline.f90
@@ -22,6 +22,9 @@
 ! DEBUG-ERR: error: invalid value 'invalid' in '-debug-info-kind=invalid'
 ! DEBUG-ERR-NOT: Pass statistics report
 
+! ALL: Pass statistics report
+! ALL: Fortran::lower::VerifierPass
+
 ! ALL: Pass statistics report
 
 ! ALL: Fortran::lower::VerifierPass

diff  --git a/flang/test/Driver/mlir-pass-pipeline.f90 b/flang/test/Driver/mlir-pass-pipeline.f90
index 2f35f928e99cfc..6c2829d3cc5c57 100644
--- a/flang/test/Driver/mlir-pass-pipeline.f90
+++ b/flang/test/Driver/mlir-pass-pipeline.f90
@@ -9,6 +9,9 @@
 
 end program
 
+! ALL: Pass statistics report
+! ALL: Fortran::lower::VerifierPass
+
 ! ALL: Pass statistics report
 
 ! ALL: Fortran::lower::VerifierPass

diff  --git a/flang/test/Driver/mmlir-opts-vs-opts.f90 b/flang/test/Driver/mmlir-opts-vs-opts.f90
new file mode 100644
index 00000000000000..8cd14e02c3fcc9
--- /dev/null
+++ b/flang/test/Driver/mmlir-opts-vs-opts.f90
@@ -0,0 +1,8 @@
+! Verify that mlir pass options are only accessible under `-mmlir`.
+
+!RUN: %flang_fc1 -emit-hlfir -mmlir -mlir-pass-statistics %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=MMLIR
+!RUN: not %flang_fc1 -emit-hlfir -mlir-pass-statistics %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=NOMMLIR
+
+!MMLIR: Pass statistics report
+!NOMMLIR: error: unknown argument: '-mlir-pass-statistics'
+end


        


More information about the flang-commits mailing list