forked from OSchip/llvm-project
[Support] Handle SPARC in sys::getHostCPUName
While working on D118450 <https://reviews.llvm.org/D118450>, I noticed that `sys::getHostCPUName` lacks SPARC support. This patch implements it. The code is taken from/inspired by GCC's `gcc/config/sparc/driver-sparc.cc`. There's one caveat: since LLVM, unlike GCC, doesn't support the SPARC-M7, -S7, and -M8 CPUs, I map all those to the latest supported one (UltraSparc T4/`niagara4`). Tested on `sparcv9-sun-solaris2.11` and `sparc64-unknown-linux-gnu` by running `savcov --version` on - Netra SPARC S7-2 (SPARC-S7, Solaris 11.4) - SPARC T5-2 (SPARC T5, Solaris 11.4) - SPARC Enterprise T5220 (UltraSPARC T2, Solaris 11.3) - SPARC T5 (UltraSPARC T5, Debian sid) - SPARC T3 (UltraSPARC T3, Debian sid) - SPARC Enterprise T5220 (Debian sid) Differential Revision: https://reviews.llvm.org/D130272
This commit is contained in:
parent
d3fc779e42
commit
979ddfff37
|
@ -65,6 +65,7 @@ namespace sys {
|
|||
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.
|
||||
|
|
|
@ -58,6 +58,9 @@ elseif( CMAKE_HOST_UNIX )
|
|||
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()
|
||||
|
|
|
@ -47,6 +47,9 @@
|
|||
#ifdef _AIX
|
||||
#include <sys/systemcfg.h>
|
||||
#endif
|
||||
#if defined(__sun__) && defined(__svr4__)
|
||||
#include <kstat.h>
|
||||
#endif
|
||||
|
||||
#define DEBUG_TYPE "host-detection"
|
||||
|
||||
|
@ -1413,6 +1416,111 @@ StringRef sys::getHostCPUName() {
|
|||
#endif
|
||||
#endif
|
||||
}
|
||||
#elif defined(__sparc__)
|
||||
#if defined(__linux__)
|
||||
StringRef sys::detail::getHostCPUNameForSPARC(StringRef ProcCpuinfoContent) {
|
||||
SmallVector<StringRef> 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<const char *>(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<llvm::MemoryBuffer> 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<char *>("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<char *>("brand"));
|
||||
if (brand != NULL && brand->data_type == KSTAT_DATA_STRING)
|
||||
buf = KSTAT_NAMED_STR_PTR(brand);
|
||||
}
|
||||
kstat_close(kc);
|
||||
|
||||
return StringSwitch<const char *>(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 {
|
||||
|
|
Loading…
Reference in New Issue