diff options
Diffstat (limited to 'llvm/lib/Support/Host.cpp')
-rw-r--r-- | llvm/lib/Support/Host.cpp | 115 |
1 files changed, 80 insertions, 35 deletions
diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp index f6003b783245..08e3a27e0173 100644 --- a/llvm/lib/Support/Host.cpp +++ b/llvm/lib/Support/Host.cpp @@ -11,20 +11,15 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Host.h" -#include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" #include "llvm/Config/llvm-config.h" -#include "llvm/Support/BCD.h" -#include "llvm/Support/Debug.h" -#include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/X86TargetParser.h" #include "llvm/Support/raw_ostream.h" -#include <assert.h> #include <string.h> // Include the platform-specific parts of this class. @@ -38,11 +33,16 @@ #ifdef _MSC_VER #include <intrin.h> #endif -#if defined(__APPLE__) && (!defined(__x86_64__)) +#ifdef __MVS__ +#include "llvm/Support/BCD.h" +#endif +#if defined(__APPLE__) #include <mach/host_info.h> #include <mach/mach.h> #include <mach/mach_host.h> #include <mach/machine.h> +#include <sys/param.h> +#include <sys/sysctl.h> #endif #ifdef _AIX #include <sys/systemcfg.h> @@ -296,6 +296,12 @@ StringRef sys::detail::getHostCPUNameForARM(StringRef ProcCpuinfoContent) { } } + if (Implementer == "0xc0") { // Ampere Computing + return StringSwitch<const char *>(Part) + .Case("0xac3", "ampere1") + .Default("generic"); + } + return "generic"; } @@ -330,7 +336,7 @@ StringRef getCPUNameFromS390Model(unsigned int Id, bool HaveVectorSupport) { case 3931: case 3932: default: - return HaveVectorSupport? "arch14" : "zEC12"; + return HaveVectorSupport? "z16" : "zEC12"; } } } // end anonymous namespace @@ -380,6 +386,26 @@ StringRef sys::detail::getHostCPUNameForS390x(StringRef ProcCpuinfoContent) { return "generic"; } +StringRef sys::detail::getHostCPUNameForRISCV(StringRef ProcCpuinfoContent) { + // There are 24 lines in /proc/cpuinfo + SmallVector<StringRef> Lines; + ProcCpuinfoContent.split(Lines, "\n"); + + // Look for uarch line to determine cpu name + StringRef UArch; + for (unsigned I = 0, E = Lines.size(); I != E; ++I) { + if (Lines[I].startswith("uarch")) { + UArch = Lines[I].substr(5).ltrim("\t :"); + break; + } + } + + return StringSwitch<const char *>(UArch) + .Case("sifive,u74-mc", "sifive-u74") + .Case("sifive,bullet0", "sifive-u74") + .Default("generic"); +} + StringRef sys::detail::getHostCPUNameForBPF() { #if !defined(__linux__) || !defined(__x86_64__) return "generic"; @@ -1034,9 +1060,9 @@ getAMDProcessorTypeAndSubtype(unsigned Family, unsigned Model, case 25: CPU = "znver3"; *Type = X86::AMDFAM19H; - if (Model <= 0x0f) { + if (Model <= 0x0f || Model == 0x21) { *Subtype = X86::AMDFAM19H_ZNVER3; - break; // 00h-0Fh: Zen3 + break; // 00h-0Fh, 21h: Zen3 } break; default: @@ -1299,32 +1325,45 @@ StringRef sys::getHostCPUName() { bool HaveVectorSupport = CVT[244] & 0x80; return getCPUNameFromS390Model(Id, HaveVectorSupport); } -#elif defined(__APPLE__) && defined(__aarch64__) -StringRef sys::getHostCPUName() { - return "cyclone"; -} -#elif defined(__APPLE__) && defined(__arm__) -StringRef sys::getHostCPUName() { - host_basic_info_data_t hostInfo; - mach_msg_type_number_t infoCount; +#elif defined(__APPLE__) && (defined(__arm__) || defined(__aarch64__)) +#define CPUFAMILY_ARM_SWIFT 0x1e2d6381 +#define CPUFAMILY_ARM_CYCLONE 0x37a09642 +#define CPUFAMILY_ARM_TYPHOON 0x2c91a47e +#define CPUFAMILY_ARM_TWISTER 0x92fb37c8 +#define CPUFAMILY_ARM_HURRICANE 0x67ceee93 +#define CPUFAMILY_ARM_MONSOON_MISTRAL 0xe81e7ef6 +#define CPUFAMILY_ARM_VORTEX_TEMPEST 0x07d34b9f +#define CPUFAMILY_ARM_LIGHTNING_THUNDER 0x462504d2 +#define CPUFAMILY_ARM_FIRESTORM_ICESTORM 0x1b588bb3 - infoCount = HOST_BASIC_INFO_COUNT; - mach_port_t hostPort = mach_host_self(); - host_info(hostPort, HOST_BASIC_INFO, (host_info_t)&hostInfo, - &infoCount); - mach_port_deallocate(mach_task_self(), hostPort); +StringRef sys::getHostCPUName() { + uint32_t Family; + size_t Length = sizeof(Family); + sysctlbyname("hw.cpufamily", &Family, &Length, NULL, 0); - if (hostInfo.cpu_type != CPU_TYPE_ARM) { - assert(false && "CPUType not equal to ARM should not be possible on ARM"); - return "generic"; + switch (Family) { + case CPUFAMILY_ARM_SWIFT: + return "swift"; + case CPUFAMILY_ARM_CYCLONE: + return "apple-a7"; + case CPUFAMILY_ARM_TYPHOON: + return "apple-a8"; + case CPUFAMILY_ARM_TWISTER: + return "apple-a9"; + case CPUFAMILY_ARM_HURRICANE: + return "apple-a10"; + case CPUFAMILY_ARM_MONSOON_MISTRAL: + return "apple-a11"; + case CPUFAMILY_ARM_VORTEX_TEMPEST: + return "apple-a12"; + case CPUFAMILY_ARM_LIGHTNING_THUNDER: + return "apple-a13"; + case CPUFAMILY_ARM_FIRESTORM_ICESTORM: + return "apple-m1"; + default: + // Default to the newest CPU we know about. + return "apple-m1"; } - switch (hostInfo.cpu_subtype) { - case CPU_SUBTYPE_ARM_V7S: - return "swift"; - default:; - } - - return "generic"; } #elif defined(_AIX) StringRef sys::getHostCPUName() { @@ -1360,6 +1399,11 @@ StringRef sys::getHostCPUName() { } #elif defined(__riscv) StringRef sys::getHostCPUName() { +#if defined(__linux__) + std::unique_ptr<llvm::MemoryBuffer> P = getProcCpuinfoContent(); + StringRef Content = P ? P->getBuffer() : ""; + return detail::getHostCPUNameForRISCV(Content); +#else #if __riscv_xlen == 64 return "generic-rv64"; #elif __riscv_xlen == 32 @@ -1367,6 +1411,7 @@ StringRef sys::getHostCPUName() { #else #error "Unhandled value of __riscv_xlen" #endif +#endif } #else StringRef sys::getHostCPUName() { return "generic"; } @@ -1455,9 +1500,6 @@ int computeHostNumPhysicalCores() { #elif defined(__linux__) && defined(__s390x__) int computeHostNumPhysicalCores() { return sysconf(_SC_NPROCESSORS_ONLN); } #elif defined(__APPLE__) -#include <sys/param.h> -#include <sys/sysctl.h> - // Gets the number of *physical cores* on the machine. int computeHostNumPhysicalCores() { uint32_t count; @@ -1706,6 +1748,9 @@ bool sys::getHostCPUFeatures(StringMap<bool> &Features) { .Case("asimd", "neon") .Case("fp", "fp-armv8") .Case("crc32", "crc") + .Case("atomics", "lse") + .Case("sve", "sve") + .Case("sve2", "sve2") #else .Case("half", "fp16") .Case("neon", "neon") |