Skip to content

Commit 23fc527

Browse files
committed
Add Lowering to omp mlir for workdistribute construct (llvm#154378)
This PR adds lowering of workdistribute construct in flang to omp mlir dialect workdistribute op. The work in this PR is c-p and updated from @ivanradanov commits from coexecute implementation: flang_workdistribute_iwomp_2024
1 parent 52d735d commit 23fc527

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,13 @@ static void processHostEvalClauses(lower::AbstractConverter &converter,
618618
cp.processCollapse(loc, eval, hostInfo->ops, hostInfo->iv);
619619
break;
620620

621+
case OMPD_teams_workdistribute:
622+
cp.processThreadLimit(stmtCtx, hostInfo->ops);
623+
[[fallthrough]];
624+
case OMPD_target_teams_workdistribute:
625+
cp.processNumTeams(stmtCtx, hostInfo->ops);
626+
break;
627+
621628
// Standalone 'target' case.
622629
case OMPD_target: {
623630
processSingleNestedIf(
@@ -2631,6 +2638,17 @@ genTeamsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
26312638
queue, item, clauseOps);
26322639
}
26332640

2641+
static mlir::omp::WorkdistributeOp genWorkdistributeOp(
2642+
lower::AbstractConverter &converter, lower::SymMap &symTable,
2643+
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
2644+
mlir::Location loc, const ConstructQueue &queue,
2645+
ConstructQueue::const_iterator item) {
2646+
return genOpWithBody<mlir::omp::WorkdistributeOp>(
2647+
OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval,
2648+
llvm::omp::Directive::OMPD_workdistribute),
2649+
queue, item);
2650+
}
2651+
26342652
//===----------------------------------------------------------------------===//
26352653
// Code generation functions for the standalone version of constructs that can
26362654
// also be a leaf of a composite construct
@@ -3262,7 +3280,10 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
32623280
TODO(loc, "Unhandled loop directive (" +
32633281
llvm::omp::getOpenMPDirectiveName(dir, version) + ")");
32643282
}
3265-
// case llvm::omp::Directive::OMPD_workdistribute:
3283+
case llvm::omp::Directive::OMPD_workdistribute:
3284+
newOp = genWorkdistributeOp(converter, symTable, semaCtx, eval, loc, queue,
3285+
item);
3286+
break;
32663287
case llvm::omp::Directive::OMPD_workshare:
32673288
newOp = genWorkshareOp(converter, symTable, stmtCtx, semaCtx, eval, loc,
32683289
queue, item);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=60 %s -o - | FileCheck %s
2+
3+
! CHECK-LABEL: func @_QPtarget_teams_workdistribute
4+
subroutine target_teams_workdistribute()
5+
integer :: aa(10), bb(10)
6+
! CHECK: omp.target
7+
! CHECK: omp.teams
8+
! CHECK: omp.workdistribute
9+
!$omp target teams workdistribute
10+
aa = bb
11+
! CHECK: omp.terminator
12+
! CHECK: omp.terminator
13+
! CHECK: omp.terminator
14+
!$omp end target teams workdistribute
15+
end subroutine target_teams_workdistribute
16+
17+
! CHECK-LABEL: func @_QPteams_workdistribute
18+
subroutine teams_workdistribute()
19+
use iso_fortran_env
20+
real(kind=real32) :: a
21+
real(kind=real32), dimension(10) :: x
22+
real(kind=real32), dimension(10) :: y
23+
! CHECK: omp.teams
24+
! CHECK: omp.workdistribute
25+
!$omp teams workdistribute
26+
y = a * x + y
27+
! CHECK: omp.terminator
28+
! CHECK: omp.terminator
29+
!$omp end teams workdistribute
30+
end subroutine teams_workdistribute

0 commit comments

Comments
 (0)