
LLVM Code Generation: A deep dive into compiler backend development
Author(s): Quentin Colombet (Author)
- Publisher: Packt Publishing
- Publication Date: 23 May 2025
- Language: English
- Print length: 608 pages
- ISBN-10: 1837637784
- ISBN-13: 9781837637782
Book Description
“If you’re working in or interested in LLVM and code generation, this book should definitely be on your list. Highly recommended!” -Yacob (Kobi) Cohen Arazi, Software Engineer at NVIDIA.
“If you’re passionate about compilers and eager to stay ahead in this dynamic field, I highly recommend giving this book a read.” -Arya Mazaheri, Co-founder of PanocularAI
“I think that this book will lower the access barrier to LLVM significantly and very quickly be on the desks of compiler engineers and students.” -Sebastian Hac, Professor (Compilers) at Saarland University
Key Features
- Understand the steps involved in generating assembly code from LLVM IR
- Learn the key constructs needed to leverage LLVM for your hardware or backend
- Strengthen your understanding with targeted exercises and practical examples in every chapter
Book Description
The LLVM infrastructure is a popular compiler ecosystem widely used in the tech industry and academia. This technology is crucial for both experienced and aspiring compiler developers looking to make an impact in the field. Written by Quentin Colombet, a veteran LLVM contributor and architect of the GlobalISel framework, this book provides a primer on the main aspects of LLVM, with an emphasis on its backend infrastructure; that is, everything needed to transform the intermediate representation (IR) produced by frontends like Clang into assembly code and object files.
You’ll learn how to write an optimizing code generator for a toy backend in LLVM. The chapters will guide you step by step through building this backend while exploring key concepts, such as the ABI, cost model, and register allocation. You’ll also find out how to express these concepts using LLVM’s existing infrastructure and how established backends address these challenges.
By the end of this book, you’ll have gained a deeper understanding of LLVM. The concepts presented are expected to remain stable across different LLVM versions, making this book a reliable quick reference guide for understanding LLVM.
What you will learn
- Understand essential compiler concepts, such as SSA, dominance, and ABI
- Build and extend LLVM backends for creating custom compiler features
- Optimize code by manipulating LLVM’s Intermediate Representation
- Contribute effectively to LLVM open-source projects and development
- Develop debugging skills for LLVM optimizations and passes
Who this book is for
This book is for both beginners to LLVM and experienced LLVM developers. If you’re new to LLVM, it offers a clear, approachable guide to compiler backends, starting with foundational concepts. For seasoned LLVM developers, it dives into less-documented areas such as TableGen, MachineIR, and MC, enabling you to solve complex problems and expand your expertise. Whether you’re starting out or looking to deepen your knowledge, this book has something for you.
Table of Contents
- Building LLVM and Understanding the Directory Structure
- Contributing to LLVM
- Compiler Basics and How They Map to LLVM APIs
- Writing Your First Optimization
- Dealing with Pass Managers
- TableGen – LLVM Swiss Army Knife for Modeling
- Understanding LLVM IR
- Survey of the Existing Passes
- Introducing Target-Specific Constructs
- Hands-On Debugging LLVM IR Passes
- Legacy Instruction Selection Framework – SelectionDAG
- Getting Started with the Machine Code Layer
- The Machine Pass Pipeline
- Getting Started with Instruction Selection
- Instruction Selection: The IR Building Phase
- Instruction Selection: The Legalization Phase
Editorial Reviews
Review
“I found it to be an incredibly thorough guide. It truly covers the A to Z of LLVM code generation – from the initial toolchain setup to producing tangible results, including detailed explanations of the lowering process, all its stages, and crucial terminology.
One of the things that impressed me is that the book doesn’t assume deep prior knowledge. It breaks down every process, even the setup of the toolchain and CMake, making it accessible. It’s a substantial read at over 600 pages, but it’s densely packed with clear examples, well-drawn diagrams, and illustrations that really help in understanding complex topics. It demonstrates various concepts and options in an easy-to-follow manner. The exercises at the end of each chapter are a thoughtful addition, allowing readers to solidify their understanding. This is a great, modern, and very up-to-date resource. I believe many in the compiler development community will find it extremely useful. If you’re working in or interested in LLVM and code generation, this book should definitely be on your list. Highly recommended!”
Yacob (Kobi) Cohen Arazi, Software Engineer at NVIDIA , Running San Diego C++ Meetup
“[….]This book demystifies the complexities of LLVM by systematically introducing the full spectrum of compiler development using LLVM, from setting up and understanding LLVM’s structure and IR to advanced backend optimization techniques and code generation for target architectures. IMHO, the lessons from this book offer actionable insights for generating efficient code, which is especially relevant for deploying AI models on edge devices. Kudos to Quentin Colombet for crafting such an invaluable resource that benefits beginner to experienced compiler enthusiasts. If you’re passionate about compilers and eager to stay ahead in this dynamic field, I highly recommend giving this book a read.”
Arya Mazaheri, Co-founder of PanocularAI
“A long term LLVM professional and contributor, Quentin has created an impressive book that covers all the important concepts for anyone who wants to get started with LLVM as well as for existing users looking to get into corners of LLVM they are not yet acquainted with. He not only discusses important background concepts from compiler theory and shows how they are implemented and put into practice in LLVM, but he also provides step-by-step guidance to the practical aspects of using LLVM. I think that this book will lower the access barrier to LLVM significantly and very quickly be on the desks of compiler engineers and students. I will definitely recommend it to my students and put it on the reading list of my course.”
Sebastian Hac, Professor (Compilers) at Saarland University
About the Author
Quentin Colombet is a veteran LLVM contributor specializing in compiler backends. He is the architect of the new instruction selection framework (GlobalISel) and code owner of the LLVM register allocators. With over two decades of experience, he has worked on compiler backends for a variety of architectures, including GPU, CPU, microcontrollers, DSP, and ASICs. Quentin joined Apple in 2012 and has contributed to x86, Aarch64, and Apple GPU backends. He is passionate about helping newcomers onboard the LLVM infrastructure, having mentored interns and new hires over the years.
Wow! eBook


