Skip to content

Commit 22d71e7

Browse files
committed
[Libomptarget] Do not check for valid binaries twice.
The only RTLs that get added to the `UsedRTLs` list have already been checked is they were valid binaries. We shouldn't need to do this again when we unregister all the used binaries as they wouldn't have been used if they were invalid anyway. Let me know if I'm incorrect in this assumption. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D131443
1 parent 2460786 commit 22d71e7

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

openmp/libomptarget/include/rtl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#ifndef _OMPTARGET_RTL_H
1414
#define _OMPTARGET_RTL_H
1515

16+
#include "omptarget.h"
17+
#include "llvm/ADT/DenseSet.h"
1618
#include "llvm/ADT/SmallVector.h"
1719
#include "llvm/Support/DynamicLibrary.h"
1820

@@ -127,6 +129,8 @@ struct RTLInfoTy {
127129
// Are there images associated with this RTL.
128130
bool IsUsed = false;
129131

132+
llvm::DenseSet<const __tgt_device_image *> UsedImages;
133+
130134
// Mutex for thread-safety when calling RTL interface functions.
131135
// It is easier to enforce thread-safety at the libomptarget level,
132136
// so that developers of new RTLs do not have to worry about it.

openmp/libomptarget/src/rtl.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ void RTLsTy::registerLib(__tgt_bin_desc *Desc) {
479479
DP("Registering image " DPxMOD " with RTL %s!\n", DPxPTR(Img->ImageStart),
480480
R.RTLName.c_str());
481481
registerImageIntoTranslationTable(TransTable, R, Img);
482+
R.UsedImages.insert(Img);
483+
482484
PM->TrlTblMtx.unlock();
483485
FoundRTL = &R;
484486

@@ -506,7 +508,6 @@ void RTLsTy::unregisterLib(__tgt_bin_desc *Desc) {
506508
for (auto &ImageAndInfo : PM->Images) {
507509
// Obtain the image and information that was previously extracted.
508510
__tgt_device_image *Img = &ImageAndInfo.first;
509-
__tgt_image_info *Info = &ImageAndInfo.second;
510511

511512
RTLInfoTy *FoundRTL = NULL;
512513

@@ -516,20 +517,9 @@ void RTLsTy::unregisterLib(__tgt_bin_desc *Desc) {
516517

517518
assert(R->IsUsed && "Expecting used RTLs.");
518519

519-
if (R->is_valid_binary_info) {
520-
if (!R->is_valid_binary_info(Img, Info)) {
521-
DP("Image " DPxMOD " is NOT compatible with RTL %s!\n",
522-
DPxPTR(Img->ImageStart), R->RTLName.c_str());
523-
continue;
524-
}
525-
} else if (!R->is_valid_binary(Img)) {
526-
DP("Image " DPxMOD " is NOT compatible with RTL %s!\n",
527-
DPxPTR(Img->ImageStart), R->RTLName.c_str());
520+
// Ensure that we do not use any unused images associated with this RTL.
521+
if (!R->UsedImages.contains(Img))
528522
continue;
529-
}
530-
531-
DP("Image " DPxMOD " is compatible with RTL " DPxMOD "!\n",
532-
DPxPTR(Img->ImageStart), DPxPTR(R->LibraryHandler.get()));
533523

534524
FoundRTL = R;
535525

0 commit comments

Comments
 (0)