Skip to content

Commit ec1fcb3

Browse files
authored
[Flang][bbc] Prevent bbc -emit-fir command invoking OpenMP passes twice (#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.
1 parent 6ea76c1 commit ec1fcb3

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

flang/tools/bbc/bbc.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,22 @@ createTargetMachine(llvm::StringRef targetTriple, std::string &error) {
256256
/*Reloc::Model=*/std::nullopt)};
257257
}
258258

259+
/// Build and execute the OpenMPFIRPassPipeline with its own instance
260+
/// of the pass manager, allowing it to be invoked as soon as it's
261+
/// required without impacting the main pass pipeline that may be invoked
262+
/// more than once for verification.
263+
static mlir::LogicalResult runOpenMPPasses(mlir::ModuleOp mlirModule) {
264+
mlir::PassManager pm(mlirModule->getName(),
265+
mlir::OpPassManager::Nesting::Implicit);
266+
fir::createOpenMPFIRPassPipeline(pm, enableOpenMPDevice);
267+
(void)mlir::applyPassManagerCLOptions(pm);
268+
if (mlir::failed(pm.run(mlirModule))) {
269+
llvm::errs() << "FATAL: failed to correctly apply OpenMP pass pipeline";
270+
return mlir::failure();
271+
}
272+
return mlir::success();
273+
}
274+
259275
//===----------------------------------------------------------------------===//
260276
// Translate Fortran input to FIR, a dialect of MLIR.
261277
//===----------------------------------------------------------------------===//
@@ -369,14 +385,16 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
369385
"could not open output file ")
370386
<< outputName;
371387

388+
// WARNING: This pipeline must be run immediately after the lowering to
389+
// ensure that the FIR is correct with respect to OpenMP operations/
390+
// attributes.
391+
if (enableOpenMP)
392+
if (mlir::failed(runOpenMPPasses(mlirModule)))
393+
return mlir::failure();
394+
372395
// Otherwise run the default passes.
373396
mlir::PassManager pm(mlirModule->getName(),
374397
mlir::OpPassManager::Nesting::Implicit);
375-
if (enableOpenMP)
376-
// WARNING: This pipeline must be run immediately after the lowering to
377-
// ensure that the FIR is correct with respect to OpenMP operations/
378-
// attributes.
379-
fir::createOpenMPFIRPassPipeline(pm, enableOpenMPDevice);
380398
pm.enableVerifier(/*verifyPasses=*/true);
381399
(void)mlir::applyPassManagerCLOptions(pm);
382400
if (passPipeline.hasAnyOccurrences()) {

0 commit comments

Comments
 (0)