diff --git a/openmp/libomptarget/include/rtl.h b/openmp/libomptarget/include/rtl.h --- a/openmp/libomptarget/include/rtl.h +++ b/openmp/libomptarget/include/rtl.h @@ -14,6 +14,7 @@ #define _OMPTARGET_RTL_H #include "omptarget.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallVector.h" #include @@ -125,6 +126,8 @@ // Are there images associated with this RTL. bool IsUsed = false; + llvm::DenseSet UsedImages; + // Mutex for thread-safety when calling RTL interface functions. // It is easier to enforce thread-safety at the libomptarget level, // so that developers of new RTLs do not have to worry about it. diff --git a/openmp/libomptarget/src/rtl.cpp b/openmp/libomptarget/src/rtl.cpp --- a/openmp/libomptarget/src/rtl.cpp +++ b/openmp/libomptarget/src/rtl.cpp @@ -468,6 +468,8 @@ DP("Registering image " DPxMOD " with RTL %s!\n", DPxPTR(Img->ImageStart), R.RTLName.c_str()); registerImageIntoTranslationTable(TransTable, R, Img); + R.UsedImages.insert(Img); + PM->TrlTblMtx.unlock(); FoundRTL = &R; @@ -505,20 +507,9 @@ assert(R->IsUsed && "Expecting used RTLs."); - if (R->is_valid_binary_info) { - if (!R->is_valid_binary_info(Img, Info)) { - DP("Image " DPxMOD " is NOT compatible with RTL %s!\n", - DPxPTR(Img->ImageStart), R->RTLName.c_str()); - continue; - } - } else if (!R->is_valid_binary(Img)) { - DP("Image " DPxMOD " is NOT compatible with RTL %s!\n", - DPxPTR(Img->ImageStart), R->RTLName.c_str()); + // Ensure that we do not use any unused images associated with this RTL. + if (!R->UsedImages.contains(Img)) continue; - } - - DP("Image " DPxMOD " is compatible with RTL " DPxMOD "!\n", - DPxPTR(Img->ImageStart), DPxPTR(R->LibraryHandler)); FoundRTL = R;