Skip to content

Commit 7395392

Browse files
committed
Only run the lower workshare pass if openmp is enabled
1 parent 0a35b4c commit 7395392

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

flang/include/flang/Tools/CLOptions.inc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ inline void createDefaultFIROptimizerPassPipeline(
328328
/// \param optLevel - optimization level used for creating FIR optimization
329329
/// passes pipeline
330330
inline void createHLFIRToFIRPassPipeline(
331-
mlir::PassManager &pm, llvm::OptimizationLevel optLevel = defaultOptLevel) {
331+
mlir::PassManager &pm, bool enableOpenMP, llvm::OptimizationLevel optLevel = defaultOptLevel) {
332332
if (optLevel.isOptimizingForSpeed()) {
333333
addCanonicalizerPassWithoutRegionSimplification(pm);
334334
addNestedPassToAllTopLevelOperations(
@@ -345,7 +345,8 @@ inline void createHLFIRToFIRPassPipeline(
345345
pm.addPass(hlfir::createLowerHLFIRIntrinsics());
346346
pm.addPass(hlfir::createBufferizeHLFIR());
347347
pm.addPass(hlfir::createConvertHLFIRtoFIR());
348-
pm.addPass(flangomp::createLowerWorkshare());
348+
if (enableOpenMP)
349+
pm.addPass(flangomp::createLowerWorkshare());
349350
}
350351

351352
/// Create a pass pipeline for handling certain OpenMP transformations needed
@@ -416,7 +417,7 @@ inline void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
416417
/// passes pipeline
417418
inline void createMLIRToLLVMPassPipeline(mlir::PassManager &pm,
418419
MLIRToLLVMPassPipelineConfig &config, llvm::StringRef inputFilename = {}) {
419-
fir::createHLFIRToFIRPassPipeline(pm, config.OptLevel);
420+
fir::createHLFIRToFIRPassPipeline(pm, config.EnableOpenMP, config.OptLevel);
420421

421422
// Add default optimizer pass pipeline.
422423
fir::createDefaultFIROptimizerPassPipeline(pm, config);

flang/include/flang/Tools/CrossToolHelpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks {
123123
false; ///< Set no-signed-zeros-fp-math attribute for functions.
124124
bool UnsafeFPMath = false; ///< Set unsafe-fp-math attribute for functions.
125125
bool NSWOnLoopVarInc = false; ///< Add nsw flag to loop variable increments.
126+
bool EnableOpenMP = false; ///< Enable OpenMP lowering.
126127
};
127128

128129
struct OffloadModuleOpts {

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,11 @@ void CodeGenAction::lowerHLFIRToFIR() {
711711
pm.enableVerifier(/*verifyPasses=*/true);
712712

713713
// Create the pass pipeline
714-
fir::createHLFIRToFIRPassPipeline(pm, level);
714+
fir::createHLFIRToFIRPassPipeline(
715+
pm,
716+
ci.getInvocation().getFrontendOpts().features.IsEnabled(
717+
Fortran::common::LanguageFeature::OpenMP),
718+
level);
715719
(void)mlir::applyPassManagerCLOptions(pm);
716720

717721
if (!mlir::succeeded(pm.run(*mlirModule))) {
@@ -824,6 +828,10 @@ void CodeGenAction::generateLLVMIR() {
824828
config.VScaleMax = vsr->second;
825829
}
826830

831+
if (ci.getInvocation().getFrontendOpts().features.IsEnabled(
832+
Fortran::common::LanguageFeature::OpenMP))
833+
config.EnableOpenMP = true;
834+
827835
if (ci.getInvocation().getLoweringOpts().getNSWOnLoopVarInc())
828836
config.NSWOnLoopVarInc = true;
829837

flang/tools/bbc/bbc.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ static llvm::LogicalResult convertFortranSourceToMLIR(
429429

430430
if (emitFIR && useHLFIR) {
431431
// lower HLFIR to FIR
432-
fir::createHLFIRToFIRPassPipeline(pm, llvm::OptimizationLevel::O2);
432+
fir::createHLFIRToFIRPassPipeline(pm, enableOpenMP,
433+
llvm::OptimizationLevel::O2);
433434
if (mlir::failed(pm.run(mlirModule))) {
434435
llvm::errs() << "FATAL: lowering from HLFIR to FIR failed";
435436
return mlir::failure();
@@ -444,6 +445,8 @@ static llvm::LogicalResult convertFortranSourceToMLIR(
444445

445446
// Add O2 optimizer pass pipeline.
446447
MLIRToLLVMPassPipelineConfig config(llvm::OptimizationLevel::O2);
448+
if (enableOpenMP)
449+
config.EnableOpenMP = true;
447450
config.NSWOnLoopVarInc = setNSW;
448451
fir::registerDefaultInlinerPass(config);
449452
fir::createDefaultFIROptimizerPassPipeline(pm, config);

flang/tools/tco/tco.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ compileFIR(const mlir::PassPipelineCLParser &passPipeline) {
138138
return mlir::failure();
139139
} else {
140140
MLIRToLLVMPassPipelineConfig config(llvm::OptimizationLevel::O2);
141+
config.EnableOpenMP = true; // assume the input contains OpenMP
141142
config.AliasAnalysis = true; // enabled when optimizing for speed
142143
if (codeGenLLVM) {
143144
// Run only CodeGen passes.

0 commit comments

Comments
 (0)