Front cover image for LLVM Cookbook

LLVM Cookbook

The book is for compiler programmers who are familiar with concepts of compilers and want to indulge in understanding, exploring, and using LLVM infrastructure in a meaningful way in their work. This book is also for programmers who are not directly involved in compiler projects but are often involved in development phases where they write thousands of lines of code. With knowledge of how compilers work, they will be able to code in an optimal way and improve performance with clean code
eBook, English, 2015
Packt Publishing, Birmingham, 2015
Online-Ressource (296 Seiten)
9781785285981, 178528598X
1020552369
Cover; Copyright; Credits; About the Authors; About the Reviewers; www.PacktPub.com; Table of Contents; Preface; Chapter 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; Chapter 2: Steps in Writing a Frontend; Introduction. Defining a TOY languageImplementing 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; Chapter 3: Extending the Frontend and Adding JIT Support; Introduction; Handling decision making paradigms
if/then/else constructs; Generating code for loops. Handling user-defined operators
binary operatorsHandling user-defined operators
unary operators; Adding JIT support; Chapter 4: Preparing Optimizations; Introduction; Various levels of optimization; Writing your own LLVM pass; Running your own pass with the opt tool; Using another pass in a new pass; Registering a pass with pass manager; Writing an analysis pass; Writing an alias analysis pass; Using other analysis passes; Chapter 5: Implementing Optimizations; Introduction; Writing a dead code elimination pass; Writing an inlining transformation pass. Writing a pass for memory optimizationCombining LLVM IR; Transforming and optimizing loops; Reassociating expressions; Vectorizing IR; Other optimization passes; Chapter 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 SelectionDAGSelecting instruction from the DAG; Scheduling instructions in SelectionDAG; Chapter 7: Optimizing the Machine Code; Introduction; Eliminating common subexpression from machine code; Analyzing live intervals; Allocating registers; Inserting the prologue-epilogue code; Code emission; Tail call optimization; Sibling call optimisation; Chapter 8: Writing an LLVM Backend; Introduction; Defining registers and registers sets; Defining the calling convention; Defining the instruction set; Implementing frame lowering; Printing an instruction; Selecting an instruction
IMD-Felder maschinell generiert
Adding instruction encoding