Book description
Over 80 engaging recipes that will help you build a compiler frontend, optimizer, and code generator using LLVM
Write a frontend for any language to generate LLVM IR
Create optimization passes to optimize the IR code using LLVM Pass Infrastructure and Pass Manager
Design and implement structures for highly-optimized compilers using LLVM, through detailed step-by-step recipes
In Detail
LLVM is a compiler framework with libraries that provides a modern source-and target-independent optimizer, along with a code generator.
This book not only explains the effective use of the compiler infrastructure that LLVM provides, but also helps you implement it in one of your projects. You start with a simple task to get you up-and-running with LLVM, followed by learning the process of writing a frontend for a language, which includes writing a lexer, a parser, and generating IR code. You will then see how to implement optimizations at different levels, generate target-independent code, and then map this generated code to a backend. Finally, you will look into the functionalities that the LLVM infrastructure provides, such as exception handling, LLVM Utility Passes, using sanitizers, the garbage collector, and how we can use these in our projects.
Table of contents
-
LLVM Cookbook
- Table of Contents
- LLVM Cookbook
- Credits
- About the Authors
- About the Reviewers
- www.PacktPub.com
- Preface
-
1. LLVM Design and Use
- Introduction
- Understanding modular design
- Cross-compiling Clang/LLVM
- Converting a C source code to LLVM assembly
- Converting IR to LLVM bitcode
- Converting LLVM bitcode to target machine assembly
- Converting LLVM bitcode back to LLVM assembly
- Transforming LLVM IR
- Linking LLVM bitcode
- Executing LLVM bitcode
- Using the C frontend Clang
- Using the GO frontend
- Using DragonEgg
-
2. Steps in Writing a Frontend
- Introduction
- Defining a TOY language
- Implementing a lexer
- Defining Abstract Syntax Tree
- Implementing a parser
- Parsing simple expressions
- Parsing binary expressions
- Invoking a driver for parsing
- Running lexer and parser on our TOY language
- Defining IR code generation methods for each AST class
- Generating IR code for expressions
- Generating IR code for functions
- Adding IR optimization support
- 3. Extending the Frontend and Adding JIT Support
- 4. Preparing Optimizations
- 5. Implementing Optimizations
-
6. Target-independent Code Generator
- Introduction
- The life of an LLVM IR instruction
- Visualizing LLVM IR CFG using GraphViz
- Describing targets using TableGen
- Defining an instruction set
- Adding a machine code descriptor
- Implementing the MachineInstrBuilder class
- Implementing the MachineBasicBlock class
- Implementing the MachineFunction class
- Writing an instruction selector
- Legalizing SelectionDAG
- Optimizing SelectionDAG
- Selecting instruction from the DAG
- Scheduling instructions in SelectionDAG
- 7. Optimizing the Machine Code
- 8. Writing an LLVM Backend
- 9. Using LLVM for Various Useful Projects
- Index
Product information
- Title: LLVM Cookbook
- Author(s):
- Release date: May 2015
- Publisher(s): Packt Publishing
- ISBN: 9781785285981
You might also like
book
CMake Cookbook
Learn CMake through a series of task-based recipes that provide you with practical, simple, and ready-to-use …
book
C++ Cookbook
Despite its highly adaptable and flexible nature, C++ is also one of the more complex programming …
book
LLVM Techniques, Tips, and Best Practices Clang and Middle-End Libraries
Learn how you can build the next big programming language, compiler, or source code analyzer using …
book
C++20 STL Cookbook
Proven techniques to improve the efficiency of your programs using the Standard Template Library (STL) Key …