diff options
| author | Sergio Afonso <safonsof@amd.com> | 2025-03-12 11:54:29 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-12 11:54:29 +0000 |
| commit | cf68c9378b0c935a1fe0ba2b3b3276d16cf2b09a (patch) | |
| tree | 38462cef3f4a08b292d92d72d75bdb5b7a50fd6c | |
| parent | 032f83b743b7783483b380f422dbc2f10fab71ee (diff) | |
| download | llvm-cf68c9378b0c935a1fe0ba2b3b3276d16cf2b09a.zip llvm-cf68c9378b0c935a1fe0ba2b3b3276d16cf2b09a.tar.gz llvm-cf68c9378b0c935a1fe0ba2b3b3276d16cf2b09a.tar.bz2 | |
[Flang][OpenMP] Move declare mapper sym creation outside loop, NFC (#130794)
This patch simplifies the definition of
`ClauseProcessor::processMapObjects` by hoisting the creation of the
MLIR symbol associated to an existing `omp.declare_mapper` operation
outside of the loop processing all mapped objects.
That change removes some inter-iteration dependencies that made the
implementation more difficult to follow.
| -rw-r--r-- | flang/lib/Lower/OpenMP/ClauseProcessor.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp index dab3182..dda2ac7 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp @@ -928,8 +928,24 @@ void ClauseProcessor::processMapObjects( llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms, llvm::StringRef mapperIdNameRef) const { fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); + + // Create the mapper symbol from its name, if specified. mlir::FlatSymbolRefAttr mapperId; - std::string mapperIdName = mapperIdNameRef.str(); + if (!mapperIdNameRef.empty() && !objects.empty()) { + std::string mapperIdName = mapperIdNameRef.str(); + if (mapperIdName == "default") { + const omp::Object &object = objects.front(); + auto &typeSpec = object.sym()->owner().IsDerivedType() + ? *object.sym()->owner().derivedTypeSpec() + : object.sym()->GetType()->derivedTypeSpec(); + mapperIdName = typeSpec.name().ToString() + ".default"; + mapperIdName = converter.mangleName(mapperIdName, *typeSpec.GetScope()); + } + assert(converter.getModuleOp().lookupSymbol(mapperIdName) && + "mapper not found"); + mapperId = + mlir::FlatSymbolRefAttr::get(&converter.getMLIRContext(), mapperIdName); + } for (const omp::Object &object : objects) { llvm::SmallVector<mlir::Value> bounds; @@ -962,20 +978,6 @@ void ClauseProcessor::processMapObjects( } } - if (!mapperIdName.empty()) { - if (mapperIdName == "default") { - auto &typeSpec = object.sym()->owner().IsDerivedType() - ? *object.sym()->owner().derivedTypeSpec() - : object.sym()->GetType()->derivedTypeSpec(); - mapperIdName = typeSpec.name().ToString() + ".default"; - mapperIdName = converter.mangleName(mapperIdName, *typeSpec.GetScope()); - } - assert(converter.getModuleOp().lookupSymbol(mapperIdName) && - "mapper not found"); - mapperId = mlir::FlatSymbolRefAttr::get(&converter.getMLIRContext(), - mapperIdName); - mapperIdName.clear(); - } // Explicit map captures are captured ByRef by default, // optimisation passes may alter this to ByCopy or other capture // types to optimise |
