Skip to content

Commit

Permalink
[Flang][bbc] Prevent bbc -emit-fir command invoking OpenMP passes twi…
Browse files Browse the repository at this point in the history
…ce (#80927)

Currently when the bbc tool is invoked with the emit-fir command the pass pipeline will be invoked twice for verification causing the previously added OpenMP pass pipeline to be invoked multiple times.

This change seeks to prevent that from occurring by using a seperate pass manager and run command immediately when it is necessary for the OpenMP passes to be executed.
  • Loading branch information
agozillon committed Feb 8, 2024
1 parent 6ea76c1 commit ec1fcb3
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions flang/tools/bbc/bbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,22 @@ createTargetMachine(llvm::StringRef targetTriple, std::string &error) {
/*Reloc::Model=*/std::nullopt)};
}

/// Build and execute the OpenMPFIRPassPipeline with its own instance
/// of the pass manager, allowing it to be invoked as soon as it's
/// required without impacting the main pass pipeline that may be invoked
/// more than once for verification.
static mlir::LogicalResult runOpenMPPasses(mlir::ModuleOp mlirModule) {
mlir::PassManager pm(mlirModule->getName(),
mlir::OpPassManager::Nesting::Implicit);
fir::createOpenMPFIRPassPipeline(pm, enableOpenMPDevice);
(void)mlir::applyPassManagerCLOptions(pm);
if (mlir::failed(pm.run(mlirModule))) {
llvm::errs() << "FATAL: failed to correctly apply OpenMP pass pipeline";
return mlir::failure();
}
return mlir::success();
}

//===----------------------------------------------------------------------===//
// Translate Fortran input to FIR, a dialect of MLIR.
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -369,14 +385,16 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
"could not open output file ")
<< outputName;

// WARNING: This pipeline must be run immediately after the lowering to
// ensure that the FIR is correct with respect to OpenMP operations/
// attributes.
if (enableOpenMP)
if (mlir::failed(runOpenMPPasses(mlirModule)))
return mlir::failure();

// Otherwise run the default passes.
mlir::PassManager pm(mlirModule->getName(),
mlir::OpPassManager::Nesting::Implicit);
if (enableOpenMP)
// WARNING: This pipeline must be run immediately after the lowering to
// ensure that the FIR is correct with respect to OpenMP operations/
// attributes.
fir::createOpenMPFIRPassPipeline(pm, enableOpenMPDevice);
pm.enableVerifier(/*verifyPasses=*/true);
(void)mlir::applyPassManagerCLOptions(pm);
if (passPipeline.hasAnyOccurrences()) {
Expand Down

0 comments on commit ec1fcb3

Please sign in to comment.