Skip to content

Commit b5d77cc

Browse files
committed
[Flang][OpenMP] Add Lowering support for lastprivate in taskloops
lastprivate support already exists within the DataSharingProcessor, so this can be extended to include the use of taskloops to enable AST->FIR lowering. The related error message has also been updated to indicate that taskloops are now supported.
1 parent 19291b7 commit b5d77cc

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
342342
if (!hasLastPrivate)
343343
return;
344344

345-
if (mlir::isa<mlir::omp::WsloopOp>(op) || mlir::isa<mlir::omp::SimdOp>(op)) {
345+
if (mlir::isa<mlir::omp::WsloopOp>(op) || mlir::isa<mlir::omp::SimdOp>(op) ||
346+
mlir::isa<mlir::omp::TaskloopOp>(op)) {
346347
mlir::omp::LoopRelatedClauseOps result;
347348
llvm::SmallVector<const semantics::Symbol *> iv;
348349
collectLoopRelatedInfo(converter, converter.getCurrentLocation(), eval,
@@ -408,7 +409,7 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
408409
} else {
409410
TODO(converter.getCurrentLocation(),
410411
"lastprivate clause in constructs other than "
411-
"simd/worksharing-loop");
412+
"simd/worksharing-loop/taskloop");
412413
}
413414
}
414415

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,8 +1776,8 @@ static void genTaskloopClauses(
17761776

17771777
cp.processTODO<clause::Allocate, clause::Collapse, clause::Default,
17781778
clause::Final, clause::If, clause::InReduction,
1779-
clause::Lastprivate, clause::Mergeable, clause::Nogroup,
1780-
clause::Priority, clause::Shared, clause::Untied>(
1779+
clause::Mergeable, clause::Nogroup, clause::Priority,
1780+
clause::Shared, clause::Untied>(
17811781
loc, llvm::omp::Directive::OMPD_taskloop);
17821782
}
17831783

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
! Test the lastprivate clause when used with the taskloop construct
2+
! RUN: bbc -emit-hlfir -fopenmp -fopenmp-version=45 %s -o - 2>&1 | FileCheck %s
3+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=45 %s -o - 2>&1 | FileCheck %s
4+
5+
! CHECK-LABEL: omp.private
6+
! CHECK-SAME: {type = private} @[[I_PRIVATE:.*]] : i32
7+
! CHECK-LABEL: omp.private
8+
! CHECK-SAME: {type = private} @[[LAST_I_PRIVATE:.*]] : i32
9+
10+
! CHECK: %[[ALLOCA_I:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFlastprivateEi"}
11+
! CHECK: %[[DECLARE_I:.*]]:2 = hlfir.declare %[[ALLOCA_I]] {uniq_name = "_QFlastprivateEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
12+
! CHECK: %[[ALLOCA_LAST_I:.*]] = fir.alloca i32 {bindc_name = "last_i", uniq_name = "_QFlastprivateElast_i"}
13+
! CHECK: %[[DECLARE_LAST_I:.*]]:2 = hlfir.declare %[[ALLOCA_LAST_I]] {uniq_name = "_QFlastprivateElast_i"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
14+
15+
subroutine lastprivate()
16+
integer :: i, last_i
17+
18+
! CHECK: omp.taskloop
19+
! CHECK-SAME: private(@[[LAST_I_PRIVATE]] %[[DECLARE_LAST_I]]#0 -> %arg0, @[[I_PRIVATE]] %[[DECLARE_I]]#0 -> %arg1 : !fir.ref<i32>, !fir.ref<i32>) {
20+
!$omp taskloop lastprivate(last_i)
21+
do i=1,10
22+
last_i = i
23+
end do
24+
!$omp end taskloop
25+
end

0 commit comments

Comments
 (0)