[llvm] 98339ac - [Support] move llvm::llvm_is_multithread to header, NFC

Jun Zhang via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 7 17:50:22 PDT 2022


Author: Jun Zhang
Date: 2022-08-08T08:49:02+08:00
New Revision: 98339ac7af30b95f42f50e27bb6f6b7e2857ddc9

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

LOG: [Support] move llvm::llvm_is_multithread to header, NFC

This allow optimization without LTO. Also remove some useless else-ifs.
Signed-off-by: Jun Zhang <jun at junz.org>

Differential Revision: https://reviews.llvm.org/D131313

Added: 
    

Modified: 
    llvm/include/llvm/Support/Mutex.h
    llvm/include/llvm/Support/Threading.h
    llvm/lib/Support/Threading.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/Mutex.h b/llvm/include/llvm/Support/Mutex.h
index d73bb8ef1120c..d61e3fd96efbe 100644
--- a/llvm/include/llvm/Support/Mutex.h
+++ b/llvm/include/llvm/Support/Mutex.h
@@ -34,33 +34,31 @@ namespace llvm
         if (!mt_only || llvm_is_multithreaded()) {
           impl.lock();
           return true;
-        } else {
-          // Single-threaded debugging code.  This would be racy in
-          // multithreaded mode, but provides not basic checks in single
-          // threaded mode.
-          ++acquired;
-          return true;
         }
+        // Single-threaded debugging code.  This would be racy in
+        // multithreaded mode, but provides not basic checks in single
+        // threaded mode.
+        ++acquired;
+        return true;
       }
 
       bool unlock() {
         if (!mt_only || llvm_is_multithreaded()) {
           impl.unlock();
           return true;
-        } else {
-          // Single-threaded debugging code.  This would be racy in
-          // multithreaded mode, but provides not basic checks in single
-          // threaded mode.
-          assert(acquired && "Lock not acquired before release!");
-          --acquired;
-          return true;
         }
+        // Single-threaded debugging code.  This would be racy in
+        // multithreaded mode, but provides not basic checks in single
+        // threaded mode.
+        assert(acquired && "Lock not acquired before release!");
+        --acquired;
+        return true;
       }
 
       bool try_lock() {
         if (!mt_only || llvm_is_multithreaded())
           return impl.try_lock();
-        else return true;
+        return true;
       }
     };
 

diff  --git a/llvm/include/llvm/Support/Threading.h b/llvm/include/llvm/Support/Threading.h
index 1e7e5f7b8f503..44e133de854b8 100644
--- a/llvm/include/llvm/Support/Threading.h
+++ b/llvm/include/llvm/Support/Threading.h
@@ -50,7 +50,7 @@ class Twine;
 
 /// Returns true if LLVM is compiled with support for multi-threading, and
 /// false otherwise.
-bool llvm_is_multithreaded();
+constexpr bool llvm_is_multithreaded() { return LLVM_ENABLE_THREADS; }
 
 #if LLVM_THREADING_USE_STD_CALL_ONCE
 

diff  --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp
index 04a1a9e194282..1a7ecde384b48 100644
--- a/llvm/lib/Support/Threading.cpp
+++ b/llvm/lib/Support/Threading.cpp
@@ -28,14 +28,6 @@ using namespace llvm;
 //===          independent code.
 //===----------------------------------------------------------------------===//
 
-bool llvm::llvm_is_multithreaded() {
-#if LLVM_ENABLE_THREADS != 0
-  return true;
-#else
-  return false;
-#endif
-}
-
 #if LLVM_ENABLE_THREADS == 0 ||                                                \
     (!defined(_WIN32) && !defined(HAVE_PTHREAD_H))
 uint64_t llvm::get_threadid() { return 0; }


        


More information about the llvm-commits mailing list