@@ -320,41 +320,34 @@ bool CodeGenAction::beginSourceFileAction() {
320320 // Add OpenMP-related passes
321321 // WARNING: These passes must be run immediately after the lowering to ensure
322322 // that the FIR is correct with respect to OpenMP operations/attributes.
323- bool isOpenMPEnabled = ci.getInvocation ().getFrontendOpts ().features .IsEnabled (
323+ bool isOpenMPEnabled =
324+ ci.getInvocation ().getFrontendOpts ().features .IsEnabled (
324325 Fortran::common::LanguageFeature::OpenMP);
326+
327+ using DoConcurrentMappingKind =
328+ Fortran::frontend::CodeGenOptions::DoConcurrentMappingKind;
329+ DoConcurrentMappingKind doConcurrentMappingKind =
330+ ci.getInvocation ().getCodeGenOpts ().getDoConcurrentMapping ();
331+
332+ if (doConcurrentMappingKind != DoConcurrentMappingKind::DCMK_None &&
333+ !isOpenMPEnabled) {
334+ unsigned diagID = ci.getDiagnostics ().getCustomDiagID (
335+ clang::DiagnosticsEngine::Warning,
336+ " lowering `do concurrent` loops to OpenMP is only supported if "
337+ " OpenMP is enabled" );
338+ ci.getDiagnostics ().Report (diagID);
339+ }
340+
325341 if (isOpenMPEnabled) {
326342 bool isDevice = false ;
327343 if (auto offloadMod = llvm::dyn_cast<mlir::omp::OffloadModuleInterface>(
328344 mlirModule->getOperation ()))
329345 isDevice = offloadMod.getIsTargetDevice ();
346+
330347 // WARNING: This pipeline must be run immediately after the lowering to
331348 // ensure that the FIR is correct with respect to OpenMP operations/
332349 // attributes.
333- fir::createOpenMPFIRPassPipeline (pm, isDevice);
334- }
335-
336- using DoConcurrentMappingKind =
337- Fortran::frontend::CodeGenOptions::DoConcurrentMappingKind;
338- DoConcurrentMappingKind selectedKind = ci.getInvocation ().getCodeGenOpts ().getDoConcurrentMapping ();
339- if (selectedKind != DoConcurrentMappingKind::DCMK_None) {
340- if (!isOpenMPEnabled) {
341- unsigned diagID = ci.getDiagnostics ().getCustomDiagID (
342- clang::DiagnosticsEngine::Warning,
343- " lowering `do concurrent` loops to OpenMP is only supported if "
344- " OpenMP is enabled" );
345- ci.getDiagnostics ().Report (diagID);
346- } else {
347- bool mapToDevice = selectedKind == DoConcurrentMappingKind::DCMK_Device;
348-
349- if (mapToDevice) {
350- unsigned diagID = ci.getDiagnostics ().getCustomDiagID (
351- clang::DiagnosticsEngine::Warning,
352- " TODO: lowering `do concurrent` loops to OpenMP device is not "
353- " supported yet" );
354- ci.getDiagnostics ().Report (diagID);
355- } else
356- pm.addPass (fir::createDoConcurrentConversionPass ());
357- }
350+ fir::createOpenMPFIRPassPipeline (pm, isDevice, doConcurrentMappingKind);
358351 }
359352
360353 pm.enableVerifier (/* verifyPasses=*/ true );
0 commit comments