[llvm][Support] Use thread_local
caching for llvm::get_threadid() query on Apple systems (#87219)
I was profiling our compiler and noticed that `llvm::get_threadid` was at the top of the hotlist, taking up a surprising 5% (7 seconds) in the profile trace. It seems that computing this on MacOS systems is non-trivial, so cache the result in a thread_local. Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
This commit is contained in:
parent
b8cc3ba409
commit
f2f01f6b03
@ -115,8 +115,11 @@ uint64_t llvm::get_threadid() {
|
||||
// Calling "mach_thread_self()" bumps the reference count on the thread
|
||||
// port, so we need to deallocate it. mach_task_self() doesn't bump the ref
|
||||
// count.
|
||||
thread_port_t Self = mach_thread_self();
|
||||
mach_port_deallocate(mach_task_self(), Self);
|
||||
static thread_local thread_port_t Self = [] {
|
||||
thread_port_t InitSelf = mach_thread_self();
|
||||
mach_port_deallocate(mach_task_self(), Self);
|
||||
return InitSelf;
|
||||
}();
|
||||
return Self;
|
||||
#elif defined(__FreeBSD__)
|
||||
return uint64_t(pthread_getthreadid_np());
|
||||
|
Loading…
x
Reference in New Issue
Block a user