[flang-commits] [flang] 7505f2c - [Flang][OpenMP] Only access the MapType if it is specified
Kiran Chandramohan via flang-commits
flang-commits at lists.llvm.org
Wed Jul 5 05:56:35 PDT 2023
Author: Kiran Chandramohan
Date: 2023-07-05T12:56:09Z
New Revision: 7505f2c92d90d559ebb95dd3e1b451a8c2546714
URL: https://github.com/llvm/llvm-project/commit/7505f2c92d90d559ebb95dd3e1b451a8c2546714
DIFF: https://github.com/llvm/llvm-project/commit/7505f2c92d90d559ebb95dd3e1b451a8c2546714.diff
LOG: [Flang][OpenMP] Only access the MapType if it is specified
Fixes #63638
Reviewed By: TIFitis
Differential Revision: https://reviews.llvm.org/D154442
Added:
Modified:
flang/lib/Lower/OpenMP.cpp
flang/test/Lower/OpenMP/target.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index e1bfa2ca25a424..fd59cc3bbd6541 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -802,37 +802,43 @@ static void createTargetOp(Fortran::lower::AbstractConverter &converter,
};
auto addMapClause = [&](const auto &mapClause, mlir::Location &location) {
- auto mapType = std::get<Fortran::parser::OmpMapType::Type>(
- std::get<std::optional<Fortran::parser::OmpMapType>>(mapClause->v.t)
- ->t);
+ const auto &oMapType =
+ std::get<std::optional<Fortran::parser::OmpMapType>>(mapClause->v.t);
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE;
- switch (mapType) {
- case Fortran::parser::OmpMapType::Type::To:
- mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
- break;
- case Fortran::parser::OmpMapType::Type::From:
- mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
- break;
- case Fortran::parser::OmpMapType::Type::Tofrom:
+ // If the map type is specified, then process it else Tofrom is the default.
+ if (oMapType) {
+ const Fortran::parser::OmpMapType::Type &mapType =
+ std::get<Fortran::parser::OmpMapType::Type>(oMapType->t);
+ switch (mapType) {
+ case Fortran::parser::OmpMapType::Type::To:
+ mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
+ break;
+ case Fortran::parser::OmpMapType::Type::From:
+ mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
+ break;
+ case Fortran::parser::OmpMapType::Type::Tofrom:
+ mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO |
+ llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
+ break;
+ case Fortran::parser::OmpMapType::Type::Alloc:
+ case Fortran::parser::OmpMapType::Type::Release:
+ // alloc and release is the default map_type for the Target Data Ops,
+ // i.e. if no bits for map_type is supplied then alloc/release is
+ // implicitly assumed based on the target directive. Default value for
+ // Target Data and Enter Data is alloc and for Exit Data it is release.
+ break;
+ case Fortran::parser::OmpMapType::Type::Delete:
+ mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_DELETE;
+ }
+
+ if (std::get<std::optional<Fortran::parser::OmpMapType::Always>>(
+ oMapType->t))
+ mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_ALWAYS;
+ } else {
mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO |
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
- break;
- case Fortran::parser::OmpMapType::Type::Alloc:
- case Fortran::parser::OmpMapType::Type::Release:
- // alloc and release is the default map_type for the Target Data Ops, i.e.
- // if no bits for map_type is supplied then alloc/release is implicitly
- // assumed based on the target directive. Default value for Target Data
- // and Enter Data is alloc and for Exit Data it is release.
- break;
- case Fortran::parser::OmpMapType::Type::Delete:
- mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_DELETE;
}
- if (std::get<std::optional<Fortran::parser::OmpMapType::Always>>(
- std::get<std::optional<Fortran::parser::OmpMapType>>(mapClause->v.t)
- ->t)
- .has_value())
- mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_ALWAYS;
// TODO: Add support MapTypeModifiers close, mapper, present, iterator
diff --git a/flang/test/Lower/OpenMP/target.f90 b/flang/test/Lower/OpenMP/target.f90
index 44b2b7b53531ea..858e66d061c7d8 100644
--- a/flang/test/Lower/OpenMP/target.f90
+++ b/flang/test/Lower/OpenMP/target.f90
@@ -125,6 +125,24 @@ subroutine omp_target_data
!CHECK: }
end subroutine omp_target_data
+!CHECK-LABEL: func.func @_QPomp_target_data_mt
+subroutine omp_target_data_mt
+ integer :: a(1024)
+ integer :: b(1024)
+ !CHECK: %[[VAR_A:.*]] = fir.alloca !fir.array<1024xi32> {bindc_name = "a", uniq_name = "_QFomp_target_data_mtEa"}
+ !CHECK: %[[VAR_B:.*]] = fir.alloca !fir.array<1024xi32> {bindc_name = "b", uniq_name = "_QFomp_target_data_mtEb"}
+ !CHECK: omp.target_data map((tofrom -> %[[VAR_A]] : !fir.ref<!fir.array<1024xi32>>))
+ !$omp target data map(a)
+ !CHECK: omp.terminator
+ !$omp end target data
+ !CHECK: }
+ !CHECK: omp.target_data map((always, from -> %[[VAR_B]] : !fir.ref<!fir.array<1024xi32>>))
+ !$omp target data map(always, from : b)
+ !CHECK: omp.terminator
+ !$omp end target data
+ !CHECK: }
+end subroutine omp_target_data_mt
+
!===============================================================================
! Target with region
!===============================================================================
More information about the flang-commits
mailing list