Skip to content

[Flang][OpenMP] Update default MapType for Map Clauses and OpenMP 5.2 #144715

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 3 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
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
17 changes: 13 additions & 4 deletions flang/lib/Lower/OpenMP/ClauseProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ void ClauseProcessor::processMapObjects(

bool ClauseProcessor::processMap(
mlir::Location currentLocation, lower::StatementContext &stmtCtx,
mlir::omp::MapClauseOps &result,
mlir::omp::MapClauseOps &result, llvm::omp::Directive directive,
llvm::SmallVectorImpl<const semantics::Symbol *> *mapSyms) const {
// We always require tracking of symbols, even if the caller does not,
// so we create an optionally used local set of symbols when the mapSyms
Expand All @@ -1261,9 +1261,18 @@ bool ClauseProcessor::processMap(
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE;
std::string mapperIdName = "__implicit_mapper";
// If the map type is specified, then process it else Tofrom is the
// default.
Map::MapType type = mapType.value_or(Map::MapType::Tofrom);
// If the map type is specified, then process it else set the appropriate
// default value
Map::MapType type;
if (directive == llvm::omp::Directive::OMPD_target_enter_data &&
semaCtx.langOptions().OpenMPVersion >= 52)
type = mapType.value_or(Map::MapType::To);
else if (directive == llvm::omp::Directive::OMPD_target_exit_data &&
semaCtx.langOptions().OpenMPVersion >= 52)
type = mapType.value_or(Map::MapType::From);
else
type = mapType.value_or(Map::MapType::Tofrom);

switch (type) {
case Map::MapType::To:
mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Lower/OpenMP/ClauseProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class ClauseProcessor {
bool processMap(mlir::Location currentLocation,
lower::StatementContext &stmtCtx,
mlir::omp::MapClauseOps &result,
llvm::omp::Directive directive = llvm::omp::OMPD_unknown,
llvm::SmallVectorImpl<const semantics::Symbol *> *mapSyms =
nullptr) const;
bool processMotionClauses(lower::StatementContext &stmtCtx,
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Lower/OpenMP/Clauses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ Map make(const parser::OmpClause::Map &inp,
auto type = [&]() -> std::optional<Map::MapType> {
if (t3)
return convert1(t3->v);
return Map::MapType::Tofrom;
return std::nullopt;
}();

Map::MapTypeModifiers typeMods;
Expand Down
5 changes: 3 additions & 2 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,8 @@ static void genTargetClauses(
}
cp.processIf(llvm::omp::Directive::OMPD_target, clauseOps);
cp.processIsDevicePtr(clauseOps, isDevicePtrSyms);
cp.processMap(loc, stmtCtx, clauseOps, &mapSyms);
cp.processMap(loc, stmtCtx, clauseOps, llvm::omp::Directive::OMPD_unknown,
&mapSyms);
cp.processNowait(clauseOps);
cp.processThreadLimit(stmtCtx, clauseOps);

Expand Down Expand Up @@ -1884,7 +1885,7 @@ static void genTargetEnterExitUpdateDataClauses(
if (directive == llvm::omp::Directive::OMPD_target_update)
cp.processMotionClauses(stmtCtx, clauseOps);
else
cp.processMap(loc, stmtCtx, clauseOps);
cp.processMap(loc, stmtCtx, clauseOps, directive);

cp.processNowait(clauseOps);
}
Expand Down
27 changes: 27 additions & 0 deletions flang/test/Lower/OpenMP/target-enter-data-default-openmp52.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
! This test checks the lowering and application of default map types for the target enter/exit data constructs and map clauses

!RUN: %flang -fc1 -emit-fir -fopenmp -fopenmp-version=52 -o - %s | FileCheck %s --check-prefix=CHECK-52
!RUN: not %flang -fc1 -emit-fir -fopenmp -fopenmp-version=51 -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-51

module test
real, allocatable :: A

contains
subroutine initialize()
allocate(A)
!$omp target enter data map(A)
!CHECK-52: omp.map.info var_ptr(%2 : !fir.ref<!fir.box<!fir.heap<f32>>>, f32) map_clauses(to) capture(ByRef) var_ptr_ptr(%5 : !fir.llvm_ptr<!fir.ref<f32>>) -> !fir.llvm_ptr<!fir.ref<f32>> {name = ""}
!CHECK-52: omp.map.info var_ptr(%2 : !fir.ref<!fir.box<!fir.heap<f32>>>, !fir.box<!fir.heap<f32>>) map_clauses(to) capture(ByRef) members(%6 : [0] : !fir.llvm_ptr<!fir.ref<f32>>) -> !fir.ref<!fir.box<!fir.heap<f32>>> {name = "a"}
!CHECK-51: to and alloc map types are permitted

end subroutine initialize

subroutine finalize()
!$omp target exit data map(A)
!CHECK-52: omp.map.info var_ptr(%2 : !fir.ref<!fir.box<!fir.heap<f32>>>, f32) map_clauses(from) capture(ByRef) var_ptr_ptr(%3 : !fir.llvm_ptr<!fir.ref<f32>>) -> !fir.llvm_ptr<!fir.ref<f32>> {name = ""}
!CHECK-52: omp.map.info var_ptr(%2 : !fir.ref<!fir.box<!fir.heap<f32>>>, !fir.box<!fir.heap<f32>>) map_clauses(from) capture(ByRef) members(%4 : [0] : !fir.llvm_ptr<!fir.ref<f32>>) -> !fir.ref<!fir.box<!fir.heap<f32>>> {name = "a"}
!CHECK-51: from, release and delete map types are permitted
deallocate(A)

end subroutine finalize
end module test
Loading