================
@@ -496,6 +733,57 @@ class MapInfoFinalizationPass
     return false;
   }
 
+  // This function generates an attach map, which is an type of OpenMP map that
+  // binds a pointer to its data, in the case of Fortran, this binding is
+  // primarily for binding the pointer inside of descriptors to the underlying
+  // data pointed to by the descriptor. This is simply an extra map that we 
must
+  // emit when generating any map of a descriptor type be it ref_ptr, ref_ptee
+  // or ref_ptr + ref_ptee (ref_ptr_ptee in OpenMP parlance), to bind the
+  // pointer inside of the descriptor to its respective data. The only case 
this
+  // can be omitted is when a user has explicitly asked for different attach
+  // semantics e.g. specifying attach(none) as a map modifier, this is the case
+  // where the [[maybe_unused]] attribute is relevant.
+  [[maybe_unused]] mlir::Operation *genImplicitAttachMap(
+      mlir::omp::MapInfoOp descMapOp, mlir::Value descriptor,
+      llvm::SmallVectorImpl<ParentAndPlacement> &mapMemberUsers,
+      mlir::Operation *target, fir::FirOpBuilder &builder,
+      mlir::omp::ClauseMapFlags refFlagType, bool isAttachAlways = false,
+      mlir::Value reuseBaseAddr = mlir::Value{}) {
+    auto baseAddr =
+        reuseBaseAddr
+            ? reuseBaseAddr
+            : fir::BoxOffsetOp::create(builder, descMapOp->getLoc(), 
descriptor,
+                                       fir::BoxFieldAttr::base_addr);
+    mlir::Type underlyingVarType = llvm::cast<mlir::omp::PointerLikeType>(
+                                       fir::unwrapRefType(baseAddr.getType()))
+                                       .getElementType();
+    if (auto seqType = llvm::dyn_cast<fir::SequenceType>(underlyingVarType))
+      if (seqType.hasDynamicExtents())
+        underlyingVarType = seqType.getEleTy();
+
+    auto implicitAttachMap = mlir::omp::MapInfoOp::create(
+        builder, descMapOp->getLoc(), descMapOp.getResult().getType(),
+        descriptor,
+        mlir::TypeAttr::get(fir::unwrapRefType(descriptor.getType())),
+        builder.getAttr<mlir::omp::ClauseMapFlagsAttr>(
+            mlir::omp::ClauseMapFlags::attach | refFlagType |
+            (isAttachAlways ? mlir::omp::ClauseMapFlags::always
+                            : mlir::omp::ClauseMapFlags::none)),
+        descMapOp.getMapCaptureTypeAttr(), /*varPtrPtr=*/
+        baseAddr, mlir::TypeAttr::get(underlyingVarType),
+        /*members=*/mlir::SmallVector<mlir::Value>{},
+        /*membersIndex=*/mlir::ArrayAttr{},
+        /*bounds=*/descMapOp.getBounds(),
----------------
agozillon wrote:

It's required, while the aim is to simply bind them together, the runtime needs 
the right information to do so. Which at this current time is the size of the 
pointer or descriptor, the descriptor address and most importantly for the 
above case, the data's address. What we need to remember at this stage is that 
we're still cannibalizing our singular initial descriptor map into 3 different 
maps, so the bounds in this case is actually the data/base addresses bounds 
rather than the descriptors (which at time of writing it never should have its 
own), and this is actually important for calculating the data/base addresses 
end address for cases where we perform array sectioning or any kind of offsets! 
So, unfortunately it's needed at the moment, we can hopefully refine it a 
little over time.  

https://github.com/llvm/llvm-project/pull/177715
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to