From a87033582f1abacba862cea555d400a73426c81d Mon Sep 17 00:00:00 2001 From: Jack Styles Date: Fri, 7 Nov 2025 10:52:28 +0000 Subject: [PATCH] [Flang][OpenMP] Add support for `taskloop nogroup` Lowering NoGroup is a clause that is supported by taskloop in the OpenMP standards. Until this point, this has been marked as TODO as support was not present in AST->FIR lowering. This has now been added so the clause can be emitted in HLFIR/FIR. Lowering from FIR to LLVM IR is not available as this has not been completed for taskloop. --- flang/lib/Lower/OpenMP/ClauseProcessor.cpp | 5 ++++ flang/lib/Lower/OpenMP/ClauseProcessor.h | 1 + flang/lib/Lower/OpenMP/OpenMP.cpp | 7 +++--- flang/test/Lower/OpenMP/taskloop-nogroup.f90 | 25 ++++++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 flang/test/Lower/OpenMP/taskloop-nogroup.f90 diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp index 1c163e6de7e5a..872f31fe45cca 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp @@ -406,6 +406,11 @@ bool ClauseProcessor::processMergeable( return markClauseOccurrence(result.mergeable); } +bool ClauseProcessor::processNogroup( + mlir::omp::NogroupClauseOps &result) const { + return markClauseOccurrence(result.nogroup); +} + bool ClauseProcessor::processNowait(mlir::omp::NowaitClauseOps &result) const { return markClauseOccurrence(result.nowait); } diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h b/flang/lib/Lower/OpenMP/ClauseProcessor.h index 6452e39b97551..d524b4ddc8ac4 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.h +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h @@ -89,6 +89,7 @@ class ClauseProcessor { bool processInclusive(mlir::Location currentLocation, mlir::omp::InclusiveClauseOps &result) const; bool processMergeable(mlir::omp::MergeableClauseOps &result) const; + bool processNogroup(mlir::omp::NogroupClauseOps &result) const; bool processNowait(mlir::omp::NowaitClauseOps &result) const; bool processNumTasks(lower::StatementContext &stmtCtx, mlir::omp::NumTasksClauseOps &result) const; diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp index ad456d89bc432..36814f27029b7 100644 --- a/flang/lib/Lower/OpenMP/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP/OpenMP.cpp @@ -1771,13 +1771,14 @@ static void genTaskloopClauses(lower::AbstractConverter &converter, ClauseProcessor cp(converter, semaCtx, clauses); cp.processGrainsize(stmtCtx, clauseOps); + cp.processNogroup(clauseOps); cp.processNumTasks(stmtCtx, clauseOps); cp.processTODO(loc, llvm::omp::Directive::OMPD_taskloop); + clause::Lastprivate, clause::Mergeable, clause::Priority, + clause::Reduction, clause::Shared, clause::Untied>( + loc, llvm::omp::Directive::OMPD_taskloop); } static void genTaskwaitClauses(lower::AbstractConverter &converter, diff --git a/flang/test/Lower/OpenMP/taskloop-nogroup.f90 b/flang/test/Lower/OpenMP/taskloop-nogroup.f90 new file mode 100644 index 0000000000000..d2c7aa5202b39 --- /dev/null +++ b/flang/test/Lower/OpenMP/taskloop-nogroup.f90 @@ -0,0 +1,25 @@ +! Test the Nogroup clause when used with the taskloop directive +! RUN: bbc -emit-hlfir -fopenmp -fopenmp-version=45 %s -o - 2>&1 | FileCheck %s +! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=45 %s -o - 2>&1 | FileCheck %s + +! CHECK-LABEL: omp.private +! CHECK-SAME: {type = private} @[[I_PRIVATE:.*]] : i32 +! CHECK-LABEL: omp.private +! CHECK-SAME: {type = firstprivate} @[[SUM_FIRSTPRIVATE:.*]] : i32 copy + +! CHECK: %[[ALLOCA_I:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFtestEi"} +! CHECK: %[[DECLARE_I:.*]]:2 = hlfir.declare %[[ALLOCA_I]] {uniq_name = "_QFtestEi"} : (!fir.ref) -> (!fir.ref, !fir.ref) +! CHECK: %[[ALLOCA_SUM:.*]] = fir.alloca i32 {bindc_name = "sum", uniq_name = "_QFtestEsum"} +! CHECK: %[[DECLARE_SUM:.*]]:2 = hlfir.declare %[[ALLOCA_SUM]] {uniq_name = "_QFtestEsum"} : (!fir.ref) -> (!fir.ref, !fir.ref) + +subroutine test() + integer :: i, sum + + ! CHECK-LABEL: omp.taskloop + ! CHECK-SAME: nogroup private(@_QFtestEsum_firstprivate_i32 %[[DECLARE_SUM]]#0 -> %arg0, @_QFtestEi_private_i32 %[[DECLARE_I]]#0 -> %arg1 : !fir.ref, !fir.ref) + !$omp taskloop nogroup + do i=1,10 + sum = sum + i + end do + !$omp end taskloop +end subroutine