Skip to content

About this tutorial

This tutorial will go over the process of converting LLVM IR to MIPS assembly code.

Right now this only covers the return instruction.

Specifically, we will only be working on llc, the static LLVM IR to assembly compiler.

We will add a new target named Nova to the LLVM tree for the MIPS architecture. Like Crafting Interpreters, every line has an explanation in this series so you can follow along seamlessly.

The main contribution of this tutorial is the pattern matching syntax for tablegen, given here

Reader’s guide

The finished code for this backend is at the nova-backend branch of the fork.

Running commands

All bash commands are to be run from the root of the LLVM source tree, named as llvm-project.

Example setup
git clone https://github.com/llvm/llvm-project
cd llvm-project

Command outputs

For some commands I include the output that I get from it, which is displayed like so:

Output below the command(s)
echo "Hello World!"
echo "Output is after this code block"
Hello World!
Output is after this code block

Errata

If you find any errors or have any suggestions, please let me know by creating an issue on the book’s GitHub repository. PRs are also most welcome!

Since I am also new to LLVM, I am writing this for myself and others to learn about it. I hope you find it useful enough!