================
@@ -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 Plugin::success();
+    }
+
+    // Allocate and construct the AMDGPU kernel.
+    GenericKernelTy *AMDGPUKernel = Plugin.allocate<AMDGPUKernelTy>();
+    if (!AMDGPUKernel)
+      return Plugin::error("Failed to allocate memory for AMDGPU kernel");
+
+    new (AMDGPUKernel) AMDGPUKernelTy(Name);
+    if (auto Err = AMDGPUKernel->initImpl(*this, Image))
+      return std::move(Err);
+
+    auto *AsyncInfoPtr = Plugin.allocate<__tgt_async_info>();
----------------
jdoerfert wrote:

Here and above you don't need plugin allocate. That's only for things that 
outlive the function, neither the Kernel nor the AsyncInfo will. They should be 
stack objects. That said, you should not need an aysync_info ptr anyway. 
AsyncInfoWrapperTy should work standalone and it has all the functions we need.

https://github.com/llvm/llvm-project/pull/71739
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to