[flang-commits] [flang] [Flang][Lower][OpenMP] Add initial lowering of pointers/allocatables/target in map clauses to map_info and entries (PR #68600)
Razvan Lupusoru via flang-commits
flang-commits at lists.llvm.org
Mon Oct 9 11:57:15 PDT 2023
================
@@ -1752,11 +1754,82 @@ bool ClauseProcessor::processMap(
semanticsContext, stmtCtx, ompObject,
clauseLocation, asFortran, bounds);
+ auto checkIfStructComponent =
+ [](const Fortran::parser::OmpObject &ompObject) {
+ bool isComponent = false;
+ std::visit(
+ Fortran::common::visitors{
+ [&](const Fortran::parser::Designator &designator) {
+ if (auto *structComp = Fortran::parser::Unwrap<
+ Fortran::parser::StructureComponent>(
+ designator)) {
+ if (std::holds_alternative<Fortran::parser::Name>(
+ structComp->base.u))
+ isComponent = true;
+ }
+ },
+ [&](const Fortran::parser::Name &name) {}},
+ ompObject.u);
+
+ return isComponent;
+ };
+
+ // TODO: Currently, it appears there's missing symbol information
+ // and bounds information for allocatables and pointers inside
+ // of derived types. The latter needs some additional support
+ // added to the bounds generation whereas the former appears
+ // that it could be a problem when referring to pointer members
+ // via an OpenMP map clause, for the moment we do not handle
+ // these cases and must emit an error.
+ if (checkIfStructComponent(ompObject) &&
+ Fortran::semantics::IsAllocatableOrPointer(
+ *getOmpObjectSymbol(ompObject)))
+ TODO(currentLocation,
+ "pointer members of derived types are currently unmapped");
+
+ if (Fortran::semantics::IsAllocatableOrPointer(
+ *getOmpObjectSymbol(ompObject))) {
+ // We mimic what will eventually be a structure containing a
+ // pointer mapping for allocatables/pointers/target e.g.:
+ //
+ // !$omp target map(from:in, in%map_ptr)
+ //
+ // ===>
+ //
+ // map_entry varptr(in) ....
+ // map_entry varptr(map_ptr) varptrptr(in) ...
----------------
razvanlupusoru wrote:
I like seeing the use of varPtrPtr since this is one aspect of OpenACC lowering which is not yet complete. :) However, I think there is a mismatch here - at least from how I thought about it when I added this operand in acc dialect. Consider how clang maps a pointer as array from a struct:
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGOpenMPRuntime.cpp#L6989
Basically the varPtrPtr is literally meant to mean &varPtr. This means that this is the address of the "base_addr" field in the descriptor: aka (&(desc.base_addr)).
This is intentional - the whole descriptor does not need mapped if all we access is the data. Clang does it the same - the whole parent struct does not need mapped if only mapping a member.
Part of reason this wasn't solidified in lowering of OpenACC is because it is not yet clear how to really represent this abstraction. Descriptors don't have to be materialized into a struct type. And in that sense, in FIR, taking the address of a field in box type is not well defined.
https://github.com/llvm/llvm-project/pull/68600
More information about the flang-commits
mailing list