Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
LLVM Code Generation

You're reading from   LLVM Code Generation A deep dive into compiler backend development

Arrow left icon
Product type Paperback
Published in May 2025
Publisher Packt
ISBN-13 9781837637782
Length 620 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Quentin Colombet Quentin Colombet
Author Profile Icon Quentin Colombet
Quentin Colombet
Arrow right icon
View More author details
Toc

Table of Contents (30) Chapters Close

Preface 1. Part 1: Getting Started with LLVM
2. Building LLVM and Understanding the Directory Structure FREE CHAPTER 3. Contributing to LLVM 4. Compiler Basics and How They Map to LLVM APIs 5. Writing Your First Optimization 6. Dealing with Pass Managers 7. TableGen – LLVM Swiss Army Knife for Modeling 8. Part 2: Middle-End: LLVM IR to LLVM IR
9. Understanding LLVM IR 10. Survey of the Existing Passes 11. Introducing Target-Specific Constructs 12. Hands-On Debugging LLVM IR Passes 13. Part 3: Introduction to the Backend
14. Getting Started with the Backend 15. Getting Started with the Machine Code Layer 16. The Machine Pass Pipeline 17. Part 4: LLVM IR to Machine IR
18. Getting Started with Instruction Selection 19. Instruction Selection: The IR Building Phase 20. Instruction Selection: The Legalization Phase 21. Instruction Selection: The Selection Phase and Beyond 22. Part 5: Final Lowering and Optimizations
23. Instruction Scheduling 24. Register Allocation 25. Lowering of the Stack Layout 26. Getting Started with the Assembler 27. Unlock Your Book’s Exclusive Benefits 28. Other Books You May Enjoy
29. Index

To get the most out of this book

The chapters are self-contained and, aside from the compiler concepts introduced in Chapters 3 and 4, you should be able to jump to any of them and get started. If you are new to the codegen space, we still recommend that you follow the chapters in order as they follow the natural flow of a compiler backend from the input IR progressively lowering it to assembly code. If you are new to compilers, we still recommend that you read at least Chapters 3 and 4 first.

For people with a compiler background but new to backends or wanting to refresh or refine their knowledge of the backends, you can use the Quiz time sections at the end of each chapter to first check your knowledge against what the chapter covers to decide whether the chapter may cover something that you may not know before reading it.

Finally, we are firm believers that practicing something helps to digest it; therefore, we recommend you spend time doing the coding exercises and implement your own solutions without looking at the provided solutions.

Software covered in the book

Operating system requirements

LLVM 20

Windows, macOS, or Linux

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Note that the code snippets and APIs are based on the open source release of LLVM 20.1.1 from February 2025. All the code has been tested solely on macOS but should work equally well on Windows and Linux. The code snippets are also available for the LLVM 19.0.1 release from September 2024 in the release_llvm_19_0_1 branch of the repositories listed in the next section.

Download the example code files

You can download the example code files and exercises for this book from GitHub at https://github.com/PacktPublishing/LLVM-Code-Generation. If there’s an update to the code, it will be updated in the GitHub repository. Additionally, the book comes with a second companion repository at https://github.com/PacktPublishing/LLVM-Code-Generation-by-example. This is a fork of LLVM that is used throughout the book to illustrate how to develop a full backend.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://packt.link/gbp/9781837637782.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and X/Twitter handles. Here is an example: “Since the SDISel framework is a single MachineFunctionPass instance, the only way to augment it is through the hooks provided by the various TargetXXX classes of your backend.”

A block of code is set as follows:

SelectionDAG has 9 nodes:
  t0: ch,glue = EntryToken
      t2: i16,ch = CopyFromReg t0, Register:i16 %0
      t4: i16,ch = CopyFromReg t0, Register:i16 %1
    t5: i16 = add t2, t4
  t7: ch,glue = CopyToReg t0, Register:i16 $r1, t5
  t8: ch = H2BLBISD::RETURN_GLUE t7, Register:i16 $r1, t7:1

Warnings or important notes appear like this.

Tips and tricks appear like this.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime