[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)

Philip Reames via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 26 16:18:25 PDT 2024


================
@@ -2002,6 +2003,76 @@ bool sys::getHostCPUFeatures(StringMap<bool> &Features) {
 
   return true;
 }
+#elif defined(__linux__) && defined(__riscv)
+// struct riscv_hwprobe
+struct RISCVHwProbe {
+  int64_t Key;
+  uint64_t Value;
+};
+bool sys::getHostCPUFeatures(StringMap<bool> &Features) {
+  RISCVHwProbe Query[]{{/*RISCV_HWPROBE_KEY_BASE_BEHAVIOR=*/3, 0},
+                       {/*RISCV_HWPROBE_KEY_IMA_EXT_0=*/4, 0}};
+  int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/Query,
----------------
preames wrote:

Consider this a purely stylistic comment.

We should probably be using either the vDSO symbol or the glibc shim.  In either case, we'd have a weak symbol which could possibly be nullptr, and need to return early.  

In this use case, the difference likely doesn't matter, but if we reuse this code, the lack of caching provided by vDSO could be problematic.  

https://github.com/llvm/llvm-project/pull/94352


More information about the cfe-commits mailing list