Skip to content

Commit d7bb230

Browse files
committed
Add flang lowering changes for mapper field in map clause.
1 parent e905951 commit d7bb230

File tree

4 files changed

+52
-22
lines changed

4 files changed

+52
-22
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -969,8 +969,10 @@ void ClauseProcessor::processMapObjects(
969969
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits,
970970
std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
971971
llvm::SmallVectorImpl<mlir::Value> &mapVars,
972-
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms) const {
972+
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms,
973+
std::string mapperIdName) const {
973974
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
975+
mlir::FlatSymbolRefAttr mapperId;
974976

975977
for (const omp::Object &object : objects) {
976978
llvm::SmallVector<mlir::Value> bounds;
@@ -1003,6 +1005,20 @@ void ClauseProcessor::processMapObjects(
10031005
}
10041006
}
10051007

1008+
if (!mapperIdName.empty()) {
1009+
if (mapperIdName == "default") {
1010+
auto &typeSpec = object.sym()->owner().IsDerivedType()
1011+
? *object.sym()->owner().derivedTypeSpec()
1012+
: object.sym()->GetType()->derivedTypeSpec();
1013+
mapperIdName = typeSpec.name().ToString() + ".default";
1014+
mapperIdName = converter.mangleName(mapperIdName, *typeSpec.GetScope());
1015+
}
1016+
assert(converter.getMLIRSymbolTable()->lookup(mapperIdName) &&
1017+
"mapper not found");
1018+
mapperId = mlir::FlatSymbolRefAttr::get(&converter.getMLIRContext(),
1019+
mapperIdName);
1020+
mapperIdName.clear();
1021+
}
10061022
// Explicit map captures are captured ByRef by default,
10071023
// optimisation passes may alter this to ByCopy or other capture
10081024
// types to optimise
@@ -1016,7 +1032,8 @@ void ClauseProcessor::processMapObjects(
10161032
static_cast<
10171033
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
10181034
mapTypeBits),
1019-
mlir::omp::VariableCaptureKind::ByRef, baseOp.getType());
1035+
mlir::omp::VariableCaptureKind::ByRef, baseOp.getType(), false,
1036+
mapperId);
10201037

10211038
if (parentObj.has_value()) {
10221039
parentMemberIndices[parentObj.value()].addChildIndexAndMapToParent(
@@ -1047,6 +1064,7 @@ bool ClauseProcessor::processMap(
10471064
const auto &[mapType, typeMods, mappers, iterator, objects] = clause.t;
10481065
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
10491066
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE;
1067+
std::string mapperIdName;
10501068
// If the map type is specified, then process it else Tofrom is the
10511069
// default.
10521070
Map::MapType type = mapType.value_or(Map::MapType::Tofrom);
@@ -1090,13 +1108,17 @@ bool ClauseProcessor::processMap(
10901108
"Support for iterator modifiers is not implemented yet");
10911109
}
10921110
if (mappers) {
1093-
TODO(currentLocation,
1094-
"Support for mapper modifiers is not implemented yet");
1111+
assert(mappers->size() == 1 && "more than one mapper");
1112+
mapperIdName = mappers->front().v.id().symbol->name().ToString();
1113+
if (mapperIdName != "default")
1114+
mapperIdName = converter.mangleName(
1115+
mapperIdName, mappers->front().v.id().symbol->owner());
10951116
}
10961117

10971118
processMapObjects(stmtCtx, clauseLocation,
10981119
std::get<omp::ObjectList>(clause.t), mapTypeBits,
1099-
parentMemberIndices, result.mapVars, *ptrMapSyms);
1120+
parentMemberIndices, result.mapVars, *ptrMapSyms,
1121+
mapperIdName);
11001122
};
11011123

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

flang/lib/Lower/OpenMP/ClauseProcessor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ class ClauseProcessor {
175175
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits,
176176
std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
177177
llvm::SmallVectorImpl<mlir::Value> &mapVars,
178-
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms) const;
178+
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms,
179+
std::string mapperIdName = "") const;
179180

180181
lower::AbstractConverter &converter;
181182
semantics::SemanticsContext &semaCtx;

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

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s
2+
program p
3+
integer, parameter :: n = 256
4+
type t1
5+
integer :: x(256)
6+
end type t1
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)
19+
do i = 1, n
20+
b%x(i) = a%x(i)
21+
end do
22+
!$omp end target
23+
end program p

0 commit comments

Comments
 (0)