[PATCH] D131851: [RISCV] Add rv32 or rv64 suffix to generic cpu name

luxufan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 14 01:30:34 PDT 2022


StephenFan created this revision.
StephenFan added reviewers: MaskRay, kito-cheng, asb, jrtc27, luismarques.
Herald added subscribers: sunshaoce, VincentWu, luke957, vkmr, evandro, sameer.abuasal, s.egerton, Jim, benna, psnobl, PkmX, rogfer01, shiva0217, simoncook, hiraditya, arichardson.
Herald added a project: All.
StephenFan requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD.
Herald added a project: LLVM.

Currently, host cpu name is determined by uarch line which is read from
/proc/cpuinfo. But since qemu's cpuinfo doesn't have an uarch line,
getHostCPUNameForRISCV would just return "generic".

This patch adds rv32 or rv64 suffix to "generic" string to avoid issues
like can't recognize "generic" cpu name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131851

Files:
  llvm/lib/Support/Host.cpp
  llvm/unittests/Support/Host.cpp


Index: llvm/unittests/Support/Host.cpp
===================================================================
--- llvm/unittests/Support/Host.cpp
+++ llvm/unittests/Support/Host.cpp
@@ -386,8 +386,25 @@
 mmu             : sv39
 uarch           : sifive,u74-mc
 )";
+  const StringRef QemuRV64CPUInfo = R"(
+processor       : 0
+hart            : 1
+isa             : rv64imafdc
+mmu             : sv39
+)";
+  const StringRef QemuRV32CPUInfo = R"(
+processor       : 0
+hart            : 1
+isa             : rv32imafdc
+mmu             : sv39
+)";
+
   EXPECT_EQ(sys::detail::getHostCPUNameForRISCV(SifiveU74MCProcCPUInfo),
             "sifive-u74");
+  EXPECT_EQ(sys::detail::getHostCPUNameForRISCV(QemuRV64CPUInfo),
+            "generic-rv64");
+  EXPECT_EQ(sys::detail::getHostCPUNameForRISCV(QemuRV32CPUInfo),
+            "generic-rv32");
   EXPECT_EQ(
       sys::detail::getHostCPUNameForRISCV("uarch           : sifive,bullet0\n"),
       "sifive-u74");
Index: llvm/lib/Support/Host.cpp
===================================================================
--- llvm/lib/Support/Host.cpp
+++ llvm/lib/Support/Host.cpp
@@ -396,17 +396,19 @@
 
   // Look for uarch line to determine cpu name
   StringRef UArch;
+  // Look for isa line to determine rv32 or rv64
+  StringRef ISA;
   for (unsigned I = 0, E = Lines.size(); I != E; ++I) {
-    if (Lines[I].startswith("uarch")) {
+    if (Lines[I].startswith("uarch"))
       UArch = Lines[I].substr(5).ltrim("\t :");
-      break;
-    }
+    if (Lines[I].startswith("isa"))
+      ISA = Lines[I].substr(3).ltrim("\t :");
   }
 
   return StringSwitch<const char *>(UArch)
       .Case("sifive,u74-mc", "sifive-u74")
       .Case("sifive,bullet0", "sifive-u74")
-      .Default("generic");
+      .Default(ISA.startswith("rv64") ? "generic-rv64" : "generic-rv32");
 }
 
 StringRef sys::detail::getHostCPUNameForBPF() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131851.452493.patch
Type: text/x-patch
Size: 1871 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220814/d196f948/attachment.bin>


More information about the llvm-commits mailing list