-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
arch/risc-v: Refactor LLVM CPU type handling in Toolchain.cmake #15475
Conversation
- Replace direct string comparisons with regex pattern matching for ARCHCPUEXTFLAGS - Change from using LLVM_CPUFLAGS list to setting LLVM_CPUTYPE directly - Simplify CPU type detection logic while maintaining same functionality - Use more consistent string variable naming convention This change makes the CPU type detection more flexible and maintainable while keeping the same behavior for supported RISC-V configurations. Signed-off-by: Huang Qi <[email protected]>
[Experimental Bot, please feedback here] Yes, this PR appears to meet the NuttX requirements, although it could be more thorough. While it addresses the core elements, providing more details in the "Impact" and "Testing" sections would significantly improve clarity and confidence in the changes. Specifically:
By adding these details, the PR would more robustly adhere to the guidelines, making review easier and increasing confidence in the proposed changes. |
elseif(${ARCHCPUEXTFLAGS} STREQUAL imafc) | ||
list(APPEND LLVM_CPUFLAGS -mcpu=sifive-e76) | ||
if(${ARCHCPUEXTFLAGS} MATCHES "^imc") | ||
set(LLVM_CPUTYPE "sifive-e20") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why use a specific vendor chip sifive-e20? @no1wudi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the RISC-V platform, the CPU_TYPE here is typically not utilized (pass to compiler); it is merely used to denote a combination of ISAs. For instance, sifive-e20 represents IMC. This is because LLVM's ARCH_TYPE only specifies RISCV32/RISCV64 and does not reflect the specific ISA. In practical application scenarios, such as in the Rust compiler, sifive-e20 is decoded as riscv32imc and then passed to the Rust compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why not pass the general riscv32imc directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you can still pass it to compiler as -mcpu
param in some case, it can works although it may not be the optimal choice, it will not cause any issues. But riscv32imc can not, it's not a valid identifier in LLVM backend:
Lines 42 to 46 in 724797e
# Convert cortex-xxx/sifive-exx to cortex_xxx/sifive_exx | |
ifneq ($(LLVM_CPUTYPE),) | |
ZIGFLAGS += -mcpu $(subst -,_,$(LLVM_CPUTYPE)) | |
endif |
For MCUs, symbols like sifive-e20 are merely used to indicate the ISA types supported by the RISC-V platform and do not entail any substantive optimizations for the CPU core itself.
For example, certain compilers using LLVM, such as wamrc, typically employ --cpu=generic-rv32
in conjunction with the --cpu-features
parameter +m,+c
to enable support for riscv32imc. In practice, however, this is equivalent to specifying --cpu=sifive-e20
.
Summary
This change makes the CPU type detection more flexible and maintainable while keeping the same behavior for supported RISC-V configurations.
Impact
build system only
Testing
GitHub CI and apache/nuttx-apps#2487