[OpenMP] Make sure the Thread ID function is not removed
authorJoseph Huber <jhuber6@vols.utk.edu>
Wed, 22 Sep 2021 13:20:49 +0000 (09:20 -0400)
committerJoseph Huber <jhuber6@vols.utk.edu>
Wed, 22 Sep 2021 14:13:18 +0000 (10:13 -0400)
Summary:
The thread ID function was reintroduced in D110195, but could
potentially be removed by the optimizer. Make the function noinline to
preserve the call sites and add it to the externalization RAII so its
definition is not removed by the attributor.

llvm/lib/Transforms/IPO/OpenMPOpt.cpp
openmp/libomptarget/DeviceRTL/include/Utils.h
openmp/libomptarget/DeviceRTL/src/Mapping.cpp

index f05eb2568cebc049bc113c3efeaa0863c565559e..182650a0fec00115d78985630c68f9fc6b9d0a8f 100644 (file)
@@ -1865,6 +1865,8 @@ private:
                                     OMPRTL___kmpc_kernel_end_parallel);
     ExternalizationRAII BarrierSPMD(OMPInfoCache,
                                     OMPRTL___kmpc_barrier_simple_spmd);
+    ExternalizationRAII ThreadId(OMPInfoCache,
+                                 OMPRTL___kmpc_get_hardware_thread_id_in_block);
 
     registerAAs(IsModulePass);
 
index dc4b1cd71a5936c32d99e8dc34f11828e7a79fea..9ac37a66d4fc92527fef30dc4100c7300f392021 100644 (file)
@@ -17,6 +17,8 @@
 namespace _OMP {
 namespace utils {
 
+void keepAlive();
+
 /// Return the value \p Var from thread Id \p SrcLane in the warp if the thread
 /// is identified by \p Mask.
 int32_t shuffle(uint64_t Mask, int32_t Var, int32_t SrcLane);
index ee2aeeea47002d544adf2c3159a1e9a267d6084b..8b8a39e8023e3f0d3c04b553a32c50f422a66639 100644 (file)
@@ -227,7 +227,8 @@ bool mapping::isGenericMode() { return !isSPMDMode(); }
 ///}
 
 extern "C" {
-uint32_t __kmpc_get_hardware_thread_id_in_block() {
+__attribute__((noinline)) uint32_t __kmpc_get_hardware_thread_id_in_block() {
+  _OMP::utils::keepAlive();
   return mapping::getThreadIdInBlock();
 }
 }