- Clang >= 14
- LLVM requirements
- 32-bit libc
git checkout primate
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
export PRIMATE_COMPILER_ROOT=<path to this repo>
CMake with proper targets. This will make the backend with RISCV and Primate useful for comparisons.
cmake -S llvm -B build -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DLLVM_CCACHE_BUILD=On -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_PROJECTS='clang;lld' -DLLVM_TARGETS_TO_BUILD='Primate;RISCV' -DLLVM_BUILD_TESTS=False -DCMAKE_INSTALL_PREFIX="/primate/primate-compiler/build" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=Primate -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
ninja -C {PRIMATE_COMPILER_ROOT}/build
Note: may get some odd compile fails. This is potentially caused by OOM. just retry the build again. Note: if you fail due to some inline asm related to fsqrt or similar, ensure you are using clang
export PATH="${PRIMATE_COMPILER_ROOT}/build/bin:$PATH"``
export LD_LIBRARY_PATH="${PRIMATE_COMPILER_ROOT}/build/lib:$LD_LIBRARY_PATH"``
clang++ -std=c++20 --target=primate32-linux-gnu -march=pr32i -c -o <output-file> <cpp>``
By default Primate comes with a basic setup containing a Memory unit, IO unit, and 2 lanes of green functional units.
Once you have run primate's archgen phase, you should be left with a primate.cfg, and a BFU_list.txt.
In order to compile code for the generated architecture you need to run archgen2tablegen.py <path to BFU_list.txt> <path to primate.cfg>.
This will create a directory primate-compiler-gen with the tablegen files the compiler requires.
Then run cpyTablegen.sh, re-run ninja, and you'll be able to compile!
dump the compile results:
llvm-objdump –-arch-name=primate32 -d -t <obj-file> > debug.dsm
Primate compiler has some quirks that require ironing out. If you run into a backend crash is probably best to submit your IR, and primate config files as an issue on the project instead of attempting to debug.
Another thing of interest is op-fusion. If you think there is an important scalar operation that is not currently fused, open an issue.
Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called "LLVM". This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.