|
41 | 41 | #include <mach/mach.h>
|
42 | 42 | #include <mach/mach_host.h>
|
43 | 43 | #include <mach/machine.h>
|
| 44 | +#include <sys/param.h> |
| 45 | +#include <sys/sysctl.h> |
44 | 46 | #endif
|
45 | 47 | #ifdef _AIX
|
46 | 48 | #include <sys/systemcfg.h>
|
@@ -1297,32 +1299,45 @@ StringRef sys::getHostCPUName() {
|
1297 | 1299 | bool HaveVectorSupport = CVT[244] & 0x80;
|
1298 | 1300 | return getCPUNameFromS390Model(Id, HaveVectorSupport);
|
1299 | 1301 | }
|
1300 |
| -#elif defined(__APPLE__) && defined(__aarch64__) |
1301 |
| -StringRef sys::getHostCPUName() { |
1302 |
| - return "cyclone"; |
1303 |
| -} |
1304 |
| -#elif defined(__APPLE__) && defined(__arm__) |
1305 |
| -StringRef sys::getHostCPUName() { |
1306 |
| - host_basic_info_data_t hostInfo; |
1307 |
| - mach_msg_type_number_t infoCount; |
| 1302 | +#elif defined(__APPLE__) && (defined(__arm__) || defined(__aarch64__)) |
| 1303 | +#define CPUFAMILY_ARM_SWIFT 0x1e2d6381 |
| 1304 | +#define CPUFAMILY_ARM_CYCLONE 0x37a09642 |
| 1305 | +#define CPUFAMILY_ARM_TYPHOON 0x2c91a47e |
| 1306 | +#define CPUFAMILY_ARM_TWISTER 0x92fb37c8 |
| 1307 | +#define CPUFAMILY_ARM_HURRICANE 0x67ceee93 |
| 1308 | +#define CPUFAMILY_ARM_MONSOON_MISTRAL 0xe81e7ef6 |
| 1309 | +#define CPUFAMILY_ARM_VORTEX_TEMPEST 0x07d34b9f |
| 1310 | +#define CPUFAMILY_ARM_LIGHTNING_THUNDER 0x462504d2 |
| 1311 | +#define CPUFAMILY_ARM_FIRESTORM_ICESTORM 0x1b588bb3 |
1308 | 1312 |
|
1309 |
| - infoCount = HOST_BASIC_INFO_COUNT; |
1310 |
| - mach_port_t hostPort = mach_host_self(); |
1311 |
| - host_info(hostPort, HOST_BASIC_INFO, (host_info_t)&hostInfo, |
1312 |
| - &infoCount); |
1313 |
| - mach_port_deallocate(mach_task_self(), hostPort); |
| 1313 | +StringRef sys::getHostCPUName() { |
| 1314 | + uint32_t Family; |
| 1315 | + size_t Length = sizeof(Family); |
| 1316 | + sysctlbyname("hw.cpufamily", &Family, &Length, NULL, 0); |
1314 | 1317 |
|
1315 |
| - if (hostInfo.cpu_type != CPU_TYPE_ARM) { |
1316 |
| - assert(false && "CPUType not equal to ARM should not be possible on ARM"); |
1317 |
| - return "generic"; |
| 1318 | + switch (Family) { |
| 1319 | + case CPUFAMILY_ARM_SWIFT: |
| 1320 | + return "swift"; |
| 1321 | + case CPUFAMILY_ARM_CYCLONE: |
| 1322 | + return "apple-a7"; |
| 1323 | + case CPUFAMILY_ARM_TYPHOON: |
| 1324 | + return "apple-a8"; |
| 1325 | + case CPUFAMILY_ARM_TWISTER: |
| 1326 | + return "apple-a9"; |
| 1327 | + case CPUFAMILY_ARM_HURRICANE: |
| 1328 | + return "apple-a10"; |
| 1329 | + case CPUFAMILY_ARM_MONSOON_MISTRAL: |
| 1330 | + return "apple-a11"; |
| 1331 | + case CPUFAMILY_ARM_VORTEX_TEMPEST: |
| 1332 | + return "apple-a12"; |
| 1333 | + case CPUFAMILY_ARM_LIGHTNING_THUNDER: |
| 1334 | + return "apple-a13"; |
| 1335 | + case CPUFAMILY_ARM_FIRESTORM_ICESTORM: |
| 1336 | + return "apple-m1"; |
| 1337 | + default: |
| 1338 | + // Default to the newest CPU we know about. |
| 1339 | + return "apple-m1"; |
1318 | 1340 | }
|
1319 |
| - switch (hostInfo.cpu_subtype) { |
1320 |
| - case CPU_SUBTYPE_ARM_V7S: |
1321 |
| - return "swift"; |
1322 |
| - default:; |
1323 |
| - } |
1324 |
| - |
1325 |
| - return "generic"; |
1326 | 1341 | }
|
1327 | 1342 | #elif defined(_AIX)
|
1328 | 1343 | StringRef sys::getHostCPUName() {
|
@@ -1453,9 +1468,6 @@ int computeHostNumPhysicalCores() {
|
1453 | 1468 | #elif defined(__linux__) && defined(__s390x__)
|
1454 | 1469 | int computeHostNumPhysicalCores() { return sysconf(_SC_NPROCESSORS_ONLN); }
|
1455 | 1470 | #elif defined(__APPLE__)
|
1456 |
| -#include <sys/param.h> |
1457 |
| -#include <sys/sysctl.h> |
1458 |
| - |
1459 | 1471 | // Gets the number of *physical cores* on the machine.
|
1460 | 1472 | int computeHostNumPhysicalCores() {
|
1461 | 1473 | uint32_t count;
|
|
0 commit comments