[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:32:35 PDT 2024


https://github.com/jeanPerier created https://github.com/llvm/llvm-project/pull/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).

>From 2bc3a67871e9d49181c21b1fb1a84e98248ee582 Mon Sep 17 00:00:00 2001
From: Jean Perier <jperier at nvidia.com>
Date: Mon, 26 Aug 2024 09:18:34 -0700
Subject: [PATCH] [flang][driver] apply mlir pass option after lowering

---
 flang/lib/Frontend/FrontendActions.cpp         | 1 +
 flang/test/Driver/mlir-debug-pass-pipeline.f90 | 3 +++
 flang/test/Driver/mlir-pass-pipeline.f90       | 3 +++
 3 files changed, 7 insertions(+)

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



More information about the flang-commits mailing list