[llvm] 1cf86df - [OpenMP] Make sure the Thread ID function is not removed

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 22 07:13:35 PDT 2021


Author: Joseph Huber
Date: 2021-09-22T10:13:18-04:00
New Revision: 1cf86df8839ae2c8ebb7c68e1c355ec960a153cf

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

LOG: [OpenMP] Make sure the Thread ID function is not removed

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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index f05eb2568cebc..182650a0fec00 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -1865,6 +1865,8 @@ struct OpenMPOpt {
                                     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);
 

diff  --git a/openmp/libomptarget/DeviceRTL/include/Utils.h b/openmp/libomptarget/DeviceRTL/include/Utils.h
index dc4b1cd71a593..9ac37a66d4fc9 100644
--- a/openmp/libomptarget/DeviceRTL/include/Utils.h
+++ b/openmp/libomptarget/DeviceRTL/include/Utils.h
@@ -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);

diff  --git a/openmp/libomptarget/DeviceRTL/src/Mapping.cpp b/openmp/libomptarget/DeviceRTL/src/Mapping.cpp
index ee2aeeea47002..8b8a39e8023e3 100644
--- a/openmp/libomptarget/DeviceRTL/src/Mapping.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/Mapping.cpp
@@ -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();
 }
 }


        


More information about the llvm-commits mailing list