Skip to content

Commit 3fd8e67

Browse files
committed
[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.
1 parent 9ea34be commit 3fd8e67

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

flang/tools/bbc/bbc.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -389,18 +389,14 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
389389
// --emit-fir: Build the IR, verify it, and dump the IR if the IR passes
390390
// verification. Use --dump-module-on-failure to dump invalid IR.
391391
pm.addPass(std::make_unique<Fortran::lower::VerifierPass>());
392-
if (mlir::failed(pm.run(mlirModule))) {
393-
llvm::errs() << "FATAL: verification of lowering to FIR failed";
394-
return mlir::failure();
395-
}
396392

397-
if (emitFIR && useHLFIR) {
398-
// lower HLFIR to FIR
393+
// Add HLFIR to FIR lowering pass
394+
if (emitFIR && useHLFIR)
399395
fir::createHLFIRToFIRPassPipeline(pm, llvm::OptimizationLevel::O2);
400-
if (mlir::failed(pm.run(mlirModule))) {
401-
llvm::errs() << "FATAL: lowering from HLFIR to FIR failed";
402-
return mlir::failure();
403-
}
396+
397+
if (mlir::failed(pm.run(mlirModule))) {
398+
llvm::errs() << "FATAL: verification of FIR or HLFIR module failed";
399+
return mlir::failure();
404400
}
405401

406402
printModule(mlirModule, out);

0 commit comments

Comments
 (0)