Skip to content

Commit 21019a3

Browse files
authored
[flang][openmp] Add Lowering to omp mlir for workdistribute construct (#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 5628964 commit 21019a3

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
@@ -534,6 +534,13 @@ static void processHostEvalClauses(lower::AbstractConverter &converter,
534534
cp.processCollapse(loc, eval, hostInfo->ops, hostInfo->iv);
535535
break;
536536

537+
case OMPD_teams_workdistribute:
538+
cp.processThreadLimit(stmtCtx, hostInfo->ops);
539+
[[fallthrough]];
540+
case OMPD_target_teams_workdistribute:
541+
cp.processNumTeams(stmtCtx, hostInfo->ops);
542+
break;
543+
537544
// Standalone 'target' case.
538545
case OMPD_target: {
539546
processSingleNestedIf(
@@ -2820,6 +2827,17 @@ genTeamsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
28202827
queue, item, clauseOps);
28212828
}
28222829

2830+
static mlir::omp::WorkdistributeOp genWorkdistributeOp(
2831+
lower::AbstractConverter &converter, lower::SymMap &symTable,
2832+
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
2833+
mlir::Location loc, const ConstructQueue &queue,
2834+
ConstructQueue::const_iterator item) {
2835+
return genOpWithBody<mlir::omp::WorkdistributeOp>(
2836+
OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval,
2837+
llvm::omp::Directive::OMPD_workdistribute),
2838+
queue, item);
2839+
}
2840+
28232841
//===----------------------------------------------------------------------===//
28242842
// Code generation functions for the standalone version of constructs that can
28252843
// also be a leaf of a composite construct
@@ -3459,7 +3477,10 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
34593477
case llvm::omp::Directive::OMPD_unroll:
34603478
genUnrollOp(converter, symTable, stmtCtx, semaCtx, eval, loc, queue, item);
34613479
break;
3462-
// case llvm::omp::Directive::OMPD_workdistribute:
3480+
case llvm::omp::Directive::OMPD_workdistribute:
3481+
newOp = genWorkdistributeOp(converter, symTable, semaCtx, eval, loc, queue,
3482+
item);
3483+
break;
34633484
case llvm::omp::Directive::OMPD_workshare:
34643485
newOp = genWorkshareOp(converter, symTable, stmtCtx, semaCtx, eval, loc,
34653486
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)