[llvm] [OFFLOAD][L0] Add support to run ctor/dtor code (PR #187510)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 19 08:02:26 PDT 2026


================
@@ -1142,4 +1139,140 @@ Expected<bool> L0DeviceTy::isAccessiblePtrImpl(const void *Ptr, size_t Size) {
   return getMemAllocator(Ptr).contains(Ptr, Size);
 }
 
+Error L0DeviceTy::callGlobalConstructors(GenericPluginTy &Plugin,
+                                         DeviceImageTy &Image) {
+  return callGlobalCtorDtorCommon(Plugin, Image, /*IsCtor=*/true);
+}
+
+Error L0DeviceTy::callGlobalDestructors(GenericPluginTy &Plugin,
+                                        DeviceImageTy &Image) {
+  return callGlobalCtorDtorCommon(Plugin, Image, /*IsCtor=*/false);
+}
+
+Error L0DeviceTy::callGlobalCtorDtorCommon(GenericPluginTy &Plugin,
+                                           DeviceImageTy &Image, bool IsCtor) {
+  const char *KernelName = IsCtor ? "spirv$device$init" : "spirv$device$fini";
----------------
jhuber6 wrote:

Does SPIR-V not support `.` in kernel names like PTX? We only used `$` because PTX will die if you use periods in names.

AMD does the correct thing and all the lowering pass does is export a kernel that calls the linker-created list.

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


More information about the llvm-commits mailing list