diff --git a/llvm/include/llvm/Support/Threading.h b/llvm/include/llvm/Support/Threading.h index f3f7c44bd439a2..ce8dbff510e8af 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 // So we can check the C++ standard lib macros. +#include #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 compute_cpu_socket(unsigned ThreadPoolNum) const; + std::optional 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 + std::optional 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 S = + std::optional 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 910437cfb70af2..24962ae2091913 100644 --- a/llvm/lib/Support/Threading.cpp +++ b/llvm/lib/Support/Threading.cpp @@ -90,7 +90,7 @@ const llvm::Optional llvm::thread::DefaultStackSize; #endif -Optional +std::optional 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 03c05554525911..3c012f12ea6efd 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 +std::optional llvm::ThreadPoolStrategy::compute_cpu_socket(unsigned ThreadPoolNum) const { ArrayRef 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 Socket = compute_cpu_socket(ThreadPoolNum); + std::optional Socket = compute_cpu_socket(ThreadPoolNum); if (!Socket) return; ArrayRef Groups = getProcessorGroups();