diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2016-10-19 22:36:07 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-10-19 22:36:07 +0000 |
commit | db46b7d217ed4462a4a02d0111e25593287dfcf1 (patch) | |
tree | 5e52b92a22b14963c0b4def8bbf8263a41aca7bf /llvm/lib/Support | |
parent | 3cb2a1e8d1b80633ead8d8a0abc8733bfaaede59 (diff) | |
download | bcm5719-llvm-db46b7d217ed4462a4a02d0111e25593287dfcf1.tar.gz bcm5719-llvm-db46b7d217ed4462a4a02d0111e25593287dfcf1.zip |
Add computeHostNumPhysicalCores() implementation for Darwin
Differential Revision: https://reviews.llvm.org/D25800
llvm-svn: 284656
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r-- | llvm/lib/Support/Host.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp index e4a9b504a76..dd19eee15f6 100644 --- a/llvm/lib/Support/Host.cpp +++ b/llvm/lib/Support/Host.cpp @@ -1234,6 +1234,25 @@ static int computeHostNumPhysicalCores() { } return UniqueItems.size(); } +#elif defined(__APPLE__) && defined(__x86_64__) +#include <sys/param.h> +#include <sys/sysctl.h> + +// Gets the number of *physical cores* on the machine. +static int computeHostNumPhysicalCores() { + uint32_t count; + size_t len = sizeof(count); + sysctlbyname("hw.physicalcpu", &count, &len, NULL, 0); + if (count < 1) { + int nm[2]; + nm[0] = CTL_HW; + nm[1] = HW_AVAILCPU; + sysctl(nm, 2, &count, &len, NULL, 0); + if (count < 1) + return -1; + } + return count; +} #else // On other systems, return -1 to indicate unknown. static int computeHostNumPhysicalCores() { return -1; } |