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:

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.