[flang-commits] [flang] [Flang][OpenMP] Update declare mapper lookup via use-module (PR #163860)
Akash Banerjee via flang-commits
flang-commits at lists.llvm.org
Mon Nov 3 23:56:00 PST 2025
================
@@ -4239,3 +4255,32 @@ void Fortran::lower::genOpenMPRequires(mlir::Operation *mod,
offloadMod.setRequires(mlirFlags);
}
}
+
+// Walk scopes and materialize omp.declare_mapper ops for mapper declarations
+// found in imported modules. If \p scope is null, start from the global scope.
+void Fortran::lower::materializeOpenMPDeclareMappers(
+ Fortran::lower::AbstractConverter &converter,
+ semantics::SemanticsContext &semaCtx, const semantics::Scope *scope) {
+ const semantics::Scope &root = scope ? *scope : semaCtx.globalScope();
+
+ // Recurse into child scopes first (modules, submodules, etc.).
+ for (const semantics::Scope &child : root.children())
+ materializeOpenMPDeclareMappers(converter, semaCtx, &child);
+
+ // Only consider module scopes to avoid duplicating local constructs.
+ if (!root.IsModule())
+ return;
+
+ // Scan symbols in this module scope for MapperDetails.
+ for (auto &it : root) {
+ const semantics::Symbol &sym = *it.second;
+ if (auto *md = sym.detailsIf<semantics::MapperDetails>()) {
+ for (const auto *decl : md->GetDeclList()) {
+ if (const auto *mapperDecl =
+ std::get_if<parser::OpenMPDeclareMapperConstruct>(&decl->u)) {
+ genOpenMPDeclareMapperImpl(converter, semaCtx, *mapperDecl, &sym);
+ }
+ }
+ }
+ }
+}
----------------
TIFitis wrote:
I've reverted to the previous approach.
>From what I understand, a function that comes in through a transitive USE is represented in the importing scope by a symbol whose details are `semantics::UseDetails`, pointing back to the defining symbol in the original module. When lowering sees a call, it follows that chain to the ultimate symbol in the source module, so the call is generated exactly as if the function were imported directly. No IR for the callee is emitted in the current compilation unit.
For declare mappers, we need to follow the chain and generate the IR. So we can either take the lazy approach, or we must go through the scopes to find any declare mappers that have brought in through USE modules and lower them.
The declare mappers don't seem to appear at the top-level.
https://github.com/llvm/llvm-project/pull/163860
More information about the flang-commits
mailing list