My two main resources when learning about LLVM Passes were:
- llvm-tutor - this project is a pedagogical gem when it comes to writing LLVM Passes. It has both detailed setup instructions and a solid collection of LLVM Passes that illustrate key concepts - and are all excellently documented. I’d recommend that anyone who wants to learn more about LLVM Passes - or even just LLVM in general - start here
- LLVM Essentials - this book contains some in-depth explanations on the surrounding LLVM infrastructure, and I found many of its code samples extremely useful when implementing my own pass
Some other helpful resources from https://llvm.org/ that I found useful:
- Getting Started with the LLVM System - this page
contains useful information on how to compile LLVM
- This answer on Stackoverflow came in handy when compiling LLVM - it turns out that compiling LLVM consumes ridiculous amounts of memory, this answer has some tips for dealing with this
- Writing an LLVM Pass - this page is
substantially less detailed than
llvm-tutor
, but still has some nice documentation and code samples. - LLVM’s Analysis and Transform Passes - this page has an awesome collection of existing LLVM Passes
Setup
I worked on an Ubuntu 20.04 machine running in EC2. Some resources call for compiling LLVM manually - and whilst I did end up doing this for another project, this is often overkill and has a lot of pitfalls.
The standard LLVM toolchain works just fine for most LLVM Pass development purposes - just using
tools likeclang
and opt
directly from an installation like:
sudo apt-get install -y llvm-13 llvm-13-dev llvm-13-tools clang-13
The next page has more details on writing LLVM Pass boilerplate
code - most of the boilerplate is based off
of llvm-tutor
.