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

via flang-commits flang-commits at lists.llvm.org
Mon Aug 26 09:34:22 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-driver

Author: None (jeanPerier)

<details>
<summary>Changes</summary>

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).

---
Full diff: https://github.com/llvm/llvm-project/pull/106099.diff


3 Files Affected:

- (modified) flang/lib/Frontend/FrontendActions.cpp (+1) 
- (modified) flang/test/Driver/mlir-debug-pass-pipeline.f90 (+3) 
- (modified) flang/test/Driver/mlir-pass-pipeline.f90 (+3) 


``````````diff
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

``````````

</details>


https://github.com/llvm/llvm-project/pull/106099


More information about the flang-commits mailing list