[Openmp-commits] [openmp] e1f911e - [OpenMP][NFC] Simplify code

Johannes Doerfert via Openmp-commits openmp-commits at lists.llvm.org
Mon Nov 27 16:03:22 PST 2023


Author: Johannes Doerfert
Date: 2023-11-27T16:02:34-08:00
New Revision: e1f911e40ce6ad4a7f393ea1b33e65b24940eb84

URL: https://github.com/llvm/llvm-project/commit/e1f911e40ce6ad4a7f393ea1b33e65b24940eb84
DIFF: https://github.com/llvm/llvm-project/commit/e1f911e40ce6ad4a7f393ea1b33e65b24940eb84.diff

LOG: [OpenMP][NFC] Simplify code

Added: 
    

Modified: 
    openmp/libomptarget/src/rtl.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/src/rtl.cpp b/openmp/libomptarget/src/rtl.cpp
index 3e2c0a64c9151fc..78076dd2c6db13d 100644
--- a/openmp/libomptarget/src/rtl.cpp
+++ b/openmp/libomptarget/src/rtl.cpp
@@ -403,33 +403,30 @@ void RTLsTy::registerRequires(int64_t Flags) {
 
 void RTLsTy::initRTLonce(RTLInfoTy &R) {
   // If this RTL is not already in use, initialize it.
-  if (!R.IsUsed && R.NumberOfDevices != 0) {
-    // Initialize the device information for the RTL we are about to use.
-    const size_t Start = PM->Devices.size();
-    PM->Devices.reserve(Start + R.NumberOfDevices);
-    for (int32_t DeviceId = 0; DeviceId < R.NumberOfDevices; DeviceId++) {
-      PM->Devices.push_back(std::make_unique<DeviceTy>(&R));
-      // global device ID
-      PM->Devices[Start + DeviceId]->DeviceID = Start + DeviceId;
-      // RTL local device ID
-      PM->Devices[Start + DeviceId]->RTLDeviceID = DeviceId;
-    }
+  if (R.IsUsed || !R.NumberOfDevices)
+    return;
 
-    // Initialize the index of this RTL and save it in the used RTLs.
-    R.Idx = (UsedRTLs.empty())
-                ? 0
-                : UsedRTLs.back()->Idx + UsedRTLs.back()->NumberOfDevices;
-    assert((size_t)R.Idx == Start &&
-           "RTL index should equal the number of devices used so far.");
-    R.IsUsed = true;
-    UsedRTLs.push_back(&R);
+  // Initialize the device information for the RTL we are about to use.
+  const size_t Start = PM->Devices.size();
+  PM->Devices.reserve(Start + R.NumberOfDevices);
+  for (int32_t DeviceId = 0; DeviceId < R.NumberOfDevices; DeviceId++) {
+    PM->Devices.push_back(std::make_unique<DeviceTy>(&R));
+    // global device ID
+    PM->Devices[Start + DeviceId]->DeviceID = Start + DeviceId;
+    // RTL local device ID
+    PM->Devices[Start + DeviceId]->RTLDeviceID = DeviceId;
+  }
 
-    // If possible, set the device identifier offset
-    if (R.set_device_offset)
-      R.set_device_offset(Start);
+  // Initialize the index of this RTL and save it in the used RTLs.
+  R.Idx = Start;
+  R.IsUsed = true;
+  UsedRTLs.push_back(&R);
 
-    DP("RTL " DPxMOD " has index %d!\n", DPxPTR(R.LibraryHandler.get()), R.Idx);
-  }
+  // If possible, set the device identifier offset
+  if (R.set_device_offset)
+    R.set_device_offset(Start);
+
+  DP("RTL " DPxMOD " has index %d!\n", DPxPTR(R.LibraryHandler.get()), R.Idx);
 }
 
 void RTLsTy::initAllRTLs() {


        


More information about the Openmp-commits mailing list