[Openmp-commits] [PATCH] D101102: [OpenMP] Replace global InfoLevel with a reference to an internal one.

Joseph Huber via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Apr 22 12:56:52 PDT 2021


jhuber6 created this revision.
jhuber6 added reviewers: JonChesterfield, jdoerfert.
jhuber6 added a project: OpenMP.
Herald added subscribers: kerbowa, jfb, guansong, yaxunl, nhaehnle, jvesely.
jhuber6 requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.

This patch improves the implementation of D100774 <https://reviews.llvm.org/D100774> by replacing the global
variable introduced with a function that returns a reference to an internal
one. This removes the need to define the variable in every plugin that uses it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101102

Files:
  openmp/libomptarget/include/Debug.h
  openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
  openmp/libomptarget/plugins/cuda/src/rtl.cpp
  openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp
  openmp/libomptarget/plugins/remote/src/rtl.cpp
  openmp/libomptarget/src/interface.cpp


Index: openmp/libomptarget/src/interface.cpp
===================================================================
--- openmp/libomptarget/src/interface.cpp
+++ openmp/libomptarget/src/interface.cpp
@@ -459,12 +459,10 @@
 }
 
 EXTERN void __tgt_set_info_flag(uint32_t NewInfoLevel) {
+  std::atomic<uint32_t> &InfoLevel = getInfoLevelInternal();
   InfoLevel.store(NewInfoLevel);
   for (auto &R : PM->RTLs.AllRTLs) {
     if (R.set_info_flag)
       R.set_info_flag(NewInfoLevel);
   }
 }
-
-// Libomptarget's InfoLevel storage.
-std::atomic<uint32_t> InfoLevel;
Index: openmp/libomptarget/plugins/remote/src/rtl.cpp
===================================================================
--- openmp/libomptarget/plugins/remote/src/rtl.cpp
+++ openmp/libomptarget/plugins/remote/src/rtl.cpp
@@ -173,6 +173,3 @@
 #ifdef __cplusplus
 }
 #endif
-
-// Remote Offloading interal InfoLevel.
-std::atomic<uint32_t> InfoLevel;
Index: openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp
===================================================================
--- openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp
+++ openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp
@@ -335,6 +335,3 @@
 #ifdef __cplusplus
 }
 #endif
-
-// Elf-64 plugin's internal InfoLevel.
-std::atomic<uint32_t> InfoLevel;
Index: openmp/libomptarget/plugins/cuda/src/rtl.cpp
===================================================================
--- openmp/libomptarget/plugins/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins/cuda/src/rtl.cpp
@@ -1252,12 +1252,10 @@
 }
 
 void __tgt_rtl_set_info_flag(uint32_t NewInfoLevel) {
+  std::atomic<uint32_t> &InfoLevel = getInfoLevelInternal();
   InfoLevel.store(NewInfoLevel);
 }
 
 #ifdef __cplusplus
 }
 #endif
-
-// Cuda plugin's internal InfoLevel.
-std::atomic<uint32_t> InfoLevel;
Index: openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
===================================================================
--- openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
+++ openmp/libomptarget/plugins/amdgpu/src/rtl.cpp
@@ -1966,6 +1966,3 @@
   }
   return OFFLOAD_SUCCESS;
 }
-
-// AMDGPU plugin's internal InfoLevel.
-std::atomic<uint32_t> InfoLevel;
Index: openmp/libomptarget/include/Debug.h
===================================================================
--- openmp/libomptarget/include/Debug.h
+++ openmp/libomptarget/include/Debug.h
@@ -65,20 +65,20 @@
 #define USED
 #endif
 
-// Interface to the InfoLevel variable defined by each library.
-extern std::atomic<uint32_t> InfoLevel;
-
 // Add __attribute__((used)) to work around a bug in gcc 5/6.
-USED static inline uint32_t getInfoLevel() {
+USED inline std::atomic<uint32_t> &getInfoLevelInternal() {
+  static std::atomic<uint32_t> InfoLevel;
   static std::once_flag Flag{};
   std::call_once(Flag, []() {
     if (char *EnvStr = getenv("LIBOMPTARGET_INFO"))
       InfoLevel.store(std::stoi(EnvStr));
   });
 
-  return InfoLevel.load();
+  return InfoLevel;
 }
 
+USED inline uint32_t getInfoLevel() { return getInfoLevelInternal().load(); }
+
 // Add __attribute__((used)) to work around a bug in gcc 5/6.
 USED static inline uint32_t getDebugLevel() {
   static uint32_t DebugLevel = 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101102.339762.patch
Type: text/x-patch
Size: 3168 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210422/e8d49174/attachment.bin>


More information about the Openmp-commits mailing list