[llvm-branch-commits] [llvm] [offload][nfc] Pull OpenMP's InteropTbl out of PluginManager (PR #230483)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Oct 9 05:53:42 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-offload
Author: Ivan R. Ivanov (ivanradanov)
<details>
<summary>Changes</summary>
PluginManager is shared with OpenACC, so the OpenMP interop table moves to OmpPluginManager in libomptarget. The OpenMP PM is defined there, and interop cleanup is registered from initRuntime.
---
Full diff: https://github.com/llvm/llvm-project/pull/230483.diff
4 Files Affected:
- (modified) offload/include/OpenMP/OffloadRTL.h (+10-1)
- (modified) offload/include/PluginManager.h (-5)
- (modified) offload/libompaccsupport/PluginManager.cpp (-8)
- (modified) offload/libomptarget/OffloadRTL.cpp (+12-4)
``````````diff
diff --git a/offload/include/OpenMP/OffloadRTL.h b/offload/include/OpenMP/OffloadRTL.h
index 1b4d93f9c57e4..d666f7efdeb4c 100644
--- a/offload/include/OpenMP/OffloadRTL.h
+++ b/offload/include/OpenMP/OffloadRTL.h
@@ -13,11 +13,20 @@
#ifndef OMPTARGET_OPENMP_OFFLOADRTL_H
#define OMPTARGET_OPENMP_OFFLOADRTL_H
+#include "OpenMP/InteropAPI.h"
#include "PluginManager.h"
#include <atomic>
-extern PluginManager *PM;
+namespace llvm::omp::target {
+class OmpPluginManager : public PluginManager {
+public:
+ /// Table of cached implicit interop objects
+ InteropTblTy InteropTbl;
+};
+} // namespace llvm::omp::target
+
+extern llvm::omp::target::OmpPluginManager *PM;
extern std::atomic<bool> RTLAlive; // Indicates if the RTL has been initialized
extern std::atomic<int> RTLOngoingSyncs; // Counts ongoing external syncs
diff --git a/offload/include/PluginManager.h b/offload/include/PluginManager.h
index 9cd5eb446c5c5..421d5a1f50a1f 100644
--- a/offload/include/PluginManager.h
+++ b/offload/include/PluginManager.h
@@ -37,8 +37,6 @@
#include <mutex>
#include <string>
-#include "OpenMP/InteropAPI.h"
-
using GenericPluginTy = llvm::omp::target::plugin::GenericPluginTy;
/// Struct for the data required to handle plugins
@@ -92,9 +90,6 @@ struct PluginManager {
HostPtrToTableMapTy HostPtrToTableMap;
std::mutex TblMapMtx; ///< For HostPtrToTableMap
- /// Table of cached implicit interop objects
- InteropTblTy InteropTbl;
-
// Work around for plugins that call dlopen on shared libraries that call
// tgt_register_lib during their initialisation. Stash the pointers in a
// vector until the plugins are all initialised and then register them.
diff --git a/offload/libompaccsupport/PluginManager.cpp b/offload/libompaccsupport/PluginManager.cpp
index c1a803ad582b6..4e0f105b18cf9 100644
--- a/offload/libompaccsupport/PluginManager.cpp
+++ b/offload/libompaccsupport/PluginManager.cpp
@@ -12,7 +12,6 @@
#include "PluginManager.h"
#include "OffloadPolicy.h"
-#include "OpenMP/OffloadRTL.h"
#include "OmpAccError.h"
#include "OpenMP/OMPT/Interface.h"
#include "Shared/Debug.h"
@@ -133,13 +132,6 @@ void PluginManager::initializeAllDevices() {
[this](ol_device_handle_t Device) { initializeDevice(Device); })) {
REPORT() << "Failed to iterate devices: " << toString(std::move(Err));
}
- // After all plugins are initialized, register atExit cleanup handlers
- std::atexit([]() {
- // Interop cleanup should be done before the plugins are deinitialized as
- // the backend libraries may be already unloaded.
- if (PM)
- PM->InteropTbl.clear();
- });
}
// Returns a pointer to the binary descriptor, upgrading from a legacy format if
diff --git a/offload/libomptarget/OffloadRTL.cpp b/offload/libomptarget/OffloadRTL.cpp
index 6812d7554a82e..84806527fb8d6 100644
--- a/offload/libomptarget/OffloadRTL.cpp
+++ b/offload/libomptarget/OffloadRTL.cpp
@@ -18,6 +18,7 @@
#include "Shared/Profile.h"
using namespace llvm::omp::target::debug;
+using llvm::omp::target::OmpPluginManager;
static std::mutex &getPluginMutex() {
static std::mutex Mutex;
@@ -26,7 +27,7 @@ static std::mutex &getPluginMutex() {
static uint32_t RefCount = 0;
std::atomic<bool> RTLAlive{false};
std::atomic<int> RTLOngoingSyncs{0};
-PluginManager *PM = nullptr;
+OmpPluginManager *PM = nullptr;
/// Check deleted and deprecated features, such as environment variables.
static void checkRuntimeEnvironment() {
@@ -44,11 +45,11 @@ void initRuntime() {
checkRuntimeEnvironment();
- if (PM == nullptr)
- PM = new PluginManager();
-
RefCount++;
if (RefCount == 1) {
+ assert(PM == nullptr);
+ PM = new llvm::omp::target::OmpPluginManager();
+
ODBG(ODT_Init) << "Init offload library!";
#ifdef OMPT_SUPPORT
// Initialize OMPT first
@@ -57,6 +58,13 @@ void initRuntime() {
PM->init();
PM->registerDelayedLibraries();
+ // After all plugins are initialized, register atExit cleanup handlers
+ std::atexit([]() {
+ // Interop cleanup should be done before the plugins are deinitialized as
+ // the backend libraries may be already unloaded.
+ if (PM)
+ PM->InteropTbl.clear();
+ });
// RTL initialization is complete
RTLAlive = true;
``````````
</details>
https://github.com/llvm/llvm-project/pull/230483
More information about the llvm-branch-commits
mailing list