[llvm] 5e50b80 - Threading: Convert Optional to std::optional

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 1 14:36:17 PST 2022


Author: Fangrui Song
Date: 2022-12-01T22:36:05Z
New Revision: 5e50b8089aee249d77542ea858d956568ec6581f

URL: https://github.com/llvm/llvm-project/commit/5e50b8089aee249d77542ea858d956568ec6581f
DIFF: https://github.com/llvm/llvm-project/commit/5e50b8089aee249d77542ea858d956568ec6581f.diff

LOG: Threading: Convert Optional to std::optional

Added: 
    

Modified: 
    llvm/include/llvm/Support/Threading.h
    llvm/lib/Support/Threading.cpp
    llvm/lib/Support/Windows/Threading.inc

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/Threading.h b/llvm/include/llvm/Support/Threading.h
index f3f7c44bd439..ce8dbff510e8 100644
--- a/llvm/include/llvm/Support/Threading.h
+++ b/llvm/include/llvm/Support/Threading.h
@@ -19,6 +19,7 @@
 #include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
 #include "llvm/Support/Compiler.h"
 #include <ciso646> // So we can check the C++ standard lib macros.
+#include <optional>
 
 #if defined(_MSC_VER)
 // MSVC's call_once implementation worked since VS 2015, which is the minimum
@@ -140,7 +141,7 @@ constexpr bool llvm_is_multithreaded() { return LLVM_ENABLE_THREADS; }
 
     /// Finds the CPU socket where a thread should go. Returns 'None' if the
     /// thread shall remain on the actual CPU socket.
-    Optional<unsigned> compute_cpu_socket(unsigned ThreadPoolNum) const;
+    std::optional<unsigned> compute_cpu_socket(unsigned ThreadPoolNum) const;
   };
 
   /// Build a strategy from a number of threads as a string provided in \p Num.
@@ -148,7 +149,7 @@ constexpr bool llvm_is_multithreaded() { return LLVM_ENABLE_THREADS; }
   /// strategy, we attempt to equally allocate the threads on all CPU sockets.
   /// "0" or an empty string will return the \p Default strategy.
   /// "all" for using all hardware threads.
-  Optional<ThreadPoolStrategy>
+  std::optional<ThreadPoolStrategy>
   get_threadpool_strategy(StringRef Num, ThreadPoolStrategy Default = {});
 
   /// Returns a thread strategy for tasks requiring significant memory or other
@@ -170,7 +171,7 @@ constexpr bool llvm_is_multithreaded() { return LLVM_ENABLE_THREADS; }
   /// If \p Num is invalid, returns a default strategy where one thread per
   /// hardware core is used.
   inline ThreadPoolStrategy heavyweight_hardware_concurrency(StringRef Num) {
-    Optional<ThreadPoolStrategy> S =
+    std::optional<ThreadPoolStrategy> S =
         get_threadpool_strategy(Num, heavyweight_hardware_concurrency());
     if (S)
       return *S;

diff  --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp
index 910437cfb70a..24962ae20919 100644
--- a/llvm/lib/Support/Threading.cpp
+++ b/llvm/lib/Support/Threading.cpp
@@ -90,7 +90,7 @@ const llvm::Optional<unsigned> llvm::thread::DefaultStackSize;
 
 #endif
 
-Optional<ThreadPoolStrategy>
+std::optional<ThreadPoolStrategy>
 llvm::get_threadpool_strategy(StringRef Num, ThreadPoolStrategy Default) {
   if (Num == "all")
     return llvm::hardware_concurrency();
@@ -98,7 +98,7 @@ llvm::get_threadpool_strategy(StringRef Num, ThreadPoolStrategy Default) {
     return Default;
   unsigned V;
   if (Num.getAsInteger(10, V))
-    return None; // malformed 'Num' value
+    return std::nullopt; // malformed 'Num' value
   if (V == 0)
     return Default;
 

diff  --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc
index 03c055545259..3c012f12ea6e 100644
--- a/llvm/lib/Support/Windows/Threading.inc
+++ b/llvm/lib/Support/Windows/Threading.inc
@@ -248,7 +248,7 @@ static int computeHostNumHardwareThreads() {
 
 // Finds the proper CPU socket where a thread number should go. Returns 'None'
 // if the thread shall remain on the actual CPU socket.
-Optional<unsigned>
+std::optional<unsigned>
 llvm::ThreadPoolStrategy::compute_cpu_socket(unsigned ThreadPoolNum) const {
   ArrayRef<ProcessorGroup> Groups = getProcessorGroups();
   // Only one CPU socket in the system or process affinity was set, no need to
@@ -273,7 +273,7 @@ llvm::ThreadPoolStrategy::compute_cpu_socket(unsigned ThreadPoolNum) const {
 // Assign the current thread to a more appropriate CPU socket or CPU group
 void llvm::ThreadPoolStrategy::apply_thread_strategy(
     unsigned ThreadPoolNum) const {
-  Optional<unsigned> Socket = compute_cpu_socket(ThreadPoolNum);
+  std::optional<unsigned> Socket = compute_cpu_socket(ThreadPoolNum);
   if (!Socket)
     return;
   ArrayRef<ProcessorGroup> Groups = getProcessorGroups();


        


More information about the llvm-commits mailing list