#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
/// Finds the CPU socket where a thread should go. Returns 'None' if the
/// thread shall remain on the actual CPU socket.
- std::optional<unsigned> compute_cpu_socket(unsigned ThreadPoolNum) const;
+ Optional<unsigned> compute_cpu_socket(unsigned ThreadPoolNum) const;
};
/// Build a strategy from a number of threads as a string provided in \p Num.
/// 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.
- std::optional<ThreadPoolStrategy>
+ Optional<ThreadPoolStrategy>
get_threadpool_strategy(StringRef Num, ThreadPoolStrategy Default = {});
/// Returns a thread strategy for tasks requiring significant memory or other
/// If \p Num is invalid, returns a default strategy where one thread per
/// hardware core is used.
inline ThreadPoolStrategy heavyweight_hardware_concurrency(StringRef Num) {
- std::optional<ThreadPoolStrategy> S =
+ Optional<ThreadPoolStrategy> S =
get_threadpool_strategy(Num, heavyweight_hardware_concurrency());
if (S)
return *S;
#endif
-std::optional<ThreadPoolStrategy>
+Optional<ThreadPoolStrategy>
llvm::get_threadpool_strategy(StringRef Num, ThreadPoolStrategy Default) {
if (Num == "all")
return llvm::hardware_concurrency();
return Default;
unsigned V;
if (Num.getAsInteger(10, V))
- return std::nullopt; // malformed 'Num' value
+ return None; // malformed 'Num' value
if (V == 0)
return Default;
// Finds the proper CPU socket where a thread number should go. Returns 'None'
// if the thread shall remain on the actual CPU socket.
-std::optional<unsigned>
+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
// Assign the current thread to a more appropriate CPU socket or CPU group
void llvm::ThreadPoolStrategy::apply_thread_strategy(
unsigned ThreadPoolNum) const {
- std::optional<unsigned> Socket = compute_cpu_socket(ThreadPoolNum);
+ Optional<unsigned> Socket = compute_cpu_socket(ThreadPoolNum);
if (!Socket)
return;
ArrayRef<ProcessorGroup> Groups = getProcessorGroups();