diff options
author | luxufan <luxufan@iscas.ac.cn> | 2022-05-17 14:06:42 +0800 |
---|---|---|
committer | luxufan <luxufan@iscas.ac.cn> | 2022-05-17 14:06:59 +0800 |
commit | 63c81b23bebed8ca39cf73715952fd40947b5b02 (patch) | |
tree | 9c36fb35cf41830b33d87135b4d9300939cc9377 /llvm/lib/Support/Host.cpp | |
parent | 9b519f416b70db0fa3bba020732988d3555a3625 (diff) | |
download | llvm-63c81b23bebed8ca39cf73715952fd40947b5b02.zip llvm-63c81b23bebed8ca39cf73715952fd40947b5b02.tar.gz llvm-63c81b23bebed8ca39cf73715952fd40947b5b02.tar.bz2 |
[RISCV] Support getHostCpuName for sifive-u74
Reviewed By: kito-cheng
Differential Revision: https://reviews.llvm.org/D123978
Diffstat (limited to 'llvm/lib/Support/Host.cpp')
-rw-r--r-- | llvm/lib/Support/Host.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp index 976599f..08e3a27 100644 --- a/llvm/lib/Support/Host.cpp +++ b/llvm/lib/Support/Host.cpp @@ -386,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"; @@ -1379,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 @@ -1386,6 +1411,7 @@ StringRef sys::getHostCPUName() { #else #error "Unhandled value of __riscv_xlen" #endif +#endif } #else StringRef sys::getHostCPUName() { return "generic"; } |