Skip to content

Commit 66028b5

Browse files
committed
[Libomptarget] Remove extra cache for offloading entries
Summary: The offloading entries right now are assumed to be baked into the binary itself, and thus always valid whenever the library is executing. This means that we don't need to copy them to additional storage and can instead simply pass around references to it. This is not likely to change in the expected operation of the OpenMP library. Additionally, the indirection for the offload entry struct is simply two pointers, so moving it by value is trivial.
1 parent 0cb9816 commit 66028b5

File tree

6 files changed

+18
-22
lines changed

6 files changed

+18
-22
lines changed

openmp/libomptarget/include/DeviceImage.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
class DeviceImageTy {
2727

2828
std::unique_ptr<llvm::object::OffloadBinary> Binary;
29-
llvm::SmallVector<std::unique_ptr<OffloadEntryTy>> OffloadEntries;
3029

3130
__tgt_bin_desc *BinaryDesc;
3231
__tgt_device_image Image;
@@ -37,7 +36,9 @@ class DeviceImageTy {
3736
__tgt_device_image &getExecutableImage() { return Image; }
3837
__tgt_bin_desc &getBinaryDesc() { return *BinaryDesc; }
3938

40-
auto entries() { return llvm::make_pointee_range(OffloadEntries); }
39+
auto entries() {
40+
return llvm::make_range(Image.EntriesBegin, Image.EntriesEnd);
41+
}
4142
};
4243

4344
#endif // OMPTARGET_DEVICE_IMAGE_H

openmp/libomptarget/include/OffloadEntry.h

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

39-
bool isCTor() { return hasFlags(OMP_DECLARE_TARGET_CTOR); }
40-
bool isDTor() { return hasFlags(OMP_DECLARE_TARGET_DTOR); }
41-
bool isLink() { return hasFlags(OMP_DECLARE_TARGET_LINK); }
39+
bool isCTor() const { return hasFlags(OMP_DECLARE_TARGET_CTOR); }
40+
bool isDTor() const { return hasFlags(OMP_DECLARE_TARGET_DTOR); }
41+
bool isLink() const { return hasFlags(OMP_DECLARE_TARGET_LINK); }
4242

43-
bool hasFlags(OpenMPOffloadingDeclareTargetFlags Flags) {
43+
bool hasFlags(OpenMPOffloadingDeclareTargetFlags Flags) const {
4444
return Flags & OffloadEntry.flags;
4545
}
4646
};

openmp/libomptarget/include/device.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ struct DeviceTy {
159159
/// }
160160

161161
/// Register \p Entry as an offload entry that is avalable on this device.
162-
void addOffloadEntry(OffloadEntryTy &Entry);
162+
void addOffloadEntry(const OffloadEntryTy &Entry);
163163

164164
/// Print all offload entries to stderr.
165165
void dumpOffloadEntries();
@@ -170,7 +170,7 @@ struct DeviceTy {
170170

171171
/// All offload entries available on this device.
172172
using DeviceOffloadEntriesMapTy =
173-
llvm::DenseMap<llvm::StringRef, OffloadEntryTy *>;
173+
llvm::DenseMap<llvm::StringRef, OffloadEntryTy>;
174174
ProtectedObj<DeviceOffloadEntriesMapTy> DeviceOffloadEntries;
175175

176176
/// Handler to collect and organize host-2-device mapping information.

openmp/libomptarget/src/DeviceImage.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ DeviceImageTy::DeviceImageTy(__tgt_bin_desc &BinaryDesc,
2727
__tgt_device_image &TgtDeviceImage)
2828
: BinaryDesc(&BinaryDesc), Image(TgtDeviceImage) {
2929

30-
for (__tgt_offload_entry &Entry :
31-
llvm::make_range(Image.EntriesBegin, Image.EntriesEnd))
32-
OffloadEntries.emplace_back(std::make_unique<OffloadEntryTy>(*this, Entry));
33-
3430
llvm::StringRef ImageStr(
3531
static_cast<char *>(Image.ImageStart),
3632
llvm::omp::target::getPtrDiff(Image.ImageEnd, Image.ImageStart));

openmp/libomptarget/src/PluginManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ void PluginAdaptorTy::addOffloadEntries(DeviceImageTy &DI) {
9797
toString(DeviceOrErr.takeError()).c_str());
9898

9999
DeviceTy &Device = *DeviceOrErr;
100-
for (OffloadEntryTy &Entry : DI.entries())
101-
Device.addOffloadEntry(Entry);
100+
for (__tgt_offload_entry &Entry : DI.entries())
101+
Device.addOffloadEntry(OffloadEntryTy(DI, Entry));
102102
}
103103
}
104104

openmp/libomptarget/src/device.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,9 @@ int32_t DeviceTy::destroyEvent(void *Event) {
291291
return OFFLOAD_SUCCESS;
292292
}
293293

294-
void DeviceTy::addOffloadEntry(OffloadEntryTy &Entry) {
294+
void DeviceTy::addOffloadEntry(const OffloadEntryTy &Entry) {
295295
std::lock_guard<decltype(PendingGlobalsMtx)> Lock(PendingGlobalsMtx);
296-
DeviceOffloadEntries.getExclusiveAccessor()->insert(
297-
{Entry.getName(), &Entry});
296+
DeviceOffloadEntries.getExclusiveAccessor()->insert({Entry.getName(), Entry});
298297
if (Entry.isGlobal())
299298
return;
300299

@@ -329,14 +328,14 @@ void DeviceTy::dumpOffloadEntries() {
329328
fprintf(stderr, "Device %i offload entries:\n", DeviceID);
330329
for (auto &It : *DeviceOffloadEntries.getExclusiveAccessor()) {
331330
const char *Kind = "kernel";
332-
if (It.second->isCTor())
331+
if (It.second.isCTor())
333332
Kind = "constructor";
334-
else if (It.second->isDTor())
333+
else if (It.second.isDTor())
335334
Kind = "destructor";
336-
else if (It.second->isLink())
335+
else if (It.second.isLink())
337336
Kind = "link";
338-
else if (It.second->isGlobal())
337+
else if (It.second.isGlobal())
339338
Kind = "global var.";
340-
fprintf(stderr, " %11s: %s\n", Kind, It.second->getNameAsCStr());
339+
fprintf(stderr, " %11s: %s\n", Kind, It.second.getNameAsCStr());
341340
}
342341
}

0 commit comments

Comments
 (0)