-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[MLIR][OpenMP] Add Lowering support for OpenMP custom mappers in map clause #121001
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
Conversation
@llvm/pr-subscribers-flang-openmp Author: Akash Banerjee (TIFitis) ChangesAdd Lowering support for OpenMP mapper field in mapInfoOp. Depends on #120994. Full diff: https://github.com/llvm/llvm-project/pull/121001.diff 4 Files Affected:
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index 3c9831120351ee..0bc9f4919330e4 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -936,8 +936,10 @@ void ClauseProcessor::processMapObjects(
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits,
std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
llvm::SmallVectorImpl<mlir::Value> &mapVars,
- llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms) const {
+ llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms,
+ std::string mapperIdName) const {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+ mlir::FlatSymbolRefAttr mapperId;
for (const omp::Object &object : objects) {
llvm::SmallVector<mlir::Value> bounds;
@@ -970,6 +972,20 @@ void ClauseProcessor::processMapObjects(
}
}
+ if (!mapperIdName.empty()) {
+ if (mapperIdName == "default") {
+ auto &typeSpec = object.sym()->owner().IsDerivedType()
+ ? *object.sym()->owner().derivedTypeSpec()
+ : object.sym()->GetType()->derivedTypeSpec();
+ mapperIdName = typeSpec.name().ToString() + ".default";
+ mapperIdName = converter.mangleName(mapperIdName, *typeSpec.GetScope());
+ }
+ assert(converter.getMLIRSymbolTable()->lookup(mapperIdName) &&
+ "mapper not found");
+ mapperId = mlir::FlatSymbolRefAttr::get(&converter.getMLIRContext(),
+ mapperIdName);
+ mapperIdName.clear();
+ }
// Explicit map captures are captured ByRef by default,
// optimisation passes may alter this to ByCopy or other capture
// types to optimise
@@ -983,7 +999,8 @@ void ClauseProcessor::processMapObjects(
static_cast<
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
mapTypeBits),
- mlir::omp::VariableCaptureKind::ByRef, baseOp.getType());
+ mlir::omp::VariableCaptureKind::ByRef, baseOp.getType(), false,
+ mapperId);
if (parentObj.has_value()) {
parentMemberIndices[parentObj.value()].addChildIndexAndMapToParent(
@@ -1014,6 +1031,7 @@ bool ClauseProcessor::processMap(
const auto &[mapType, typeMods, mappers, iterator, objects] = clause.t;
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE;
+ std::string mapperIdName;
// If the map type is specified, then process it else Tofrom is the
// default.
Map::MapType type = mapType.value_or(Map::MapType::Tofrom);
@@ -1057,13 +1075,17 @@ bool ClauseProcessor::processMap(
"Support for iterator modifiers is not implemented yet");
}
if (mappers) {
- TODO(currentLocation,
- "Support for mapper modifiers is not implemented yet");
+ assert(mappers->size() == 1 && "more than one mapper");
+ mapperIdName = mappers->front().v.id().symbol->name().ToString();
+ if (mapperIdName != "default")
+ mapperIdName = converter.mangleName(
+ mapperIdName, mappers->front().v.id().symbol->owner());
}
processMapObjects(stmtCtx, clauseLocation,
std::get<omp::ObjectList>(clause.t), mapTypeBits,
- parentMemberIndices, result.mapVars, *ptrMapSyms);
+ parentMemberIndices, result.mapVars, *ptrMapSyms,
+ mapperIdName);
};
bool clauseFound = findRepeatableClause<omp::clause::Map>(process);
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h b/flang/lib/Lower/OpenMP/ClauseProcessor.h
index 7b047d4a7567ad..34eebf16ca17b0 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.h
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h
@@ -171,7 +171,8 @@ class ClauseProcessor {
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits,
std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
llvm::SmallVectorImpl<mlir::Value> &mapVars,
- llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms) const;
+ llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms,
+ std::string mapperIdName = "") const;
lower::AbstractConverter &converter;
semantics::SemanticsContext &semaCtx;
diff --git a/flang/test/Lower/OpenMP/Todo/map-mapper.f90 b/flang/test/Lower/OpenMP/Todo/map-mapper.f90
deleted file mode 100644
index 9554ffd5fda7bd..00000000000000
--- a/flang/test/Lower/OpenMP/Todo/map-mapper.f90
+++ /dev/null
@@ -1,16 +0,0 @@
-! RUN: not %flang_fc1 -emit-fir -fopenmp -fopenmp-version=50 %s 2>&1 | FileCheck %s
-program p
- integer, parameter :: n = 256
- real(8) :: a(256)
- !! TODO: Add declare mapper, when it works to lower this construct
- !!type t1
- !! integer :: x
- !!end type t1
- !!!$omp declare mapper(xx : t1 :: nn) map(nn, nn%x)
- !$omp target map(mapper(xx), from:a)
-!CHECK: not yet implemented: Support for mapper modifiers is not implemented yet
- do i=1,n
- a(i) = 4.2
- end do
- !$omp end target
-end program p
diff --git a/flang/test/Lower/OpenMP/map-mapper.f90 b/flang/test/Lower/OpenMP/map-mapper.f90
new file mode 100644
index 00000000000000..856fff834643e4
--- /dev/null
+++ b/flang/test/Lower/OpenMP/map-mapper.f90
@@ -0,0 +1,23 @@
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s
+program p
+ integer, parameter :: n = 256
+ type t1
+ integer :: x(256)
+ end type t1
+
+ !$omp declare mapper(xx : t1 :: nn) map(to: nn, nn%x)
+ !$omp declare mapper(t1 :: nn) map(from: nn)
+
+ !CHECK-LABEL: omp.declare_mapper @_QQFt1.default : !fir.type<_QFTt1{x:!fir.array<256xi32>}>
+ !CHECK-LABEL: omp.declare_mapper @_QQFxx : !fir.type<_QFTt1{x:!fir.array<256xi32>}>
+
+ type(t1) :: a, b
+ !CHECK: %[[MAP_A:.*]] = omp.map.info var_ptr(%{{.*}} : {{.*}}, {{.*}}) mapper(@_QQFxx) map_clauses(tofrom) capture(ByRef) -> {{.*}} {name = "a"}
+ !CHECK: %[[MAP_B:.*]] = omp.map.info var_ptr(%{{.*}} : {{.*}}, {{.*}}) mapper(@_QQFt1.default) map_clauses(tofrom) capture(ByRef) -> {{.*}} {name = "b"}
+ !CHECK: omp.target map_entries(%[[MAP_A]] -> %{{.*}}, %[[MAP_B]] -> %{{.*}}, %{{.*}} -> %{{.*}}, %{{.*}} -> %{{.*}} : {{.*}}, {{.*}}, {{.*}}, {{.*}}) {
+ !$omp target map(mapper(xx) : a) map(mapper(default) : b)
+ do i = 1, n
+ b%x(i) = a%x(i)
+ end do
+ !$omp end target
+end program p
|
@llvm/pr-subscribers-flang-fir-hlfir Author: Akash Banerjee (TIFitis) ChangesAdd Lowering support for OpenMP mapper field in mapInfoOp. Depends on #120994. Full diff: https://github.com/llvm/llvm-project/pull/121001.diff 4 Files Affected:
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index 3c9831120351ee..0bc9f4919330e4 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -936,8 +936,10 @@ void ClauseProcessor::processMapObjects(
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits,
std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
llvm::SmallVectorImpl<mlir::Value> &mapVars,
- llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms) const {
+ llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms,
+ std::string mapperIdName) const {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+ mlir::FlatSymbolRefAttr mapperId;
for (const omp::Object &object : objects) {
llvm::SmallVector<mlir::Value> bounds;
@@ -970,6 +972,20 @@ void ClauseProcessor::processMapObjects(
}
}
+ if (!mapperIdName.empty()) {
+ if (mapperIdName == "default") {
+ auto &typeSpec = object.sym()->owner().IsDerivedType()
+ ? *object.sym()->owner().derivedTypeSpec()
+ : object.sym()->GetType()->derivedTypeSpec();
+ mapperIdName = typeSpec.name().ToString() + ".default";
+ mapperIdName = converter.mangleName(mapperIdName, *typeSpec.GetScope());
+ }
+ assert(converter.getMLIRSymbolTable()->lookup(mapperIdName) &&
+ "mapper not found");
+ mapperId = mlir::FlatSymbolRefAttr::get(&converter.getMLIRContext(),
+ mapperIdName);
+ mapperIdName.clear();
+ }
// Explicit map captures are captured ByRef by default,
// optimisation passes may alter this to ByCopy or other capture
// types to optimise
@@ -983,7 +999,8 @@ void ClauseProcessor::processMapObjects(
static_cast<
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
mapTypeBits),
- mlir::omp::VariableCaptureKind::ByRef, baseOp.getType());
+ mlir::omp::VariableCaptureKind::ByRef, baseOp.getType(), false,
+ mapperId);
if (parentObj.has_value()) {
parentMemberIndices[parentObj.value()].addChildIndexAndMapToParent(
@@ -1014,6 +1031,7 @@ bool ClauseProcessor::processMap(
const auto &[mapType, typeMods, mappers, iterator, objects] = clause.t;
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE;
+ std::string mapperIdName;
// If the map type is specified, then process it else Tofrom is the
// default.
Map::MapType type = mapType.value_or(Map::MapType::Tofrom);
@@ -1057,13 +1075,17 @@ bool ClauseProcessor::processMap(
"Support for iterator modifiers is not implemented yet");
}
if (mappers) {
- TODO(currentLocation,
- "Support for mapper modifiers is not implemented yet");
+ assert(mappers->size() == 1 && "more than one mapper");
+ mapperIdName = mappers->front().v.id().symbol->name().ToString();
+ if (mapperIdName != "default")
+ mapperIdName = converter.mangleName(
+ mapperIdName, mappers->front().v.id().symbol->owner());
}
processMapObjects(stmtCtx, clauseLocation,
std::get<omp::ObjectList>(clause.t), mapTypeBits,
- parentMemberIndices, result.mapVars, *ptrMapSyms);
+ parentMemberIndices, result.mapVars, *ptrMapSyms,
+ mapperIdName);
};
bool clauseFound = findRepeatableClause<omp::clause::Map>(process);
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h b/flang/lib/Lower/OpenMP/ClauseProcessor.h
index 7b047d4a7567ad..34eebf16ca17b0 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.h
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h
@@ -171,7 +171,8 @@ class ClauseProcessor {
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits,
std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices,
llvm::SmallVectorImpl<mlir::Value> &mapVars,
- llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms) const;
+ llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms,
+ std::string mapperIdName = "") const;
lower::AbstractConverter &converter;
semantics::SemanticsContext &semaCtx;
diff --git a/flang/test/Lower/OpenMP/Todo/map-mapper.f90 b/flang/test/Lower/OpenMP/Todo/map-mapper.f90
deleted file mode 100644
index 9554ffd5fda7bd..00000000000000
--- a/flang/test/Lower/OpenMP/Todo/map-mapper.f90
+++ /dev/null
@@ -1,16 +0,0 @@
-! RUN: not %flang_fc1 -emit-fir -fopenmp -fopenmp-version=50 %s 2>&1 | FileCheck %s
-program p
- integer, parameter :: n = 256
- real(8) :: a(256)
- !! TODO: Add declare mapper, when it works to lower this construct
- !!type t1
- !! integer :: x
- !!end type t1
- !!!$omp declare mapper(xx : t1 :: nn) map(nn, nn%x)
- !$omp target map(mapper(xx), from:a)
-!CHECK: not yet implemented: Support for mapper modifiers is not implemented yet
- do i=1,n
- a(i) = 4.2
- end do
- !$omp end target
-end program p
diff --git a/flang/test/Lower/OpenMP/map-mapper.f90 b/flang/test/Lower/OpenMP/map-mapper.f90
new file mode 100644
index 00000000000000..856fff834643e4
--- /dev/null
+++ b/flang/test/Lower/OpenMP/map-mapper.f90
@@ -0,0 +1,23 @@
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s
+program p
+ integer, parameter :: n = 256
+ type t1
+ integer :: x(256)
+ end type t1
+
+ !$omp declare mapper(xx : t1 :: nn) map(to: nn, nn%x)
+ !$omp declare mapper(t1 :: nn) map(from: nn)
+
+ !CHECK-LABEL: omp.declare_mapper @_QQFt1.default : !fir.type<_QFTt1{x:!fir.array<256xi32>}>
+ !CHECK-LABEL: omp.declare_mapper @_QQFxx : !fir.type<_QFTt1{x:!fir.array<256xi32>}>
+
+ type(t1) :: a, b
+ !CHECK: %[[MAP_A:.*]] = omp.map.info var_ptr(%{{.*}} : {{.*}}, {{.*}}) mapper(@_QQFxx) map_clauses(tofrom) capture(ByRef) -> {{.*}} {name = "a"}
+ !CHECK: %[[MAP_B:.*]] = omp.map.info var_ptr(%{{.*}} : {{.*}}, {{.*}}) mapper(@_QQFt1.default) map_clauses(tofrom) capture(ByRef) -> {{.*}} {name = "b"}
+ !CHECK: omp.target map_entries(%[[MAP_A]] -> %{{.*}}, %[[MAP_B]] -> %{{.*}}, %{{.*}} -> %{{.*}}, %{{.*}} -> %{{.*}} : {{.*}}, {{.*}}, {{.*}}, {{.*}}) {
+ !$omp target map(mapper(xx) : a) map(mapper(default) : b)
+ do i = 1, n
+ b%x(i) = a%x(i)
+ end do
+ !$omp end target
+end program p
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
ed3cb3d
to
5f892bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, LGTM. Just some minor nits, no need to wait for another review by me.
@@ -936,8 +936,10 @@ void ClauseProcessor::processMapObjects( | |||
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits, | |||
std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices, | |||
llvm::SmallVectorImpl<mlir::Value> &mapVars, | |||
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms) const { | |||
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms, | |||
std::string mapperIdName) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Use llvm::StringRef
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, even we accept a StringRef
, we would have to immediately copy it to a std:string
as we need to pass an lvalue
to converter.mangleName
. As such, wouldn't it be better to accept it as a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accepting a StringRef
gives us more flexibility while passing arguments (plus, it gives us the option to rework the implementation to avoid copies later on), it follows LLVM recommendations and I don't see any drawbacks from using it here. In my opinion, I still think it's a better option. If you feel strongly about it, this is not a blocking issue for me.
5ca5a1f
to
86513d3
Compare
5f892bb
to
802c3df
Compare
86513d3
to
e93c05d
Compare
802c3df
to
1b3e235
Compare
e93c05d
to
e905951
Compare
1b3e235
to
c5b4f50
Compare
e905951
to
19e22eb
Compare
c5b4f50
to
e5d0cd9
Compare
19e22eb
to
04831ef
Compare
e5d0cd9
to
20a5496
Compare
04831ef
to
03838f7
Compare
20a5496
to
862fda5
Compare
…clause (llvm#121001) Add Lowering support for OpenMP mapper field in mapInfoOp. NOTE: This patch only supports explicit mapper lowering. I'll add a separate PR soon which handles implicit default mapper recognition. Depends on llvm#120994.
…P DeclareMapper (llvm#121005) Add conversion support from FIR to LLVM Dialect for OMP DeclareMapper. Depends on llvm#121001
land and revert: 785a5b4 [MLIR][OpenMP] Add LLVM translation support for OpenMP UserDefinedMappers (llvm#124746) d6ab12c [MLIR][OpenMP] Add conversion support from FIR to LLVM Dialect for OMP DeclareMapper (llvm#121005) 886b2ed [MLIR][OpenMP] Add Lowering support for OpenMP custom mappers in map clause (llvm#121001) ee17955 [MLIR][OpenMP] Add OMP Mapper field to MapInfoOp (llvm#120994)
…clause (llvm#121001) Add Lowering support for OpenMP mapper field in mapInfoOp. NOTE: This patch only supports explicit mapper lowering. I'll add a separate PR soon which handles implicit default mapper recognition. Depends on llvm#120994.
…P DeclareMapper (llvm#121005) Add conversion support from FIR to LLVM Dialect for OMP DeclareMapper. Depends on llvm#121001
…clause (llvm#121001) Add Lowering support for OpenMP mapper field in mapInfoOp. NOTE: This patch only supports explicit mapper lowering. I'll add a separate PR soon which handles implicit default mapper recognition. Depends on llvm#120994.
…P DeclareMapper (llvm#121005) Add conversion support from FIR to LLVM Dialect for OMP DeclareMapper. Depends on llvm#121001
Add Lowering support for OpenMP mapper field in mapInfoOp.
NOTE: This patch only supports explicit mapper lowering. I'll add a separate PR soon which handles implicit default mapper recognition.
Depends on #120994.