Learning the (Mighty) LLVM Compiler Infrastructure

For starters, I suggest downloading the LLVM source code and building it yourself. After that, follow the official tutorial of writing a pass to get a sense of what an LLVM pass is. Starting from the hello-world pass, you can then modify the pass however you like. A few good small tasks to get yourself up to speed with LLVM are:

  • Count the number of functions and find the functions with the largest and the smallest numbers of instructions.
  • Check the size of all the structs of a C/C++ program and find the largest struct.

Pick a medium to large C/C++ program to compile. Good candidates are Apache’s httpd and nginx (or whatever pleases you). Download the source code and tweak its configuration file(s) to set your LLVM compiler as the compiler that will compile the target program, and of course, run your passes on the program to see what you can get.