llvm/llvm-project

[RISC-V] Update Linux Feature Detection

Open

#192317 opened on Apr 15, 2026

View on GitHub
 (9 comments) (1 reaction) (1 assignee)C++ (26,378 stars) (10,782 forks)batch import
backend:RISC-Vgood first issue

Description

There are new architecture hwprobe features exposed by recent linux versions. The docs are here: https://docs.kernel.org/arch/riscv/hwprobe.html

I think we have implemented up to RISCV_HWPROBE_EXT_ZAWRS, but no further. We should add support for the rest of the supported extensions.

This entails:

  • Proposing extension bitmask assignments for (standard) extensions that don't have them already. This is done via the https://github.com/riscv-non-isa/riscv-c-api-doc repo (note that there are some proposed but not yet landed bitmask assignments in the open PRs for that repo, which new proposals should not conflict with).
  • Add the RISCVExtensionBitmask to the relevant extensions.
  • Implement detection in llvm/lib/TargetParser/Host.cpp (used by -march=native) and compiler-rt/lib/builtins/cpu_model/riscv.c (used by ifuncs)

There is no compiler-rt interface for exposing vendor-specific extensions (which have a different hwprobe keys), but we may still be able to detect them in llvm/lib/TargetParser/Host.cpp for -march=native.

This would also be a good opportunity to move away from the deprecated RISCV_HWPROBE_KEY_CPUPERF_0, and to RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF, and also implement the same for RISCV_HWPROBE_KEY_MISALIGNED_VECTOR_PERF potentially (this can be a separate PR).

Contributor guide