Skip to content

Commit ea048f7

Browse files
committed
Add flang lowering changes for mapper field in map clause.
1 parent 30611f8 commit ea048f7

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

+27-5
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,10 @@ void ClauseProcessor::processMapObjects(
936936
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits,
937937
std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
938938
llvm::SmallVectorImpl<mlir::Value> &mapVars,
939-
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms) const {
939+
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms,
940+
std::string mapperIdName) const {
940941
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
942+
mlir::FlatSymbolRefAttr mapperId;
941943

942944
for (const omp::Object &object : objects) {
943945
llvm::SmallVector<mlir::Value> bounds;
@@ -970,6 +972,20 @@ void ClauseProcessor::processMapObjects(
970972
}
971973
}
972974

975+
if (!mapperIdName.empty()) {
976+
if (mapperIdName == "default") {
977+
auto &typeSpec = object.sym()->owner().IsDerivedType()
978+
? *object.sym()->owner().derivedTypeSpec()
979+
: object.sym()->GetType()->derivedTypeSpec();
980+
mapperIdName = typeSpec.name().ToString() + ".default";
981+
mapperIdName = converter.mangleName(mapperIdName, *typeSpec.GetScope());
982+
}
983+
assert(converter.getMLIRSymbolTable()->lookup(mapperIdName) &&
984+
"mapper not found");
985+
mapperId = mlir::FlatSymbolRefAttr::get(&converter.getMLIRContext(),
986+
mapperIdName);
987+
mapperIdName.clear();
988+
}
973989
// Explicit map captures are captured ByRef by default,
974990
// optimisation passes may alter this to ByCopy or other capture
975991
// types to optimise
@@ -983,7 +999,8 @@ void ClauseProcessor::processMapObjects(
983999
static_cast<
9841000
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
9851001
mapTypeBits),
986-
mlir::omp::VariableCaptureKind::ByRef, baseOp.getType());
1002+
mlir::omp::VariableCaptureKind::ByRef, baseOp.getType(), false,
1003+
mapperId);
9871004

9881005
if (parentObj.has_value()) {
9891006
parentMemberIndices[parentObj.value()].addChildIndexAndMapToParent(
@@ -1014,6 +1031,7 @@ bool ClauseProcessor::processMap(
10141031
const auto &[mapType, typeMods, mappers, iterator, objects] = clause.t;
10151032
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
10161033
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE;
1034+
std::string mapperIdName;
10171035
// If the map type is specified, then process it else Tofrom is the
10181036
// default.
10191037
Map::MapType type = mapType.value_or(Map::MapType::Tofrom);
@@ -1057,13 +1075,17 @@ bool ClauseProcessor::processMap(
10571075
"Support for iterator modifiers is not implemented yet");
10581076
}
10591077
if (mappers) {
1060-
TODO(currentLocation,
1061-
"Support for mapper modifiers is not implemented yet");
1078+
assert(mappers->size() == 1 && "more than one mapper");
1079+
mapperIdName = mappers->front().v.id().symbol->name().ToString();
1080+
if (mapperIdName != "default")
1081+
mapperIdName = converter.mangleName(
1082+
mapperIdName, mappers->front().v.id().symbol->owner());
10621083
}
10631084

10641085
processMapObjects(stmtCtx, clauseLocation,
10651086
std::get<omp::ObjectList>(clause.t), mapTypeBits,
1066-
parentMemberIndices, result.mapVars, *ptrMapSyms);
1087+
parentMemberIndices, result.mapVars, *ptrMapSyms,
1088+
mapperIdName);
10671089
};
10681090

10691091
bool clauseFound = findRepeatableClause<omp::clause::Map>(process);

flang/lib/Lower/OpenMP/ClauseProcessor.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ class ClauseProcessor {
171171
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits,
172172
std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
173173
llvm::SmallVectorImpl<mlir::Value> &mapVars,
174-
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms) const;
174+
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms,
175+
std::string mapperIdName = "") const;
175176

176177
lower::AbstractConverter &converter;
177178
semantics::SemanticsContext &semaCtx;

flang/test/Lower/OpenMP/Todo/map-mapper.f90

-16
This file was deleted.
+14-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s
22
program p
33
integer, parameter :: n = 256
4-
real(8) :: a(256)
54
type t1
6-
integer :: x
5+
integer :: x(256)
76
end type t1
8-
!$omp declare mapper(xx : t1 :: nn) map(nn, nn%x)
9-
!$omp target map(mapper(xx), from:a)
10-
!CHECK: not yet implemented: Support for mapper modifiers is not implemented yet
7+
8+
!$omp declare mapper(xx : t1 :: nn) map(to: nn, nn%x)
9+
!$omp declare mapper(t1 :: nn) map(from: nn)
10+
11+
!CHECK-LABEL: omp.declare_mapper @_QQFt1.default : !fir.type<_QFTt1{x:!fir.array<256xi32>}>
12+
!CHECK-LABEL: omp.declare_mapper @_QQFxx : !fir.type<_QFTt1{x:!fir.array<256xi32>}>
13+
14+
type(t1) :: a, b
15+
!CHECK: %[[MAP_A:.*]] = omp.map.info var_ptr(%{{.*}} : {{.*}}, {{.*}}) mapper(@_QQFxx) map_clauses(tofrom) capture(ByRef) -> {{.*}} {name = "a"}
16+
!CHECK: %[[MAP_B:.*]] = omp.map.info var_ptr(%{{.*}} : {{.*}}, {{.*}}) mapper(@_QQFt1.default) map_clauses(tofrom) capture(ByRef) -> {{.*}} {name = "b"}
17+
!CHECK: omp.target map_entries(%[[MAP_A]] -> %{{.*}}, %[[MAP_B]] -> %{{.*}}, %{{.*}} -> %{{.*}}, %{{.*}} -> %{{.*}} : {{.*}}, {{.*}}, {{.*}}, {{.*}}) {
18+
!$omp target map(mapper(xx) : a) map(mapper(default) : b)
1119
do i = 1, n
12-
a(i) = 4.2
20+
b%x(i) = a%x(i)
1321
end do
1422
!$omp end target
1523
end program p

0 commit comments

Comments
 (0)