llvmllvm-codegen

How to write a simple LLVM backend target?


I have read this doc and first chapter of this example.

The doc and example are really good at helping me understanding backend of compiler and LLVM.

However, they still not answering the question of for adding a new target, what file (minimum) I need to modify and add, with the reasons of doing that.

In the example, it asked me to change bunch of llvm config files, while in the doc, it just ask me to add lib/Target/<name of target> and add config option -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=<name of target> or add target name into LLVM_ALL_TARGETS in llvm/CMakeLists.txt.

It actually makes me confused of how to add a new target simple and clear.

Thus I would like to ask if anyone knows, thanks!!!


Solution

  • I made this: https://github.com/artyom-razinov/llvm-project/tree/llvm-backend-riscw

    Which is updated version of this: https://github.com/andresag01/llvm-project

    Which is a repo for this article: https://sourcecodeartisan.com/2020/09/13/llvm-backend-0.html

    Comment for last commit has some info on how to build and how to compile c to target architecture (some riscw architecture, I have no idea what it is): https://github.com/artyom-razinov/llvm-project/commit/cb8a38e1ed0e3101ba2a46b4dff683bc63abbc66

    Off-topic: It's sad that github doesn't support markdown in commit messages...