[clang] [llvm] [WIP][RISCV] Support __builtin_cpu_init and __builtin_cpu_supports (PR #99700)
Piyou Chen via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 19 22:41:42 PDT 2024
BeMg wrote:
> * Updating clang tests to exercise this logic.
> * Actually running it at all. I did not build compiler-rt, and thus all my checking was of generated asm/IR.
Maybe we could compile the test code with `compiler-rt/lib/builtins/riscv/feature_bits.c` manually. Then we could get rid of copmiler-rt building during running the `__builtin_cpu_init` and `__builtin_cpu_supports` actually.
Actually, I tried this patch in my local, and it work well.
---
Here is build script for compiler-rt, if you want to build compiler-rt.
```
cmake -DCMAKE_C_COMPILER_TARGET="riscv64-unknown-linux-gnu" \
-DCMAKE_ASM_COMPILER_TARGET="riscv64-unknown-linux-gnu" \
-DCMAKE_AR=./path/to/llvm/install/bin/llvm-ar \
-DCMAKE_C_COMPILER=./path/to/llvm/install/bin/clang \
-DCMAKE_NM=./path/to/llvm/install/bin/llvm-nm \
-DCMAKE_RANLIB=./path/to/llvm/install/bin/llvm-ranlib \
-DCOMPILER_RT_BUILD_BUILTINS=ON \
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
-DCOMPILER_RT_BUILD_MEMPROF=OFF \
-DCOMPILER_RT_BUILD_PROFILE=OFF \
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
-DCOMPILER_RT_BUILD_XRAY=OFF \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
-DLLVM_CONFIG_PATH=./path/to/llvm/install/bin/llvm-config \
-G "Ninja" ../compiler-rt
ninja
# Put the `libclang_rt.builtins-riscv64.a` in correct path
cp ./path/to/build/lib/linux/* ./path/to/llvm/install/lib/clang/19/lib/linux
```
```
# Compile using compiler-rt
clang -march=rv64imafd -rtlib=compiler-rt test.c
```
> * Investigate claims from gcc docs that __builtin_cpu_init is called early in process lifetime with high priority constructor. I did not find this with some quick searching.
https://github.com/llvm/llvm-project/pull/99700
More information about the llvm-commits
mailing list