[flang-commits] [flang] [MLIR][OpenMP] Add Lowering support for implicitly linking to default declare mappers (PR #131006)
Sergio Afonso via flang-commits
flang-commits at lists.llvm.org
Mon Mar 17 09:34:46 PDT 2025
================
@@ -978,6 +960,42 @@ void ClauseProcessor::processMapObjects(
}
}
+ // Create the mapper symbol from its name, if specified.
+ mlir::FlatSymbolRefAttr mapperId;
+ if (!mapperIdNameRef.empty()) {
+ std::string mapperIdName = mapperIdNameRef.str();
+ if (mapperIdNameRef == "implicit" || mapperIdNameRef == "default") {
+ if (!mlir::isa<mlir::omp::DeclareMapperOp>(
+ firOpBuilder.getRegion().getParentOp())) {
+ const semantics::DerivedTypeSpec *typeSpec = nullptr;
+
+ if (object.sym()->owner().IsDerivedType())
+ typeSpec = object.sym()->owner().derivedTypeSpec();
+ else if (object.sym()->GetType() &&
+ object.sym()->GetType()->category() ==
+ semantics::DeclTypeSpec::TypeDerived)
+ typeSpec = &object.sym()->GetType()->derivedTypeSpec();
+
+ if (typeSpec) {
+ mapperIdName = typeSpec->name().ToString() + ".default";
+ mapperIdName =
+ converter.mangleName(mapperIdName, *typeSpec->GetScope());
+ }
+ }
+ }
+ if (mapperIdNameRef == "implicit") {
+ mapperId = converter.getModuleOp().lookupSymbol(mapperIdName)
+ ? mlir::FlatSymbolRefAttr::get(
+ &converter.getMLIRContext(), mapperIdName)
+ : mlir::FlatSymbolRefAttr();
+ } else {
+ assert(converter.getModuleOp().lookupSymbol(mapperIdName) &&
+ "mapper not found");
+ mapperId = mlir::FlatSymbolRefAttr::get(&converter.getMLIRContext(),
+ mapperIdName);
+ }
+ }
----------------
skatrak wrote:
I understand there are three main cases to handle in this function, based on the value of `mapperIdNameRef`:
1. If it is empty, then `mapperId` will remain `null` for all objects in the list.
2. If it is set to "implicit" or "default", then `mapperId` will be, for each object, a symbol name derived from the type of the object. Except for "implicit", which will remain null if that symbol hasn't been defined.
3. If it is set to any other string, which just results in a symbol being created with that exact string.
If I understood that correctly, in my opinion it still makes sense to address cases 1 and 3 outside of the loop by setting some `sharedMapperId` symbol. Inside of the loop, we can handle case 2:
```c++
mlir::FlatSymbolRefAttr mapperId = sharedMapperId;
if (!mapperId && !mapperIdNameRef.empty()) {
// Update mapperId depending on whether it is "implicit" or "default"...
}
// Use mapperId when creating the omp.map.info...
```
It's not a big deal, but it should help reduce compilation overhead a bit.
https://github.com/llvm/llvm-project/pull/131006
More information about the flang-commits
mailing list