@@ -887,13 +887,64 @@ bool ClauseProcessor::processLink(
887
887
});
888
888
}
889
889
890
+ void ClauseProcessor::processMapObjects (
891
+ lower::StatementContext &stmtCtx, mlir::Location clauseLocation,
892
+ const omp::ObjectList &objects,
893
+ llvm::omp::OpenMPOffloadMappingFlags mapTypeBits,
894
+ std::map<const semantics::Symbol *,
895
+ llvm::SmallVector<OmpMapMemberIndicesData>> &parentMemberIndices,
896
+ llvm::SmallVectorImpl<mlir::Value> &mapVars,
897
+ llvm::SmallVectorImpl<const semantics::Symbol *> *mapSyms,
898
+ llvm::SmallVectorImpl<mlir::Location> *mapSymLocs,
899
+ llvm::SmallVectorImpl<mlir::Type> *mapSymTypes) const {
900
+ fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
901
+ for (const omp::Object &object : objects) {
902
+ llvm::SmallVector<mlir::Value> bounds;
903
+ std::stringstream asFortran;
904
+
905
+ lower::AddrAndBoundsInfo info =
906
+ lower::gatherDataOperandAddrAndBounds<mlir::omp::MapBoundsOp,
907
+ mlir::omp::MapBoundsType>(
908
+ converter, firOpBuilder, semaCtx, stmtCtx, *object.sym (),
909
+ object.ref (), clauseLocation, asFortran, bounds,
910
+ treatIndexAsSection);
911
+
912
+ // Explicit map captures are captured ByRef by default,
913
+ // optimisation passes may alter this to ByCopy or other capture
914
+ // types to optimise
915
+ mlir::Value baseOp = info.rawInput ;
916
+ auto location = mlir::NameLoc::get (
917
+ mlir::StringAttr::get (firOpBuilder.getContext (), asFortran.str ()),
918
+ baseOp.getLoc ());
919
+ mlir::omp::MapInfoOp mapOp = createMapInfoOp (
920
+ firOpBuilder, location, baseOp,
921
+ /* varPtrPtr=*/ mlir::Value{}, asFortran.str (), bounds,
922
+ /* members=*/ {}, /* membersIndex=*/ mlir::DenseIntElementsAttr{},
923
+ static_cast <
924
+ std::underlying_type_t <llvm::omp::OpenMPOffloadMappingFlags>>(
925
+ mapTypeBits),
926
+ mlir::omp::VariableCaptureKind::ByRef, baseOp.getType ());
927
+
928
+ if (object.sym ()->owner ().IsDerivedType ()) {
929
+ addChildIndexAndMapToParent (object, parentMemberIndices, mapOp, semaCtx);
930
+ } else {
931
+ mapVars.push_back (mapOp);
932
+ if (mapSyms)
933
+ mapSyms->push_back (object.sym ());
934
+ if (mapSymTypes)
935
+ mapSymTypes->push_back (baseOp.getType ());
936
+ if (mapSymLocs)
937
+ mapSymLocs->push_back (baseOp.getLoc ());
938
+ }
939
+ }
940
+ }
941
+
890
942
bool ClauseProcessor::processMap (
891
943
mlir::Location currentLocation, lower::StatementContext &stmtCtx,
892
944
mlir::omp::MapClauseOps &result,
893
945
llvm::SmallVectorImpl<const semantics::Symbol *> *mapSyms,
894
946
llvm::SmallVectorImpl<mlir::Location> *mapSymLocs,
895
947
llvm::SmallVectorImpl<mlir::Type> *mapSymTypes) const {
896
- fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
897
948
// We always require tracking of symbols, even if the caller does not,
898
949
// so we create an optionally used local set of symbols when the mapSyms
899
950
// argument is not present.
@@ -948,46 +999,10 @@ bool ClauseProcessor::processMap(
948
999
mapTypeBits |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO |
949
1000
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
950
1001
}
951
-
952
- for (const omp::Object &object : std::get<omp::ObjectList>(clause.t )) {
953
- llvm::SmallVector<mlir::Value> bounds;
954
- std::stringstream asFortran;
955
-
956
- lower::AddrAndBoundsInfo info =
957
- lower::gatherDataOperandAddrAndBounds<mlir::omp::MapBoundsOp,
958
- mlir::omp::MapBoundsType>(
959
- converter, firOpBuilder, semaCtx, stmtCtx, *object.sym (),
960
- object.ref (), clauseLocation, asFortran, bounds,
961
- treatIndexAsSection);
962
-
963
- // Explicit map captures are captured ByRef by default,
964
- // optimisation passes may alter this to ByCopy or other capture
965
- // types to optimise
966
- mlir::Value baseOp = info.rawInput ;
967
- auto location = mlir::NameLoc::get (
968
- mlir::StringAttr::get (firOpBuilder.getContext (), asFortran.str ()),
969
- baseOp.getLoc ());
970
- mlir::omp::MapInfoOp mapOp = createMapInfoOp (
971
- firOpBuilder, location, baseOp,
972
- /* varPtrPtr=*/ mlir::Value{}, asFortran.str (), bounds,
973
- /* members=*/ {}, /* membersIndex=*/ mlir::DenseIntElementsAttr{},
974
- static_cast <
975
- std::underlying_type_t <llvm::omp::OpenMPOffloadMappingFlags>>(
976
- mapTypeBits),
977
- mlir::omp::VariableCaptureKind::ByRef, baseOp.getType ());
978
-
979
- if (object.sym ()->owner ().IsDerivedType ()) {
980
- addChildIndexAndMapToParent (object, parentMemberIndices, mapOp,
981
- semaCtx);
982
- } else {
983
- result.mapVars .push_back (mapOp);
984
- ptrMapSyms->push_back (object.sym ());
985
- if (mapSymTypes)
986
- mapSymTypes->push_back (baseOp.getType ());
987
- if (mapSymLocs)
988
- mapSymLocs->push_back (baseOp.getLoc ());
989
- }
990
- }
1002
+ processMapObjects (stmtCtx, clauseLocation,
1003
+ std::get<omp::ObjectList>(clause.t ), mapTypeBits,
1004
+ parentMemberIndices, result.mapVars , ptrMapSyms,
1005
+ mapSymLocs, mapSymTypes);
991
1006
});
992
1007
993
1008
insertChildMapInfoIntoParent (converter, parentMemberIndices, result.mapVars ,
@@ -1050,27 +1065,55 @@ bool ClauseProcessor::processEnter(
1050
1065
}
1051
1066
1052
1067
bool ClauseProcessor::processUseDeviceAddr (
1053
- mlir::omp::UseDeviceAddrClauseOps &result,
1068
+ lower::StatementContext &stmtCtx, mlir::omp::UseDeviceAddrClauseOps &result,
1054
1069
llvm::SmallVectorImpl<mlir::Type> &useDeviceTypes,
1055
1070
llvm::SmallVectorImpl<mlir::Location> &useDeviceLocs,
1056
1071
llvm::SmallVectorImpl<const semantics::Symbol *> &useDeviceSyms) const {
1057
- return findRepeatableClause<omp::clause::UseDeviceAddr>(
1058
- [&](const omp::clause::UseDeviceAddr &clause, const parser::CharBlock &) {
1059
- addUseDeviceClause (converter, clause.v , result.useDeviceAddrVars ,
1060
- useDeviceTypes, useDeviceLocs, useDeviceSyms);
1072
+ std::map<const semantics::Symbol *,
1073
+ llvm::SmallVector<OmpMapMemberIndicesData>>
1074
+ parentMemberIndices;
1075
+ bool clauseFound = findRepeatableClause<omp::clause::UseDeviceAddr>(
1076
+ [&](const omp::clause::UseDeviceAddr &clause,
1077
+ const parser::CharBlock &source) {
1078
+ mlir::Location location = converter.genLocation (source);
1079
+ llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
1080
+ llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO |
1081
+ llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
1082
+ processMapObjects (stmtCtx, location, clause.v , mapTypeBits,
1083
+ parentMemberIndices, result.useDeviceAddrVars ,
1084
+ &useDeviceSyms, &useDeviceLocs, &useDeviceTypes);
1061
1085
});
1086
+
1087
+ insertChildMapInfoIntoParent (converter, parentMemberIndices,
1088
+ result.useDeviceAddrVars , useDeviceSyms,
1089
+ &useDeviceTypes, &useDeviceLocs);
1090
+ return clauseFound;
1062
1091
}
1063
1092
1064
1093
bool ClauseProcessor::processUseDevicePtr (
1065
- mlir::omp::UseDevicePtrClauseOps &result,
1094
+ lower::StatementContext &stmtCtx, mlir::omp::UseDevicePtrClauseOps &result,
1066
1095
llvm::SmallVectorImpl<mlir::Type> &useDeviceTypes,
1067
1096
llvm::SmallVectorImpl<mlir::Location> &useDeviceLocs,
1068
1097
llvm::SmallVectorImpl<const semantics::Symbol *> &useDeviceSyms) const {
1069
- return findRepeatableClause<omp::clause::UseDevicePtr>(
1070
- [&](const omp::clause::UseDevicePtr &clause, const parser::CharBlock &) {
1071
- addUseDeviceClause (converter, clause.v , result.useDevicePtrVars ,
1072
- useDeviceTypes, useDeviceLocs, useDeviceSyms);
1098
+ std::map<const semantics::Symbol *,
1099
+ llvm::SmallVector<OmpMapMemberIndicesData>>
1100
+ parentMemberIndices;
1101
+ bool clauseFound = findRepeatableClause<omp::clause::UseDevicePtr>(
1102
+ [&](const omp::clause::UseDevicePtr &clause,
1103
+ const parser::CharBlock &source) {
1104
+ mlir::Location location = converter.genLocation (source);
1105
+ llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
1106
+ llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO |
1107
+ llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
1108
+ processMapObjects (stmtCtx, location, clause.v , mapTypeBits,
1109
+ parentMemberIndices, result.useDevicePtrVars ,
1110
+ &useDeviceSyms, &useDeviceLocs, &useDeviceTypes);
1073
1111
});
1112
+
1113
+ insertChildMapInfoIntoParent (converter, parentMemberIndices,
1114
+ result.useDevicePtrVars , useDeviceSyms,
1115
+ &useDeviceTypes, &useDeviceLocs);
1116
+ return clauseFound;
1074
1117
}
1075
1118
1076
1119
} // namespace omp
0 commit comments