Skip to content

[flang][OpenMP] Lower standalone ops via OMP dispatch, NFC #92045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 27 additions & 41 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,9 @@ static void genOMPDispatch(Fortran::lower::AbstractConverter &converter,
const List<Clause> &clauses = item->clauses;

switch (llvm::omp::Directive dir = item->id) {
case llvm::omp::Directive::OMPD_barrier:
genBarrierOp(converter, symTable, semaCtx, eval, loc, queue, item);
break;
case llvm::omp::Directive::OMPD_distribute:
genDistributeOp(converter, symTable, semaCtx, eval, loc, clauses, queue,
item);
Expand All @@ -1968,22 +1971,25 @@ static void genOMPDispatch(Fortran::lower::AbstractConverter &converter,
break;
case llvm::omp::Directive::OMPD_loop:
case llvm::omp::Directive::OMPD_masked:
case llvm::omp::Directive::OMPD_tile:
case llvm::omp::Directive::OMPD_unroll:
TODO(loc, "Unhandled loop directive (" +
llvm::omp::getOpenMPDirectiveName(dir) + ")");
break;
case llvm::omp::Directive::OMPD_master:
genMasterOp(converter, symTable, semaCtx, eval, loc, clauses, queue, item);
break;
case llvm::omp::Directive::OMPD_ordered:
// Block-associated "ordered" construct.
genOrderedRegionOp(converter, symTable, semaCtx, eval, loc, clauses, queue,
item);
break;
case llvm::omp::Directive::OMPD_parallel:
genParallelOp(converter, symTable, semaCtx, eval, loc, clauses, queue, item,
/*outerCombined=*/false);
break;
case llvm::omp::Directive::OMPD_section:
genSectionOp(converter, symTable, semaCtx, eval, loc, /*clauses=*/{}, queue,
item);
break;
case llvm::omp::Directive::OMPD_sections:
genSectionsOp(converter, symTable, semaCtx, eval, loc, clauses, queue,
item);
Expand Down Expand Up @@ -2025,16 +2031,28 @@ static void genOMPDispatch(Fortran::lower::AbstractConverter &converter,
genTaskloopOp(converter, symTable, semaCtx, eval, loc, clauses, queue,
item);
break;
case llvm::omp::Directive::OMPD_taskwait:
genTaskwaitOp(converter, symTable, semaCtx, eval, loc, clauses, queue,
item);
break;
case llvm::omp::Directive::OMPD_taskyield:
genTaskyieldOp(converter, symTable, semaCtx, eval, loc, queue, item);
break;
case llvm::omp::Directive::OMPD_teams:
genTeamsOp(converter, symTable, semaCtx, eval, loc, clauses, queue, item);
break;
case llvm::omp::Directive::OMPD_tile:
case llvm::omp::Directive::OMPD_unroll:
TODO(loc, "Unhandled loop directive (" +
llvm::omp::getOpenMPDirectiveName(dir) + ")");
// case llvm::omp::Directive::OMPD_workdistribute:
case llvm::omp::Directive::OMPD_workshare:
// FIXME: Workshare is not a commonly used OpenMP construct, an
// implementation for this feature will come later. For the codes
// that use this construct, add a single construct for now.
genSingleOp(converter, symTable, semaCtx, eval, loc, clauses, queue, item);
break;

// Composite constructs
case llvm::omp::Directive::OMPD_distribute_parallel_do:
genCompositeDistributeParallelDo(converter, symTable, semaCtx, eval, loc,
Expand Down Expand Up @@ -2174,45 +2192,14 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
ConstructQueue queue{
buildConstructQueue(converter.getFirOpBuilder().getModule(), semaCtx,
eval, directive.source, directive.v, clauses)};

switch (directive.v) {
default:
break;
case llvm::omp::Directive::OMPD_barrier:
genBarrierOp(converter, symTable, semaCtx, eval, currentLocation, queue,
queue.begin());
break;
case llvm::omp::Directive::OMPD_taskwait:
genTaskwaitOp(converter, symTable, semaCtx, eval, currentLocation, clauses,
queue, queue.begin());
break;
case llvm::omp::Directive::OMPD_taskyield:
genTaskyieldOp(converter, symTable, semaCtx, eval, currentLocation, queue,
queue.begin());
break;
case llvm::omp::Directive::OMPD_target_data:
genTargetDataOp(converter, symTable, semaCtx, eval, currentLocation,
clauses, queue, queue.begin());
break;
case llvm::omp::Directive::OMPD_target_enter_data:
genTargetEnterExitUpdateDataOp<mlir::omp::TargetEnterDataOp>(
converter, symTable, semaCtx, currentLocation, clauses, queue,
queue.begin());
break;
case llvm::omp::Directive::OMPD_target_exit_data:
genTargetEnterExitUpdateDataOp<mlir::omp::TargetExitDataOp>(
converter, symTable, semaCtx, currentLocation, clauses, queue,
queue.begin());
break;
case llvm::omp::Directive::OMPD_target_update:
genTargetEnterExitUpdateDataOp<mlir::omp::TargetUpdateOp>(
converter, symTable, semaCtx, currentLocation, clauses, queue,
queue.begin());
break;
case llvm::omp::Directive::OMPD_ordered:
if (directive.v == llvm::omp::Directive::OMPD_ordered) {
// Standalone "ordered" directive.
genOrderedOp(converter, symTable, semaCtx, eval, currentLocation, clauses,
queue, queue.begin());
break;
} else {
// Dispatch handles the "block-associated" variant of "ordered".
genOMPDispatch(converter, symTable, semaCtx, eval, currentLocation, queue,
queue.begin());
}
}

Expand Down Expand Up @@ -2466,8 +2453,7 @@ genOMP(Fortran::lower::AbstractConverter &converter,
ConstructQueue queue{buildConstructQueue(
converter.getFirOpBuilder().getModule(), semaCtx, eval,
sectionConstruct.source, llvm::omp::Directive::OMPD_section, {})};
genSectionOp(converter, symTable, semaCtx, eval, loc,
/*clauses=*/{}, queue, queue.begin());
genOMPDispatch(converter, symTable, semaCtx, eval, loc, queue, queue.begin());
}

static void
Expand Down
Loading