Skip to content

Commit 89efae9

Browse files
authored
[Flang][OpenMP] Update default MapType for Map Clauses and OpenMP 5.2 (#144715)
In OpenMP 5.2, the `target enter data` and `target exit data` constructs now have default map types if the user does not define them in the Map clause. For `target enter data`, this is `to` and `target exit data` this is `from`. This behaviour is now enabled when OpenMP 5.2 or greater is used when compiling. To enable this, the default value is now set in the `processMap` clause, with any previous behaviour being maintained for either older versions of OpenMP or other directives. See also #110008
1 parent 19360e6 commit 89efae9

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ void ClauseProcessor::processMapObjects(
12691269

12701270
bool ClauseProcessor::processMap(
12711271
mlir::Location currentLocation, lower::StatementContext &stmtCtx,
1272-
mlir::omp::MapClauseOps &result,
1272+
mlir::omp::MapClauseOps &result, llvm::omp::Directive directive,
12731273
llvm::SmallVectorImpl<const semantics::Symbol *> *mapSyms) const {
12741274
// We always require tracking of symbols, even if the caller does not,
12751275
// so we create an optionally used local set of symbols when the mapSyms
@@ -1287,9 +1287,18 @@ bool ClauseProcessor::processMap(
12871287
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
12881288
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE;
12891289
std::string mapperIdName = "__implicit_mapper";
1290-
// If the map type is specified, then process it else Tofrom is the
1291-
// default.
1292-
Map::MapType type = mapType.value_or(Map::MapType::Tofrom);
1290+
// If the map type is specified, then process it else set the appropriate
1291+
// default value
1292+
Map::MapType type;
1293+
if (directive == llvm::omp::Directive::OMPD_target_enter_data &&
1294+
semaCtx.langOptions().OpenMPVersion >= 52)
1295+
type = mapType.value_or(Map::MapType::To);
1296+
else if (directive == llvm::omp::Directive::OMPD_target_exit_data &&
1297+
semaCtx.langOptions().OpenMPVersion >= 52)
1298+
type = mapType.value_or(Map::MapType::From);
1299+
else
1300+
type = mapType.value_or(Map::MapType::Tofrom);
1301+
12931302
switch (type) {
12941303
case Map::MapType::To:
12951304
mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;

flang/lib/Lower/OpenMP/ClauseProcessor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class ClauseProcessor {
139139
bool processMap(mlir::Location currentLocation,
140140
lower::StatementContext &stmtCtx,
141141
mlir::omp::MapClauseOps &result,
142+
llvm::omp::Directive directive = llvm::omp::OMPD_unknown,
142143
llvm::SmallVectorImpl<const semantics::Symbol *> *mapSyms =
143144
nullptr) const;
144145
bool processMotionClauses(lower::StatementContext &stmtCtx,

flang/lib/Lower/OpenMP/Clauses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ Map make(const parser::OmpClause::Map &inp,
10431043
auto type = [&]() -> std::optional<Map::MapType> {
10441044
if (t3)
10451045
return convert1(t3->v);
1046-
return Map::MapType::Tofrom;
1046+
return std::nullopt;
10471047
}();
10481048

10491049
Map::MapTypeModifiers typeMods;

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,8 @@ static void genTargetClauses(
18311831
}
18321832
cp.processIf(llvm::omp::Directive::OMPD_target, clauseOps);
18331833
cp.processIsDevicePtr(clauseOps, isDevicePtrSyms);
1834-
cp.processMap(loc, stmtCtx, clauseOps, &mapSyms);
1834+
cp.processMap(loc, stmtCtx, clauseOps, llvm::omp::Directive::OMPD_unknown,
1835+
&mapSyms);
18351836
cp.processNowait(clauseOps);
18361837
cp.processThreadLimit(stmtCtx, clauseOps);
18371838

@@ -1884,7 +1885,7 @@ static void genTargetEnterExitUpdateDataClauses(
18841885
if (directive == llvm::omp::Directive::OMPD_target_update)
18851886
cp.processMotionClauses(stmtCtx, clauseOps);
18861887
else
1887-
cp.processMap(loc, stmtCtx, clauseOps);
1888+
cp.processMap(loc, stmtCtx, clauseOps, directive);
18881889

18891890
cp.processNowait(clauseOps);
18901891
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
! This test checks the lowering and application of default map types for the target enter/exit data constructs and map clauses
2+
3+
!RUN: %flang -fc1 -emit-fir -fopenmp -fopenmp-version=52 -o - %s | FileCheck %s --check-prefix=CHECK-52
4+
!RUN: not %flang -fc1 -emit-fir -fopenmp -fopenmp-version=51 -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-51
5+
6+
module test
7+
real, allocatable :: A
8+
9+
contains
10+
subroutine initialize()
11+
allocate(A)
12+
!$omp target enter data map(A)
13+
!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 = ""}
14+
!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"}
15+
!CHECK-51: to and alloc map types are permitted
16+
17+
end subroutine initialize
18+
19+
subroutine finalize()
20+
!$omp target exit data map(A)
21+
!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 = ""}
22+
!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"}
23+
!CHECK-51: from, release and delete map types are permitted
24+
deallocate(A)
25+
26+
end subroutine finalize
27+
end module test

0 commit comments

Comments
 (0)