diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp --- a/flang/lib/Lower/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP.cpp @@ -563,7 +563,8 @@ static void createTargetDataOp(Fortran::lower::AbstractConverter &converter, const Fortran::parser::OmpClauseList &opClauseList, - const llvm::omp::Directive &directive) { + const llvm::omp::Directive &directive, + Fortran::lower::pft::Evaluation *eval = nullptr) { Fortran::lower::StatementContext stmtCtx; fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); @@ -668,9 +669,10 @@ mlir::Location currentLocation = converter.getCurrentLocation(); if (directive == llvm::omp::Directive::OMPD_target_data) { - firOpBuilder.create( + auto dataOp = firOpBuilder.create( currentLocation, ifClauseOperand, deviceOperand, useDevicePtrOperand, useDeviceAddrOperand, mapOperands, mapTypesArrayAttr); + createBodyOfOp(dataOp, converter, currentLocation, *eval, &opClauseList); } else if (directive == llvm::omp::Directive::OMPD_target_enter_data) { firOpBuilder.create(currentLocation, ifClauseOperand, deviceOperand, nowaitAttr, @@ -922,6 +924,10 @@ } else if (std::get_if(&clause.u)) { // Nothing needs to be done for threads clause. continue; + } else if (std::get_if(&clause.u)) { + // Map clause is exclusive to Target Data directives. It is handled + // as part of the DataOp creation. + continue; } else if (const auto &finalClause = std::get_if(&clause.u)) { mlir::Value finalVal = fir::getBase(converter.genExprValue( @@ -984,6 +990,8 @@ /*task_reductions=*/nullptr, allocateOperands, allocatorOperands); createBodyOfOp(taskGroupOp, converter, currentLocation, eval, &opClauseList); + } else if (blockDirective.v == llvm::omp::OMPD_target_data) { + createTargetDataOp(converter, opClauseList, blockDirective.v, &eval); } else { TODO(converter.getCurrentLocation(), "Unhandled block directive"); } diff --git a/flang/test/Lower/OpenMP/target_data.f90 b/flang/test/Lower/OpenMP/target_data.f90 --- a/flang/test/Lower/OpenMP/target_data.f90 +++ b/flang/test/Lower/OpenMP/target_data.f90 @@ -4,7 +4,6 @@ ! Target_Enter Simple !=============================================================================== - !CHECK-LABEL: func.func @_QPomp_target_enter_simple() { subroutine omp_target_enter_simple integer :: a(1024) @@ -103,3 +102,17 @@ !CHECK: omp.target_exit_data device(%[[VAL_2:.*]] : i32) map((from -> {{.*}} : !fir.ref>)) !$omp target exit data map(from: a) device(d) end subroutine omp_target_exit_device + +!=============================================================================== +! Target_Data with region +!=============================================================================== + +!CHECK-LABEL: func.func @_QPomp_target_data() { +subroutine omp_target_data + integer :: a(1024) + !CHECK: omp.target_data map((tofrom -> {{.*}} : !fir.ref>)) + !$omp target data map(tofrom: a) + a(1) = 10 + !CHECK: omp.terminator + !$omp end target data +end subroutine omp_target_data