[Openmp-commits] [openmp] [Libomptarget] Remove remaining global constructors in plugins (PR #75814)

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Mon Dec 18 07:44:35 PST 2023


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/75814

Summary:
This patch fixes the remaining global constructor in the plguins after
addressing the ones in the JIT interface. This struct was mistakenly
using global constructors as not all the members were being initialized
properly. This was almost certainly being optimized out because it's
trivial, but would still be present in debug builds and prevented us
from compiling with `-Werror=global-constructors`. We will want to do
that once offloading is moved to a runtimes only build.


>From b6e04ce7f6f13581559d6c8b1ada071ca8f395ba Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 18 Dec 2023 09:42:30 -0600
Subject: [PATCH] [Libomptarget] Remove remaining global constructors in
 plugins

Summary:
This patch fixes the remaining global constructor in the plguins after
addressing the ones in the JIT interface. This struct was mistakenly
using global constructors as not all the members were being initialized
properly. This was almost certainly being optimized out because it's
trivial, but would still be present in debug builds and prevented us
from compiling with `-Werror=global-constructors`. We will want to do
that once offloading is moved to a runtimes only build.
---
 .../common/src/PluginInterface.cpp            | 23 ++++++++++---------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp b/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
index 3c7d1ca8998787..d51575a87949ca 100644
--- a/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp
@@ -49,15 +49,15 @@ struct RecordReplayTy {
 
 private:
   // Memory pointers for recording, replaying memory.
-  void *MemoryStart;
-  void *MemoryPtr;
-  size_t MemorySize;
-  size_t TotalSize;
-  GenericDeviceTy *Device;
-  std::mutex AllocationLock;
-
-  RRStatusTy Status;
-  bool ReplaySaveOutput;
+  void *MemoryStart = nullptr;
+  void *MemoryPtr = nullptr;
+  size_t MemorySize = 0;
+  size_t TotalSize = 0;
+  GenericDeviceTy *Device = nullptr;
+  std::mutex AllocationLock{};
+
+  RRStatusTy Status = RRDeactivated;
+  bool ReplaySaveOutput = false;
   bool UsedVAMap = false;
   uintptr_t MemoryOffset = 0;
 
@@ -190,7 +190,7 @@ struct RecordReplayTy {
   void setStatus(RRStatusTy Status) { this->Status = Status; }
   bool isSaveOutputEnabled() const { return ReplaySaveOutput; }
 
-  RecordReplayTy()
+  constexpr RecordReplayTy()
       : Status(RRStatusTy::RRDeactivated), ReplaySaveOutput(false) {}
 
   void saveImage(const char *Name, const DeviceImageTy &Image) {
@@ -352,8 +352,9 @@ struct RecordReplayTy {
       Device->free(MemoryStart);
     }
   }
+};
 
-} RecordReplay;
+static RecordReplayTy RecordReplay;
 
 // Extract the mapping of host function pointers to device function pointers
 // from the entry table. Functions marked as 'indirect' in OpenMP will have



More information about the Openmp-commits mailing list