diff --git a/llvm/include/llvm/Support/Host.h b/llvm/include/llvm/Support/Host.h --- a/llvm/include/llvm/Support/Host.h +++ b/llvm/include/llvm/Support/Host.h @@ -65,6 +65,7 @@ StringRef getHostCPUNameForARM(StringRef ProcCpuinfoContent); StringRef getHostCPUNameForS390x(StringRef ProcCpuinfoContent); StringRef getHostCPUNameForRISCV(StringRef ProcCpuinfoContent); + StringRef getHostCPUNameForSPARC(StringRef ProcCpuinfoContent); StringRef getHostCPUNameForBPF(); /// Helper functions to extract CPU details from CPUID on x86. diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt --- a/llvm/lib/Support/CMakeLists.txt +++ b/llvm/lib/Support/CMakeLists.txt @@ -58,6 +58,9 @@ if( UNIX AND NOT (BEOS OR HAIKU) ) set(system_libs ${system_libs} m) endif() + if( UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "SunOS" ) + set(system_libs ${system_libs} kstat) + endif() if( FUCHSIA ) set(system_libs ${system_libs} zircon) endif() diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp --- a/llvm/lib/Support/Host.cpp +++ b/llvm/lib/Support/Host.cpp @@ -47,6 +47,9 @@ #ifdef _AIX #include #endif +#if defined(__sun__) && defined(__svr4__) +#include +#endif #define DEBUG_TYPE "host-detection" @@ -1413,6 +1416,111 @@ #endif #endif } +#elif defined(__sparc__) +#if defined(__linux__) +StringRef sys::detail::getHostCPUNameForSPARC(StringRef ProcCpuinfoContent) { + SmallVector Lines; + ProcCpuinfoContent.split(Lines, "\n"); + + // Look for cpu line to determine cpu name + StringRef Cpu; + for (unsigned I = 0, E = Lines.size(); I != E; ++I) { + if (Lines[I].startswith("cpu")) { + Cpu = Lines[I].substr(5).ltrim("\t :"); + break; + } + } + + return StringSwitch(Cpu) + .StartsWith("SuperSparc", "supersparc") + .StartsWith("HyperSparc", "hypersparc") + .StartsWith("SpitFire", "ultrasparc") + .StartsWith("BlackBird", "ultrasparc") + .StartsWith("Sabre", " ultrasparc") + .StartsWith("Hummingbird", "ultrasparc") + .StartsWith("Cheetah", "ultrasparc3") + .StartsWith("Jalapeno", "ultrasparc3") + .StartsWith("Jaguar", "ultrasparc3") + .StartsWith("Panther", "ultrasparc3") + .StartsWith("Serrano", "ultrasparc3") + .StartsWith("UltraSparc T1", "niagara") + .StartsWith("UltraSparc T2", "niagara2") + .StartsWith("UltraSparc T3", "niagara3") + .StartsWith("UltraSparc T4", "niagara4") + .StartsWith("UltraSparc T5", "niagara4") + .StartsWith("LEON", "leon3") + // niagara7/m8 not supported by LLVM yet. + .StartsWith("SPARC-M7", "niagara4" /* "niagara7" */) + .StartsWith("SPARC-S7", "niagara4" /* "niagara7" */) + .StartsWith("SPARC-M8", "niagara4" /* "m8" */) + .Default("generic"); +} +#endif + +StringRef sys::getHostCPUName() { +#if defined(__linux__) + std::unique_ptr P = getProcCpuinfoContent(); + StringRef Content = P ? P->getBuffer() : ""; + return detail::getHostCPUNameForSPARC(Content); +#elif defined(__sun__) && defined(__svr4__) + char *buf = NULL; + kstat_ctl_t *kc; + kstat_t *ksp; + kstat_named_t *brand = NULL; + + kc = kstat_open(); + if (kc != NULL) { + ksp = kstat_lookup(kc, const_cast("cpu_info"), -1, NULL); + if (ksp != NULL && kstat_read(kc, ksp, NULL) != -1 && + ksp->ks_type == KSTAT_TYPE_NAMED) + brand = + (kstat_named_t *)kstat_data_lookup(ksp, const_cast("brand")); + if (brand != NULL && brand->data_type == KSTAT_DATA_STRING) + buf = KSTAT_NAMED_STR_PTR(brand); + } + kstat_close(kc); + + return StringSwitch(buf) + .Case("TMS390S10", "supersparc") // Texas Instruments microSPARC I + .Case("TMS390Z50", "supersparc") // Texas Instruments SuperSPARC I + .Case("TMS390Z55", + "supersparc") // Texas Instruments SuperSPARC I with SuperCache + .Case("MB86904", "supersparc") // Fujitsu microSPARC II + .Case("MB86907", "supersparc") // Fujitsu TurboSPARC + .Case("RT623", "hypersparc") // Ross hyperSPARC + .Case("RT625", "hypersparc") + .Case("RT626", "hypersparc") + .Case("UltraSPARC-I", "ultrasparc") + .Case("UltraSPARC-II", "ultrasparc") + .Case("UltraSPARC-IIe", "ultrasparc") + .Case("UltraSPARC-IIi", "ultrasparc") + .Case("SPARC64-III", "ultrasparc") + .Case("SPARC64-IV", "ultrasparc") + .Case("UltraSPARC-III", "ultrasparc3") + .Case("UltraSPARC-III+", "ultrasparc3") + .Case("UltraSPARC-IIIi", "ultrasparc3") + .Case("UltraSPARC-IIIi+", "ultrasparc3") + .Case("UltraSPARC-IV", "ultrasparc3") + .Case("UltraSPARC-IV+", "ultrasparc3") + .Case("SPARC64-V", "ultrasparc3") + .Case("SPARC64-VI", "ultrasparc3") + .Case("SPARC64-VII", "ultrasparc3") + .Case("UltraSPARC-T1", "niagara") + .Case("UltraSPARC-T2", "niagara2") + .Case("UltraSPARC-T2", "niagara2") + .Case("UltraSPARC-T2+", "niagara2") + .Case("SPARC-T3", "niagara3") + .Case("SPARC-T4", "niagara4") + .Case("SPARC-T5", "niagara4") + // niagara7/m8 not supported by LLVM yet. + .Case("SPARC-M7", "niagara4" /* "niagara7" */) + .Case("SPARC-S7", "niagara4" /* "niagara7" */) + .Case("SPARC-M8", "niagara4" /* "m8" */) + .Default("generic"); +#else + return "generic"; +#endif +} #else StringRef sys::getHostCPUName() { return "generic"; } namespace llvm {