@@ -1446,6 +1446,41 @@ void ClauseProcessor::processMapObjects(
14461446 }
14471447}
14481448
1449+ // / Extract and mangle the mapper identifier name from a mapper clause.
1450+ // / Returns "__implicit_mapper" if no mapper is specified, or "default" if
1451+ // / the default mapper is specified, otherwise returns the mangled mapper name.
1452+ // / This handles both the Map clause (which uses a vector of mappers) and
1453+ // / To/From clauses (which use a DefinedOperator).
1454+ template <typename MapperType>
1455+ static std::string
1456+ getMapperIdentifier (lower::AbstractConverter &converter,
1457+ const std::optional<MapperType> &mapper) {
1458+ std::string mapperIdName = " __implicit_mapper" ;
1459+ if (mapper) {
1460+ const semantics::Symbol *mapperSym = nullptr ;
1461+
1462+ // Handle different mapper types
1463+ if constexpr (std::is_same_v<MapperType, omp::clause::DefinedOperator>) {
1464+ // For To/From clauses: mapper is a DefinedOperator
1465+ assert (mapper->size () == 1 && " more than one mapper" );
1466+ mapperSym = mapper->front ().v .id ().symbol ;
1467+ } else {
1468+ // For Map clause: mappers is a vector
1469+ assert (mapper->size () == 1 && " more than one mapper" );
1470+ mapperSym = mapper->front ().v .id ().symbol ;
1471+ }
1472+
1473+ mapperIdName = mapperSym->name ().ToString ();
1474+ if (mapperIdName != " default" ) {
1475+ // Mangle with the ultimate owner so that use-associated mapper
1476+ // identifiers resolve to the same symbol as their defining scope.
1477+ const semantics::Symbol &ultimate = mapperSym->GetUltimate ();
1478+ mapperIdName = converter.mangleName (mapperIdName, ultimate.owner ());
1479+ }
1480+ }
1481+ return mapperIdName;
1482+ }
1483+
14491484bool ClauseProcessor::processMap (
14501485 mlir::Location currentLocation, lower::StatementContext &stmtCtx,
14511486 mlir::omp::MapClauseOps &result, llvm::omp::Directive directive,
@@ -1514,17 +1549,7 @@ bool ClauseProcessor::processMap(
15141549 TODO (currentLocation,
15151550 " Support for iterator modifiers is not implemented yet" );
15161551 }
1517- if (mappers) {
1518- assert (mappers->size () == 1 && " more than one mapper" );
1519- const semantics::Symbol *mapperSym = mappers->front ().v .id ().symbol ;
1520- mapperIdName = mapperSym->name ().ToString ();
1521- if (mapperIdName != " default" ) {
1522- // Mangle with the ultimate owner so that use-associated mapper
1523- // identifiers resolve to the same symbol as their defining scope.
1524- const semantics::Symbol &ultimate = mapperSym->GetUltimate ();
1525- mapperIdName = converter.mangleName (mapperIdName, ultimate.owner ());
1526- }
1527- }
1552+ mapperIdName = getMapperIdentifier (converter, mappers);
15281553
15291554 processMapObjects (stmtCtx, clauseLocation,
15301555 std::get<omp::ObjectList>(clause.t ), mapTypeBits,
@@ -1556,19 +1581,7 @@ bool ClauseProcessor::processMotionClauses(lower::StatementContext &stmtCtx,
15561581 mapTypeBits |= mlir::omp::ClauseMapFlags::present;
15571582
15581583 // Support motion modifiers: mapper, iterator.
1559- std::string mapperIdName = " __implicit_mapper" ;
1560- if (mapper) {
1561- // Only one mapper is allowed by the parser here.
1562- assert (mapper->size () == 1 && " more than one mapper" );
1563- const semantics::Symbol *mapperSym = mapper->front ().v .id ().symbol ;
1564- mapperIdName = mapperSym->name ().ToString ();
1565- if (mapperIdName != " default" ) {
1566- // Mangle with the ultimate owner so that use-associated mapper
1567- // identifiers resolve to the same symbol as their defining scope.
1568- const semantics::Symbol &ultimate = mapperSym->GetUltimate ();
1569- mapperIdName = converter.mangleName (mapperIdName, ultimate.owner ());
1570- }
1571- }
1584+ std::string mapperIdName = getMapperIdentifier (converter, mapper);
15721585 if (iterator) {
15731586 TODO (clauseLocation, " Iterator modifier is not supported yet" );
15741587 }
0 commit comments