Pointers to writing a new backend for beginners?

I need to write a new LLVM backend for a target processor from scratch.

I have gone through the document Writing an LLVM Backend. Unfortunately, this document describes the steps at a very high level and misses details. As a beginner who knows nothing about the source code yet, I haven’t found it super helpful so far. But I understand that the learning curve should be steep.

So, I went on to look for more documents, and I found Tutorial: Creating an LLVM Backend for the Cpu0 Architecture. It is a detailed external tutorial that teaches you how to write a new backend step by step. It is a very detailed but lengthy tutorial. It is full of grammar mistakes, but it is tolerable. The example architecture Cpu0 is a mips-like ISA, targeting ELF as the output file format.

The problem I have found so far is that the tutorial lacks some necessary explanations when it just tells me where to put what code. My target ISA, ABI, and output file format are different than in the tutorial. It is a VLIW architecture, targeting XCOFF file format. I am just worried that the tutorial is too specific to fit my needs.

However, I believe that these two documents mentioned above are not the only ones available online. Can anyone suggest me some good (or better) materials to read (or watch)? It will be very appreciated.

1 Like

You could have a look at this discussion.

I found How to Write an LLVM Backend #0: Introduction | Source Code Artisan to be quite helpful. But I do agree that generally the existing materials are a bit lacking in terms of explaining how things fit together, what is important/necessary for what, etc.

You might find the RISC-V patches helpful: GitHub - lowRISC/riscv-llvm: RISC-V support for LLVM projects (LLVM, Clang, ...)
I know it’s not what you’re looking for (it’s another RISC that uses ELF) but it could be useful to get a sense of what is needed in a backend.