Index: flang/lib/Lower/OpenMP.cpp =================================================================== --- flang/lib/Lower/OpenMP.cpp +++ flang/lib/Lower/OpenMP.cpp @@ -247,6 +247,7 @@ mlir::omp::ClauseProcBindKindAttr procBindKindAttr; SmallVector allocateOperands, allocatorOperands; mlir::UnitAttr nowaitAttr; + mlir::Attribute simdClauseOperand; const auto &opClauseList = std::get(beginBlockDirective.t); @@ -292,6 +293,9 @@ &clause.u)) { // Privatisation clauses are handled elsewhere. continue; + } else if (std::get_if(&clause.u)) { + // Nothing needs to be done for threads clause. + continue; } else { TODO(currentLocation, "OpenMP Block construct clauses"); } @@ -319,6 +323,10 @@ auto singleOp = firOpBuilder.create( currentLocation, allocateOperands, allocatorOperands, nowaitAttr); createBodyOfOp(singleOp, converter, currentLocation); + } else if (blockDirective.v == llvm::omp::OMPD_ordered) { + auto orderedOp = firOpBuilder.create( + currentLocation, simdClauseOperand.dyn_cast_or_null()); + createBodyOfOp(orderedOp, converter, currentLocation); } else { TODO(converter.getCurrentLocation(), "Unhandled block directive"); } Index: flang/test/Lower/OpenMP/omp-ordered-threads.f90 =================================================================== --- /dev/null +++ flang/test/Lower/OpenMP/omp-ordered-threads.f90 @@ -0,0 +1,42 @@ +! This test checks lowering of OpenMP ordered directive with threads Clause. +! Without clause in ordered direcitve, it behaves as if threads clause is +! specified. + +! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck %s --check-prefix=FIRDialect +! RUN: bbc -fopenmp -emit-fir %s -o - | \ +! RUN: tco --disable-llvm --print-ir-after=fir-to-llvm-ir 2>&1 | \ +! RUN: FileCheck %s --check-prefix=LLVMIRDialect +! RUN: bbc -fopenmp -emit-fir %s -o - | tco | FileCheck %s --check-prefix=LLVMIR + +subroutine ordered + integer :: i + integer :: a(20) + +!FIRDialect: omp.ordered_region { +!LLVMIRDialect: omp.ordered_region { +!LLVMIR: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB0:[0-9]+]]), !dbg !{{.*}} +!LLVMIR-NEXT: call void @__kmpc_ordered(%struct.ident_t* @[[GLOB0]], i32 [[TMP0]]), !dbg !{{.*}} +!$OMP ORDERED + a(i) = a(i-1) + 1 +!FIRDialect: omp.terminator +!FIRDialect-NEXT: } +!LLVMIRDialect: omp.terminator +!LLVMIRDialect-NEXT: } +!LLVMIR: call void @__kmpc_end_ordered(%struct.ident_t* @[[GLOB0]], i32 [[TMP0]]), !dbg !{{.*}} +!$OMP END ORDERED + +!FIRDialect: omp.ordered_region { +!LLVMIRDialect: omp.ordered_region { +!LLVMIR: [[TMP1:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]]), !dbg !{{.*}} +!LLVMIR-NEXT: call void @__kmpc_ordered(%struct.ident_t* @[[GLOB1]], i32 [[TMP1]]), !dbg !{{.*}} +!$OMP ORDERED THREADS + a(i) = a(i-1) + 1 +!FIRDialect: omp.terminator +!FIRDialect-NEXT: } +!LLVMIRDialect: omp.terminator +!LLVMIRDialect-NEXT: } +!LLVMIR: call void @__kmpc_end_ordered(%struct.ident_t* @[[GLOB1]], i32 [[TMP1]]), !dbg !{{.*}} +!LLVMIR-NEXT: ret void, !dbg !{{.*}} +!$OMP END ORDERED + +end