@@ -929,18 +929,35 @@ void ClauseProcessor::processMapObjects(
929
929
llvm::StringRef mapperIdNameRef) const {
930
930
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
931
931
932
+ auto getDefaultMapperID = [&](const omp::Object &object,
933
+ std::string &mapperIdName) {
934
+ if (!mlir::isa<mlir::omp::DeclareMapperOp>(
935
+ firOpBuilder.getRegion ().getParentOp ())) {
936
+ const semantics::DerivedTypeSpec *typeSpec = nullptr ;
937
+
938
+ if (object.sym ()->owner ().IsDerivedType ())
939
+ typeSpec = object.sym ()->owner ().derivedTypeSpec ();
940
+ else if (object.sym ()->GetType () &&
941
+ object.sym ()->GetType ()->category () ==
942
+ semantics::DeclTypeSpec::TypeDerived)
943
+ typeSpec = &object.sym ()->GetType ()->derivedTypeSpec ();
944
+
945
+ if (typeSpec) {
946
+ mapperIdName = typeSpec->name ().ToString () + " .default" ;
947
+ mapperIdName =
948
+ converter.mangleName (mapperIdName, *typeSpec->GetScope ());
949
+ }
950
+ }
951
+ };
952
+
932
953
// Create the mapper symbol from its name, if specified.
933
954
mlir::FlatSymbolRefAttr mapperId;
934
- if (!mapperIdNameRef.empty () && !objects.empty ()) {
955
+ if (!mapperIdNameRef.empty () && !objects.empty () &&
956
+ mapperIdNameRef != " __implicit_mapper" ) {
935
957
std::string mapperIdName = mapperIdNameRef.str ();
936
- if (mapperIdName == " default" ) {
937
- const omp::Object &object = objects.front ();
938
- auto &typeSpec = object.sym ()->owner ().IsDerivedType ()
939
- ? *object.sym ()->owner ().derivedTypeSpec ()
940
- : object.sym ()->GetType ()->derivedTypeSpec ();
941
- mapperIdName = typeSpec.name ().ToString () + " .default" ;
942
- mapperIdName = converter.mangleName (mapperIdName, *typeSpec.GetScope ());
943
- }
958
+ const omp::Object &object = objects.front ();
959
+ if (mapperIdNameRef == " default" )
960
+ getDefaultMapperID (object, mapperIdName);
944
961
assert (converter.getModuleOp ().lookupSymbol (mapperIdName) &&
945
962
" mapper not found" );
946
963
mapperId =
@@ -978,6 +995,15 @@ void ClauseProcessor::processMapObjects(
978
995
}
979
996
}
980
997
998
+ if (mapperIdNameRef == " __implicit_mapper" ) {
999
+ std::string mapperIdName;
1000
+ getDefaultMapperID (object, mapperIdName);
1001
+ mapperId = converter.getModuleOp ().lookupSymbol (mapperIdName)
1002
+ ? mlir::FlatSymbolRefAttr::get (&converter.getMLIRContext (),
1003
+ mapperIdName)
1004
+ : mlir::FlatSymbolRefAttr ();
1005
+ }
1006
+
981
1007
// Explicit map captures are captured ByRef by default,
982
1008
// optimisation passes may alter this to ByCopy or other capture
983
1009
// types to optimise
@@ -1023,7 +1049,7 @@ bool ClauseProcessor::processMap(
1023
1049
const auto &[mapType, typeMods, mappers, iterator, objects] = clause.t ;
1024
1050
llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
1025
1051
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE;
1026
- std::string mapperIdName;
1052
+ std::string mapperIdName = " __implicit_mapper " ;
1027
1053
// If the map type is specified, then process it else Tofrom is the
1028
1054
// default.
1029
1055
Map::MapType type = mapType.value_or (Map::MapType::Tofrom);
0 commit comments