Skip to content

Commit 2542876

Browse files
authored
[Libomptarget] Remove handling of old ctor / dtor entries (#80153)
Summary: A previous patch removed creating these entries in clang in favor of the backend emitting a callable kernel and having the runtime call that if present. The support for the old style was kept around in LLVM 18.0 but now that we have forked to 19.0 we should remove the support. The effect of this would be that an application linking against a newer libomptarget that still had the old constructors will no longer be called. In that case, they can either recompile or use the `libomptarget.so.18` that comes with the previous release.
1 parent 35a0089 commit 2542876

File tree

8 files changed

+8
-152
lines changed

8 files changed

+8
-152
lines changed

openmp/libomptarget/include/OffloadEntry.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class OffloadEntryTy {
3636
const char *getNameAsCStr() const { return OffloadEntry.name; }
3737
__tgt_bin_desc *getBinaryDescription() const;
3838

39-
bool isCTor() const { return hasFlags(OMP_DECLARE_TARGET_CTOR); }
40-
bool isDTor() const { return hasFlags(OMP_DECLARE_TARGET_DTOR); }
4139
bool isLink() const { return hasFlags(OMP_DECLARE_TARGET_LINK); }
4240

4341
bool hasFlags(OpenMPOffloadingDeclareTargetFlags Flags) const {

openmp/libomptarget/include/PluginManager.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ struct PluginAdaptorTy {
5858
/// user.
5959
int32_t getNumberOfUserDevices() const { return NumberOfUserDevices; }
6060

61-
/// Add all offload entries described by \p DI to the devices managed by this
62-
/// plugin.
63-
void addOffloadEntries(DeviceImageTy &DI);
64-
6561
/// RTL index, index is the number of devices of other RTLs that were
6662
/// registered before, i.e. the OpenMP index of the first device to be
6763
/// registered with this RTL.

openmp/libomptarget/include/device.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,13 @@ struct PluginAdaptorTy;
3838
struct __tgt_bin_desc;
3939
struct __tgt_target_table;
4040

41-
///
42-
struct PendingCtorDtorListsTy {
43-
std::list<void *> PendingCtors;
44-
std::list<void *> PendingDtors;
45-
};
46-
typedef std::map<__tgt_bin_desc *, PendingCtorDtorListsTy>
47-
PendingCtorsDtorsPerLibrary;
48-
4941
struct DeviceTy {
5042
int32_t DeviceID;
5143
PluginAdaptorTy *RTL;
5244
int32_t RTLDeviceID;
5345

5446
bool HasMappedGlobalData = false;
5547

56-
PendingCtorsDtorsPerLibrary PendingCtorsDtors;
57-
58-
std::mutex PendingGlobalsMtx;
59-
6048
DeviceTy(PluginAdaptorTy *RTL, int32_t DeviceID, int32_t RTLDeviceID);
6149
// DeviceTy is not copyable
6250
DeviceTy(const DeviceTy &D) = delete;
@@ -158,9 +146,6 @@ struct DeviceTy {
158146
int32_t destroyEvent(void *Event);
159147
/// }
160148

161-
/// Register \p Entry as an offload entry that is avalable on this device.
162-
void addOffloadEntry(const OffloadEntryTy &Entry);
163-
164149
/// Print all offload entries to stderr.
165150
void dumpOffloadEntries();
166151

openmp/libomptarget/include/omptarget.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ enum tgt_map_type {
9191
enum OpenMPOffloadingDeclareTargetFlags {
9292
/// Mark the entry global as having a 'link' attribute.
9393
OMP_DECLARE_TARGET_LINK = 0x01,
94-
/// Mark the entry kernel as being a global constructor.
95-
OMP_DECLARE_TARGET_CTOR = 0x02,
96-
/// Mark the entry kernel as being a global destructor.
97-
OMP_DECLARE_TARGET_DTOR = 0x04,
9894
/// Mark the entry global as being an indirectly callable function.
9995
OMP_DECLARE_TARGET_INDIRECT = 0x08
10096
};

openmp/libomptarget/src/PluginManager.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,6 @@ Error PluginAdaptorTy::init() {
8989
return Error::success();
9090
}
9191

92-
void PluginAdaptorTy::addOffloadEntries(DeviceImageTy &DI) {
93-
for (int32_t I = 0, E = getNumberOfUserDevices(); I < E; ++I) {
94-
auto DeviceOrErr = PM->getDevice(DeviceOffset + I);
95-
if (!DeviceOrErr)
96-
FATAL_MESSAGE(DeviceOffset + I, "%s",
97-
toString(DeviceOrErr.takeError()).c_str());
98-
99-
DeviceTy &Device = *DeviceOrErr;
100-
for (__tgt_offload_entry &Entry : DI.entries())
101-
Device.addOffloadEntry(OffloadEntryTy(DI, Entry));
102-
}
103-
}
104-
10592
void PluginManager::init() {
10693
TIMESCOPE();
10794
DP("Loading RTLs...\n");
@@ -259,9 +246,6 @@ void PluginManager::registerLib(__tgt_bin_desc *Desc) {
259246
PM->TrlTblMtx.unlock();
260247
FoundRTL = &R;
261248

262-
// Register all offload entries with the devices handled by the plugin.
263-
R.addOffloadEntries(DI);
264-
265249
// if an RTL was found we are done - proceed to register the next image
266250
break;
267251
}
@@ -302,34 +286,6 @@ void PluginManager::unregisterLib(__tgt_bin_desc *Desc) {
302286

303287
FoundRTL = &R;
304288

305-
// Execute dtors for static objects if the device has been used, i.e.
306-
// if its PendingCtors list has been emptied.
307-
for (int32_t I = 0; I < FoundRTL->getNumberOfUserDevices(); ++I) {
308-
auto DeviceOrErr = PM->getDevice(FoundRTL->DeviceOffset + I);
309-
if (!DeviceOrErr)
310-
FATAL_MESSAGE(FoundRTL->DeviceOffset + I, "%s",
311-
toString(DeviceOrErr.takeError()).c_str());
312-
313-
DeviceTy &Device = *DeviceOrErr;
314-
Device.PendingGlobalsMtx.lock();
315-
if (Device.PendingCtorsDtors[Desc].PendingCtors.empty()) {
316-
AsyncInfoTy AsyncInfo(Device);
317-
for (auto &Dtor : Device.PendingCtorsDtors[Desc].PendingDtors) {
318-
int Rc =
319-
target(nullptr, Device, Dtor, CTorDTorKernelArgs, AsyncInfo);
320-
if (Rc != OFFLOAD_SUCCESS) {
321-
DP("Running destructor " DPxMOD " failed.\n", DPxPTR(Dtor));
322-
}
323-
}
324-
// Remove this library's entry from PendingCtorsDtors
325-
Device.PendingCtorsDtors.erase(Desc);
326-
// All constructors have been issued, wait for them now.
327-
if (AsyncInfo.synchronize() != OFFLOAD_SUCCESS)
328-
DP("Failed synchronizing destructors kernels.\n");
329-
}
330-
Device.PendingGlobalsMtx.unlock();
331-
}
332-
333289
DP("Unregistered image " DPxMOD " from RTL " DPxMOD "!\n",
334290
DPxPTR(Img->ImageStart), DPxPTR(R.LibraryHandler.get()));
335291

openmp/libomptarget/src/device.cpp

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int HostDataToTargetTy::addEventIfNecessary(DeviceTy &Device,
6666

6767
DeviceTy::DeviceTy(PluginAdaptorTy *RTL, int32_t DeviceID, int32_t RTLDeviceID)
6868
: DeviceID(DeviceID), RTL(RTL), RTLDeviceID(RTLDeviceID),
69-
PendingCtorsDtors(), PendingGlobalsMtx(), MappingInfo(*this) {}
69+
MappingInfo(*this) {}
7070

7171
DeviceTy::~DeviceTy() {
7272
if (DeviceID == -1 || !(getInfoLevel() & OMP_INFOTYPE_DUMP_TABLE))
@@ -297,48 +297,11 @@ int32_t DeviceTy::destroyEvent(void *Event) {
297297
return OFFLOAD_SUCCESS;
298298
}
299299

300-
void DeviceTy::addOffloadEntry(const OffloadEntryTy &Entry) {
301-
std::lock_guard<decltype(PendingGlobalsMtx)> Lock(PendingGlobalsMtx);
302-
DeviceOffloadEntries.getExclusiveAccessor()->insert({Entry.getName(), Entry});
303-
if (Entry.isGlobal())
304-
return;
305-
306-
if (Entry.isCTor()) {
307-
DP("Adding ctor " DPxMOD " to the pending list.\n",
308-
DPxPTR(Entry.getAddress()));
309-
MESSAGE("WARNING: Calling deprecated constructor for entry %s will be "
310-
"removed in a future release \n",
311-
Entry.getNameAsCStr());
312-
PendingCtorsDtors[Entry.getBinaryDescription()].PendingCtors.push_back(
313-
Entry.getAddress());
314-
} else if (Entry.isDTor()) {
315-
// Dtors are pushed in reverse order so they are executed from end
316-
// to beginning when unregistering the library!
317-
DP("Adding dtor " DPxMOD " to the pending list.\n",
318-
DPxPTR(Entry.getAddress()));
319-
MESSAGE("WARNING: Calling deprecated destructor for entry %s will be "
320-
"removed in a future release \n",
321-
Entry.getNameAsCStr());
322-
PendingCtorsDtors[Entry.getBinaryDescription()].PendingDtors.push_front(
323-
Entry.getAddress());
324-
}
325-
326-
if (Entry.isLink()) {
327-
MESSAGE(
328-
"WARNING: The \"link\" attribute is not yet supported for entry: %s!\n",
329-
Entry.getNameAsCStr());
330-
}
331-
}
332-
333300
void DeviceTy::dumpOffloadEntries() {
334301
fprintf(stderr, "Device %i offload entries:\n", DeviceID);
335302
for (auto &It : *DeviceOffloadEntries.getExclusiveAccessor()) {
336303
const char *Kind = "kernel";
337-
if (It.second.isCTor())
338-
Kind = "constructor";
339-
else if (It.second.isDTor())
340-
Kind = "destructor";
341-
else if (It.second.isLink())
304+
if (It.second.isLink())
342305
Kind = "link";
343306
else if (It.second.isGlobal())
344307
Kind = "global var.";

openmp/libomptarget/src/omptarget.cpp

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -291,36 +291,9 @@ static int initLibrary(DeviceTy &Device) {
291291
}
292292
}
293293

294-
if (Rc != OFFLOAD_SUCCESS) {
294+
if (Rc != OFFLOAD_SUCCESS)
295295
return Rc;
296-
}
297296

298-
/*
299-
* Run ctors for static objects
300-
*/
301-
if (!Device.PendingCtorsDtors.empty()) {
302-
AsyncInfoTy AsyncInfo(Device);
303-
// Call all ctors for all libraries registered so far
304-
for (auto &Lib : Device.PendingCtorsDtors) {
305-
if (!Lib.second.PendingCtors.empty()) {
306-
DP("Has pending ctors... call now\n");
307-
for (auto &Entry : Lib.second.PendingCtors) {
308-
void *Ctor = Entry;
309-
int Rc = target(nullptr, Device, Ctor, CTorDTorKernelArgs, AsyncInfo);
310-
if (Rc != OFFLOAD_SUCCESS) {
311-
REPORT("Running ctor " DPxMOD " failed.\n", DPxPTR(Ctor));
312-
return OFFLOAD_FAIL;
313-
}
314-
}
315-
// Clear the list to indicate that this device has been used
316-
Lib.second.PendingCtors.clear();
317-
DP("Done with pending ctors for lib " DPxMOD "\n", DPxPTR(Lib.first));
318-
}
319-
}
320-
// All constructors have been issued, wait for them now.
321-
if (AsyncInfo.synchronize() != OFFLOAD_SUCCESS)
322-
return OFFLOAD_FAIL;
323-
}
324297
Device.HasMappedGlobalData = true;
325298

326299
static Int32Envar DumpOffloadEntries =
@@ -435,14 +408,10 @@ bool checkDeviceAndCtors(int64_t &DeviceID, ident_t *Loc) {
435408
FATAL_MESSAGE(DeviceID, "%s", toString(DeviceOrErr.takeError()).data());
436409

437410
// Check whether global data has been mapped for this device
438-
{
439-
std::lock_guard<decltype(DeviceOrErr->PendingGlobalsMtx)> LG(
440-
DeviceOrErr->PendingGlobalsMtx);
441-
if (initLibrary(*DeviceOrErr) != OFFLOAD_SUCCESS) {
442-
REPORT("Failed to init globals on device %" PRId64 "\n", DeviceID);
443-
handleTargetOutcome(false, Loc);
444-
return true;
445-
}
411+
if (initLibrary(*DeviceOrErr) != OFFLOAD_SUCCESS) {
412+
REPORT("Failed to init globals on device %" PRId64 "\n", DeviceID);
413+
handleTargetOutcome(false, Loc);
414+
return true;
446415
}
447416

448417
return false;

openmp/libomptarget/test/offloading/ctor_dtor.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
// RUN: %libomptarget-compilexx-run-and-check-generic
22
// RUN: %libomptarget-compileoptxx-run-and-check-generic
3-
// RUN: %libomptarget-compilexx-generic && \
4-
// RUN: env OMPTARGET_DUMP_OFFLOAD_ENTRIES=0 %libomptarget-run-generic 2>&1 | \
5-
// RUN: %fcheck-generic --check-prefix=DUMP
6-
//
7-
// DUMP: Device 0 offload entries:
8-
// DUMP-DAG: global var.: s
9-
// DUMP-DAG: kernel: __omp_offloading_{{.*}}_main_
10-
//
3+
114
#include <cstdio>
125
struct S {
136
S() : i(7) {}

0 commit comments

Comments
 (0)