[flang-commits] [flang] [Flang][bbc] Prevent bbc -emit-fir command invoking all passes twice (PR #80927)

via flang-commits flang-commits at lists.llvm.org
Tue Feb 6 18:52:10 PST 2024


https://github.com/agozillon created https://github.com/llvm/llvm-project/pull/80927

Currently when the bbc tool is invoked with the emit-fir command the pass pipeline will be invoked twice causing passes added to the pass manager to run twice on the input IR.

This change seeks to prevent that from occuring by only invoking the pass managers run command once and situationally adding the HLFIR to FIR pass pipeline in the same scenario as before.

>From 3fd8e67690e3a10d6000b2a0480a0d62dcf275e9 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon <Andrew.Gozillon at amd.com>
Date: Tue, 6 Feb 2024 20:42:32 -0600
Subject: [PATCH] [Flang][bbc] Prevent bbc -emit-fir command invoking all
 passes twice

Currently when the bbc tool is invoked with the emit-fir command the pass pipeline will be invoked twice causing passes added to the pass manager to
run twice on the input IR.

This change seeks to prevent that from occuring by only invoking the pass
managers run command once and situationally adding the HLFIR to FIR
pass pipeline in the same scenario as before.
---
 flang/tools/bbc/bbc.cpp | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index 98d9258e023e55..68445be28c656f 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -389,18 +389,14 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
     // --emit-fir: Build the IR, verify it, and dump the IR if the IR passes
     // verification. Use --dump-module-on-failure to dump invalid IR.
     pm.addPass(std::make_unique<Fortran::lower::VerifierPass>());
-    if (mlir::failed(pm.run(mlirModule))) {
-      llvm::errs() << "FATAL: verification of lowering to FIR failed";
-      return mlir::failure();
-    }
 
-    if (emitFIR && useHLFIR) {
-      // lower HLFIR to FIR
+    // Add HLFIR to FIR lowering pass
+    if (emitFIR && useHLFIR)
       fir::createHLFIRToFIRPassPipeline(pm, llvm::OptimizationLevel::O2);
-      if (mlir::failed(pm.run(mlirModule))) {
-        llvm::errs() << "FATAL: lowering from HLFIR to FIR failed";
-        return mlir::failure();
-      }
+
+    if (mlir::failed(pm.run(mlirModule))) {
+      llvm::errs() << "FATAL: verification of FIR or HLFIR module failed";
+      return mlir::failure();
     }
 
     printModule(mlirModule, out);



More information about the flang-commits mailing list