@@ -929,18 +929,35 @@ void ClauseProcessor::processMapObjects(
929929 llvm::StringRef mapperIdNameRef) const {
930930 fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
931931
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+
932953 // Create the mapper symbol from its name, if specified.
933954 mlir::FlatSymbolRefAttr mapperId;
934- if (!mapperIdNameRef.empty () && !objects.empty ()) {
955+ if (!mapperIdNameRef.empty () && !objects.empty () &&
956+ mapperIdNameRef != " __implicit_mapper" ) {
935957 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);
944961 assert (converter.getModuleOp ().lookupSymbol (mapperIdName) &&
945962 " mapper not found" );
946963 mapperId =
@@ -978,6 +995,15 @@ void ClauseProcessor::processMapObjects(
978995 }
979996 }
980997
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+
9811007 // Explicit map captures are captured ByRef by default,
9821008 // optimisation passes may alter this to ByCopy or other capture
9831009 // types to optimise
@@ -1023,7 +1049,7 @@ bool ClauseProcessor::processMap(
10231049 const auto &[mapType, typeMods, mappers, iterator, objects] = clause.t ;
10241050 llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
10251051 llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE;
1026- std::string mapperIdName;
1052+ std::string mapperIdName = " __implicit_mapper " ;
10271053 // If the map type is specified, then process it else Tofrom is the
10281054 // default.
10291055 Map::MapType type = mapType.value_or (Map::MapType::Tofrom);
0 commit comments