[flang-commits] [flang] [llvm] [flang-rt] Add APIs to retrive base_addr and DataSizeInBytes from Descriptor. (PR #152756)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Tue Aug 19 09:27:05 PDT 2025


================
@@ -48,6 +48,30 @@ void RTDEF(CopyAndUpdateDescriptor)(Descriptor &to, const Descriptor &from,
   }
 }
 
+void *RTDEF(DescriptorGetBaseAddress)(
+    const Descriptor &desc, const char *sourceFile, int sourceLine) {
+  Terminator terminator{sourceFile, sourceLine};
+  void *baseAddr = desc.raw().base_addr;
+  if (!baseAddr) {
+    terminator.Crash("Could not retrieve Descriptor's base address");
+  }
+  return baseAddr;
+}
+
+std::size_t RTDEF(DescriptorGetDataSizeInBytes)(
----------------
vzakhari wrote:

There is `fir.box_total_elements` (probably not implemented end-to-end right now) and `fir.box_elesize`, which can be used to compute the data size in bytes (of course, assuming that the data is contiguous).

So there are existing operations that should allow you to get all the data for `omp_target_memcpy` invocation and insert it in the compiler generated code rather than doing it in the Fortran runtime.

https://github.com/llvm/llvm-project/pull/152756


More information about the flang-commits mailing list