[llvm] [openmp] [clang] [OpenMP] Rework handling of global ctor/dtors in OpenMP (PR #71739)

Joseph Huber via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 9 03:30:11 PST 2023


================
@@ -2627,6 +2637,48 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
   using AMDGPUEventRef = AMDGPUResourceRef<AMDGPUEventTy>;
   using AMDGPUEventManagerTy = GenericDeviceResourceManagerTy<AMDGPUEventRef>;
 
+  /// Common method to invoke a single threaded constructor or destructor
+  /// kernel by name.
+  Error callGlobalCtorDtorCommon(GenericPluginTy &Plugin, DeviceImageTy &Image,
+                                 const char *Name) {
+    // Perform a quick check for the named kernel in the image. The kernel
+    // should be created by the 'amdgpu-lower-ctor-dtor' pass.
+    GenericGlobalHandlerTy &Handler = Plugin.getGlobalHandler();
+    GlobalTy Global(Name, sizeof(void *));
+    if (auto Err = Handler.getGlobalMetadataFromImage(*this, Image, Global)) {
+      consumeError(std::move(Err));
+      return Error::success();
----------------
jhuber6 wrote:

If there were any global ctors / dtors the backend will emit a kernel. This is simply encoding "Does this symbol exist? If not continue on". We check the ELF symbol table directly as it's more efficient than going through the device API.

We probably need to encode the logic better, since `consumeError` is a bit of a code smell. Maybe a helper function like `Handler.hasGlobal` or something.

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


More information about the cfe-commits mailing list