[flang-commits] [flang] [Flang][OpenMP] Add support for `taskloop nogroup` Lowering (PR #166923)
via flang-commits
flang-commits at lists.llvm.org
Fri Nov 7 03:19:00 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-openmp
Author: Jack Styles (Stylie777)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/166923.diff
4 Files Affected:
- (modified) flang/lib/Lower/OpenMP/ClauseProcessor.cpp (+5)
- (modified) flang/lib/Lower/OpenMP/ClauseProcessor.h (+1)
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+4-3)
- (added) flang/test/Lower/OpenMP/taskloop-nogroup.f90 (+25)
``````````diff
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<omp::clause::Mergeable>(result.mergeable);
}
+bool ClauseProcessor::processNogroup(
+ mlir::omp::NogroupClauseOps &result) const {
+ return markClauseOccurrence<omp::clause::Nogroup>(result.nogroup);
+}
+
bool ClauseProcessor::processNowait(mlir::omp::NowaitClauseOps &result) const {
return markClauseOccurrence<omp::clause::Nowait>(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<clause::Allocate, clause::Collapse, clause::Default,
clause::Final, clause::If, clause::InReduction,
- clause::Lastprivate, clause::Mergeable, clause::Nogroup,
- clause::Priority, clause::Reduction, clause::Shared,
- clause::Untied>(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<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! 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<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+
+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<i32>, !fir.ref<i32>)
+ !$omp taskloop nogroup
+ do i=1,10
+ sum = sum + i
+ end do
+ !$omp end taskloop
+end subroutine
``````````
</details>
https://github.com/llvm/llvm-project/pull/166923
More information about the flang-commits
mailing list