[flang-commits] [flang] [Flang][OpenMP] Add Lowering support for Collapse with Taskloop (PR #166791)
Jack Styles via flang-commits
flang-commits at lists.llvm.org
Tue Nov 11 05:30:45 PST 2025
https://github.com/Stylie777 updated https://github.com/llvm/llvm-project/pull/166791
>From aaae621a6429ca79f93e34910731149002ff7862 Mon Sep 17 00:00:00 2001
From: Jack Styles <jack.styles at arm.com>
Date: Thu, 6 Nov 2025 15:48:45 +0000
Subject: [PATCH 1/3] [Flang][OpenMP] Add Lowering support for Collapse with
Taskloop
Supprot for lowering collapse already exists within
`genLoopNestClauses`, which is called when lowering taskloop. However,
the TODO message still included the Collapse clause, so it was not
activated. By removing this, it enables lowering of the Collapse
clause in taskloop.
---
flang/lib/Lower/OpenMP/OpenMP.cpp | 2 +-
flang/test/Lower/OpenMP/taskloop-collapse.f90 | 34 +++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 flang/test/Lower/OpenMP/taskloop-collapse.f90
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 99470d0bbd2bf..8da82454a828c 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1778,7 +1778,7 @@ static void genTaskloopClauses(lower::AbstractConverter &converter,
cp.processPriority(stmtCtx, clauseOps);
cp.processUntied(clauseOps);
- cp.processTODO<clause::Collapse, clause::InReduction, clause::Lastprivate,
+ cp.processTODO<clause::InReduction, clause::Lastprivate,
clause::Nogroup, clause::Reduction>(
loc, llvm::omp::Directive::OMPD_taskloop);
}
diff --git a/flang/test/Lower/OpenMP/taskloop-collapse.f90 b/flang/test/Lower/OpenMP/taskloop-collapse.f90
new file mode 100644
index 0000000000000..48243640d07b9
--- /dev/null
+++ b/flang/test/Lower/OpenMP/taskloop-collapse.f90
@@ -0,0 +1,34 @@
+! Test the collapse clause when being used with the taskloop construct
+! 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} @[[J_PRIVATE:.*]] : i32
+! CHECK-LABEL: omp.private
+! CHECK-SAME: {type = private} @[[I_PRIVATE:.*]] : i32
+! CHECK-LABEL: omp.private
+! CHECK-SAME: {type = firstprivate} @[[SUM_FIRSTPRIVATE:.*]] : i32 copy
+
+! CHECK-LABEL: func.func @_QPtest()
+! CHECK: %[[ALLOCA_I:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFtestEi"}
+! CHECK: %[[DECLARE_I:.*]]:2 = hlfir.declare %1 {uniq_name = "_QFtestEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! CHECK: %[[ALLOCA_J:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFtestEj"}
+! CHECK: %[[DECLARE_J:.*]]:2 = hlfir.declare %3 {uniq_name = "_QFtestEj"} : (!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 %5 {uniq_name = "_QFtestEsum"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+
+subroutine test()
+ integer :: i, j, sum
+
+ !$omp taskloop collapse(2)
+ ! CHECK-LABEL: omp.taskloop
+ ! CHECK-SAME: private(@_QFtestEsum_firstprivate_i32 %[[DECLARE_SUM]]#0 -> %arg0, @_QFtestEi_private_i32 %[[DECLARE_I]]#0 -> %arg1, @_QFtestEj_private_i32 %[[DECLARE_J]]#0 -> %arg2 : !fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>)
+ ! CHECK-LABEL: omp.loop_nest
+ ! CHECK-SAME: (%arg3, %arg4) : i32 = (%c1_i32, %c1_i32_1) to (%c10_i32, %c5_i32) inclusive step (%c1_i32_0, %c1_i32_2) collapse(2)
+ do i = 1, 10
+ do j = 1, 5
+ sum = sum + i + j
+ end do
+ end do
+ !$omp end taskloop
+end subroutine
>From 2230e3ddb846bdae034414adbc2ef8c93486dae5 Mon Sep 17 00:00:00 2001
From: Jack Styles <jack.styles at arm.com>
Date: Fri, 7 Nov 2025 11:28:22 +0000
Subject: [PATCH 2/3] Add test for checking tilesizes gets rejected
---
flang/test/Semantics/OpenMP/taskloop04.f90 | 15 +++++++++++++++
1 file changed, 15 insertions(+)
create mode 100644 flang/test/Semantics/OpenMP/taskloop04.f90
diff --git a/flang/test/Semantics/OpenMP/taskloop04.f90 b/flang/test/Semantics/OpenMP/taskloop04.f90
new file mode 100644
index 0000000000000..4ffcf84f708e9
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/taskloop04.f90
@@ -0,0 +1,15 @@
+! When lowering Taskloop, it is possible for the TileSizes clause to be lowered, but this is not a supported clause.
+! We should make sure that any use of Tilesizes with Taskloop is correctly rejected by the Semantics.
+! RUN: %python %S/../test_errors.py %s %flang -fopenmp
+
+subroutine test
+ integer :: i, sum
+
+ !ERROR: TILE cannot follow TASKLOOP
+ !ERROR: SIZES clause is not allowed on the TASKLOOP directive
+ !$omp taskloop tile sizes(2)
+ do i=1,10
+ sum = sum + i
+ end do
+ !$omp end taskloop
+end subroutine
>From eb9627dd3223487fb030cc0cf7c9b5977eb8c813 Mon Sep 17 00:00:00 2001
From: Jack Styles <jack.styles at arm.com>
Date: Tue, 11 Nov 2025 13:29:45 +0000
Subject: [PATCH 3/3] formatting after rebase
---
flang/lib/Lower/OpenMP/OpenMP.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 8da82454a828c..0f9e40525eece 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1778,9 +1778,8 @@ static void genTaskloopClauses(lower::AbstractConverter &converter,
cp.processPriority(stmtCtx, clauseOps);
cp.processUntied(clauseOps);
- cp.processTODO<clause::InReduction, clause::Lastprivate,
- clause::Nogroup, clause::Reduction>(
- loc, llvm::omp::Directive::OMPD_taskloop);
+ cp.processTODO<clause::InReduction, clause::Lastprivate, clause::Nogroup,
+ clause::Reduction>(loc, llvm::omp::Directive::OMPD_taskloop);
}
static void genTaskwaitClauses(lower::AbstractConverter &converter,
More information about the flang-commits
mailing list