[Openmp-commits] [openmp] 5ad07ac - [Libomptarget] Use entry name for global info

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Mon Apr 25 06:56:54 PDT 2022


Author: Joseph Huber
Date: 2022-04-25T09:56:43-04:00
New Revision: 5ad07ac400dad1cbc7c7c0a5e6325165da993fb1

URL: https://github.com/llvm/llvm-project/commit/5ad07ac400dad1cbc7c7c0a5e6325165da993fb1
DIFF: https://github.com/llvm/llvm-project/commit/5ad07ac400dad1cbc7c7c0a5e6325165da993fb1.diff

LOG: [Libomptarget] Use entry name for global info

Currently, globals on the device will have an infinite reference count
and an unknown name when using `LIBOMPTARGET_INFO` to print the mapping
table. We already store the name of the global in the offloading entry
so we should be able to use it, although there will be no source
location. To do this we need to create a valid `ident_t` string from a
name only.

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D124381

Added: 
    

Modified: 
    openmp/libomptarget/include/SourceInfo.h
    openmp/libomptarget/src/omptarget.cpp
    openmp/libomptarget/test/offloading/info.c

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/include/SourceInfo.h b/openmp/libomptarget/include/SourceInfo.h
index 7d30a041468a1..d508f6d6bc993 100644
--- a/openmp/libomptarget/include/SourceInfo.h
+++ b/openmp/libomptarget/include/SourceInfo.h
@@ -50,15 +50,17 @@ class SourceInfo {
   std::string initStr(const void *Name) {
     if (!Name)
       return ";unknown;unknown;0;0;;";
-    else
-      return std::string(reinterpret_cast<const char *>(Name));
+
+    std::string Str = std::string(reinterpret_cast<const char *>(Name));
+    if (Str.find(';') == std::string::npos)
+      return ";" + Str + ";unknown;0;0;;";
+    return Str;
   }
 
   std::string initStr(const ident_t *Loc) {
     if (!Loc)
       return ";unknown;unknown;0;0;;";
-    else
-      return std::string(reinterpret_cast<const char *>(Loc->psource));
+    return std::string(reinterpret_cast<const char *>(Loc->psource));
   }
 
   /// Get n-th substring in an expression separated by ;.

diff  --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp
index 62e46cab98c45..f8439177a5e6b 100644
--- a/openmp/libomptarget/src/omptarget.cpp
+++ b/openmp/libomptarget/src/omptarget.cpp
@@ -168,7 +168,7 @@ static int InitLibrary(DeviceTy &Device) {
               (uintptr_t)CurrHostEntry->addr +
                   CurrHostEntry->size /*HstPtrEnd*/,
               (uintptr_t)CurrDeviceEntry->addr /*TgtPtrBegin*/,
-              false /*UseHoldRefCount*/, nullptr /*Name*/,
+              false /*UseHoldRefCount*/, CurrHostEntry->name,
               true /*IsRefCountINF*/));
         }
       }

diff  --git a/openmp/libomptarget/test/offloading/info.c b/openmp/libomptarget/test/offloading/info.c
index 4a494d14fb57c..006b184e1c2cc 100644
--- a/openmp/libomptarget/test/offloading/info.c
+++ b/openmp/libomptarget/test/offloading/info.c
@@ -54,7 +54,7 @@ int main() {
 // INFO: Libomptarget device 0 info: Removing map entry with HstPtrBegin={{.*}}, TgtPtrBegin={{.*}}, Size=256, Name=A[0:64]
 // INFO: Libomptarget device 0 info: OpenMP Host-Device pointer mappings after block at info.c:[[#%u,]]:[[#%u,]]:
 // INFO: Libomptarget device 0 info: Host Ptr  Target Ptr Size (B) DynRefCount HoldRefCount Declaration
-// INFO: Libomptarget device 0 info: [[#%#x,]] [[#%#x,]]  4        INF         0            unknown at unknown:0:0
+// INFO: Libomptarget device 0 info: [[#%#x,]] [[#%#x,]]  4        INF         0            global at unknown:0:0
 #pragma omp target data map(alloc:A[0:N]) map(ompx_hold,tofrom:B[0:N]) map(to:C[0:N])
 #pragma omp target firstprivate(val)
   { val = 1; }


        


More information about the Openmp-commits mailing list