aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Threading.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Support/Threading.cpp')
-rw-r--r--llvm/lib/Support/Threading.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp
index de5adad..39de058 100644
--- a/llvm/lib/Support/Threading.cpp
+++ b/llvm/lib/Support/Threading.cpp
@@ -84,16 +84,34 @@ void llvm::llvm_execute_on_thread_async(
int computeHostNumHardwareThreads();
unsigned llvm::ThreadPoolStrategy::compute_thread_count() const {
+ if (ThreadsRequested > 0)
+ return ThreadsRequested;
+
int MaxThreadCount = UseHyperThreads ? computeHostNumHardwareThreads()
: sys::getHostNumPhysicalCores();
if (MaxThreadCount <= 0)
MaxThreadCount = 1;
+ return MaxThreadCount;
+}
- // No need to create more threads than there are hardware threads, it would
- // uselessly induce more context-switching and cache eviction.
- if (!ThreadsRequested || ThreadsRequested > (unsigned)MaxThreadCount)
- return MaxThreadCount;
- return ThreadsRequested;
+Optional<ThreadPoolStrategy>
+llvm::get_threadpool_strategy(StringRef Num, ThreadPoolStrategy Default) {
+ if (Num == "all")
+ return llvm::hardware_concurrency();
+ if (Num.empty())
+ return Default;
+ unsigned V;
+ if (Num.getAsInteger(10, V))
+ return None; // malformed 'Num' value
+ if (V == 0)
+ return Default;
+
+ // Do not take the Default into account. This effectively disables
+ // heavyweight_hardware_concurrency() if the user asks for any number of
+ // threads on the cmd-line.
+ ThreadPoolStrategy S = llvm::hardware_concurrency();
+ S.ThreadsRequested = V;
+ return S;
}
namespace {