Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 45 additions & 19 deletions flang/lib/Lower/OpenMP/ClauseProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,41 @@ void ClauseProcessor::processMapObjects(
}
}

/// Extract and mangle the mapper identifier name from a mapper clause.
/// Returns "__implicit_mapper" if no mapper is specified, or "default" if
/// the default mapper is specified, otherwise returns the mangled mapper name.
/// This handles both the Map clause (which uses a vector of mappers) and
/// To/From clauses (which use a DefinedOperator).
template <typename MapperType>
static std::string
getMapperIdentifier(lower::AbstractConverter &converter,
const std::optional<MapperType> &mapper) {
std::string mapperIdName = "__implicit_mapper";
if (mapper) {
const semantics::Symbol *mapperSym = nullptr;

// Handle different mapper types
if constexpr (std::is_same_v<MapperType, omp::clause::DefinedOperator>) {
// For To/From clauses: mapper is a DefinedOperator
assert(mapper->size() == 1 && "more than one mapper");
mapperSym = mapper->front().v.id().symbol;
} else {
// For Map clause: mappers is a vector
assert(mapper->size() == 1 && "more than one mapper");
mapperSym = mapper->front().v.id().symbol;
}

mapperIdName = mapperSym->name().ToString();
if (mapperIdName != "default") {
// Mangle with the ultimate owner so that use-associated mapper
// identifiers resolve to the same symbol as their defining scope.
const semantics::Symbol &ultimate = mapperSym->GetUltimate();
mapperIdName = converter.mangleName(mapperIdName, ultimate.owner());
}
}
return mapperIdName;
}

bool ClauseProcessor::processMap(
mlir::Location currentLocation, lower::StatementContext &stmtCtx,
mlir::omp::MapClauseOps &result, llvm::omp::Directive directive,
Expand Down Expand Up @@ -1514,17 +1549,7 @@ bool ClauseProcessor::processMap(
TODO(currentLocation,
"Support for iterator modifiers is not implemented yet");
}
if (mappers) {
assert(mappers->size() == 1 && "more than one mapper");
const semantics::Symbol *mapperSym = mappers->front().v.id().symbol;
mapperIdName = mapperSym->name().ToString();
if (mapperIdName != "default") {
// Mangle with the ultimate owner so that use-associated mapper
// identifiers resolve to the same symbol as their defining scope.
const semantics::Symbol &ultimate = mapperSym->GetUltimate();
mapperIdName = converter.mangleName(mapperIdName, ultimate.owner());
}
}
mapperIdName = getMapperIdentifier(converter, mappers);

processMapObjects(stmtCtx, clauseLocation,
std::get<omp::ObjectList>(clause.t), mapTypeBits,
Expand All @@ -1548,21 +1573,22 @@ bool ClauseProcessor::processMotionClauses(lower::StatementContext &stmtCtx,
mlir::Location clauseLocation = converter.genLocation(source);
const auto &[expectation, mapper, iterator, objects] = clause.t;

// TODO Support motion modifiers: mapper, iterator.
if (mapper) {
TODO(clauseLocation, "Mapper modifier is not supported yet");
} else if (iterator) {
TODO(clauseLocation, "Iterator modifier is not supported yet");
}

mlir::omp::ClauseMapFlags mapTypeBits =
std::is_same_v<llvm::remove_cvref_t<decltype(clause)>, omp::clause::To>
? mlir::omp::ClauseMapFlags::to
: mlir::omp::ClauseMapFlags::from;
if (expectation && *expectation == omp::clause::To::Expectation::Present)
mapTypeBits |= mlir::omp::ClauseMapFlags::present;

// Support motion modifiers: mapper, iterator.
std::string mapperIdName = getMapperIdentifier(converter, mapper);
if (iterator) {
TODO(clauseLocation, "Iterator modifier is not supported yet");
}

processMapObjects(stmtCtx, clauseLocation, objects, mapTypeBits,
parentMemberIndices, result.mapVars, mapSymbols);
parentMemberIndices, result.mapVars, mapSymbols,
mapperIdName);
};

bool clauseFound = findRepeatableClause<omp::clause::To>(callbackFn);
Expand Down
Loading
Loading