Yet another RISC-V LLVM Backend. This is a project for learning how LLVM backend works and what RISC-V architecture is by reimplementing the official LLVM's RISC-V backend.
This example is inspired by:
-
create soft link in
llvm/.vscode
cd llvm-project/llvm/.vscode ln -s ../../../scripts_in_llvm/run_with_llc.sh run_with_llc.sh
git clone --recursive https://github.com/Alwaysproblem/Toy-llvm-backend
git clone https://github.com/riscv-collab/riscv-gnu-toolchain
cd /path/to/riscv-gnu-toolchain
configure --prefix=/opt/gcc-riscv --with-arch=rv64gc --with-abi=lp64d --enable-multilib
make linux
cd /path/to/Toy-llvm-backend
bash tools/build_clang.sh
-
build and run
bash tools/build_llc.sh -p Ch1 ./llvm-project/llvm/build/bin/llc --version # LLVM (http://llvm.org/): # LLVM version x.x.x # DEBUG build with assertions. # Default target: # Host CPU: alderlake # Registered Targets: # toy - TOY Backend for riscv (32-bit) [experimental]
-
build and run
bash tools/clean_llvm_branch.sh # Optional bash tools/build_llc.sh -p Ch2 ./llvm-project/build_clang/bin/clang --target=riscv64-unknown-gnu -march=rv32g examples/arith.c -c -emit-llvm -O0 -o arith.bc ./llvm-project/llvm/build/bin/llc -debug -march=toy -filetype=asm arith.bc -o arith.S # Args: ./build/bin/llc -debug -march=toy -filetype=asm arith.bc -o arith.S # llc: /root/Desktop/dockerVolumn/Toy-llvm-backend/llvm-project/llvm/lib/CodeGen/LLVMTargetMachine.cpp:42: void llvm::LLVMTargetMachine::initAsmInfo(): Assertion 'MRI && "Unable to create reg info"' failed. # ...
you can apply the Ch3 patch to the llvm-project folder and see through the changes.
bash tools/apply_patch.sh -p Ch3