[libc-commits] [libc] 4ac24b3 - [libc] inline thread self (#101739)

via libc-commits libc-commits at lists.llvm.org
Fri Aug 2 13:11:21 PDT 2024


Author: Schrodinger ZHU Yifan
Date: 2024-08-02T13:11:17-07:00
New Revision: 4ac24b388a5d812c57d50ed8ce336f1d516450cc

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

LOG: [libc] inline thread self (#101739)

The codegen for non-inlined version is "quite ugly" as it emits some
checks to make sure the initialization routine is properly executed
because the compiler does not see how the TLS object is initialized.
This leads to some `callq 0x0` junk in the final outputs.

For codegen details, see https://godbolt.org/z/rb5qYj3vY.

Added: 
    

Modified: 
    libc/src/__support/threads/thread.cpp
    libc/src/__support/threads/thread.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/threads/thread.cpp b/libc/src/__support/threads/thread.cpp
index 886281e0d50f7..dad4f75f092ed 100644
--- a/libc/src/__support/threads/thread.cpp
+++ b/libc/src/__support/threads/thread.cpp
@@ -17,9 +17,6 @@
 #include "src/__support/macros/attributes.h"
 
 namespace LIBC_NAMESPACE_DECL {
-
-LIBC_THREAD_LOCAL Thread self;
-
 namespace {
 
 using AtExitCallback = void(void *);

diff  --git a/libc/src/__support/threads/thread.h b/libc/src/__support/threads/thread.h
index 68640cef32964..f2b1f6bbb253d 100644
--- a/libc/src/__support/threads/thread.h
+++ b/libc/src/__support/threads/thread.h
@@ -231,7 +231,7 @@ struct Thread {
   int get_name(cpp::StringStream &name) const;
 };
 
-extern LIBC_THREAD_LOCAL Thread self;
+LIBC_INLINE_VAR LIBC_THREAD_LOCAL Thread self;
 
 // Platforms should implement this function.
 [[noreturn]] void thread_exit(ThreadReturnValue retval, ThreadStyle style);


        


More information about the libc-commits mailing list