Getting Started with LLVM Core Libraries

Get to grips with LLVM essentials and use the core libraries to build advanced tools

Getting Started with LLVM Core Libraries

Starting
Bruno Cardoso Lopes, Rafael Auler

Get to grips with LLVM essentials and use the core libraries to build advanced tools
$26.99
$44.99
RRP $26.99
RRP $44.99
eBook
Print + eBook
$12.99 p/month

Want this title & more? Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.
+ Collection
Free Sample

Book Details

ISBN 139781782166924
Paperback314 pages

About This Book

  • Learn how to configure, build, and use LLVM and Clang based tools
  • Explore the depths of the LLVM front-end, IR, code generator, and libraries, and learn how a modern compiler is implemented in a practical way.
  • Customize your project to benefit from Just in Time compilation (JIT), static analysis and source-to-source transformations.

Who This Book Is For

This book is intended for enthusiasts, computer science students, and compiler engineers interested in learning about the LLVM framework. You need a background in C++ and, although not mandatory, should know at least some compiler theory. Whether you are a newcomer or a compiler expert, this book provides a practical introduction to LLVM and avoids complex scenarios. If you are interested enough and excited about this technology, then this book is definitely for you.

Table of Contents

Chapter 1: Build and Install LLVM
Understanding LLVM versions
Obtaining prebuilt packages
Building from sources
Summary
Chapter 2: External Projects
Introducing Clang extras
Using the DragonEgg plugin
Summary
Chapter 3: Tools and Design
Introducing LLVM's basic design principles and its history
Understanding LLVM today
Interacting with the compiler driver
Using standalone tools
Delving into the LLVM internal design
Writing your first LLVM project
Navigating the LLVM source – general advice
Summary
Chapter 4: The Frontend
Introducing Clang
Learning the frontend phases with Clang
Putting it together
Summary
Chapter 5: The LLVM Intermediate Representation
Overview
Exercising basic tools to manipulate the IR formats
Introducing the LLVM IR language syntax
Writing a custom LLVM IR generator
Optimizing at the IR level
Summary
Chapter 6: The Backend
Overview
Learning the backend code structure
Knowing the backend libraries
Learning how to use TableGen for LLVM backends
Understanding the instruction selection phase
Scheduler
Machine instructions
Register allocation
Prologue and epilogue
Understanding the machine code framework
Writing your own machine pass
Summary
Chapter 7: The Just-in-Time Compiler
Getting to know the LLVM JIT engine basics
Introducing the llvm::JIT framework
Introducing the llvm::MCJIT framework
Using LLVM JIT compilation tools
Other resources
Summary
Chapter 8: Cross-platform Compilation
Comparing GCC and LLVM
Understanding target triples
Preparing your toolchain
Cross-compiling with Clang command-line arguments
Generating a Clang cross-compiler
Testing
Additional resources
Summary
Chapter 9: The Clang Static Analyzer
Understanding the role of a static analyzer
Testing the static analyzer
Extending the static analyzer with your own checkers
More resources
Summary
Chapter 10: Clang Tools with LibTooling
Generating a compile command database
The clang-tidy tool
Refactoring tools
Writing your own tool
More resources
Summary

What You Will Learn

  • Configure, build, and install extra LLVM open source projects including Clang tools, static analyzer, Compiler-RT, LLDB, DragonEgg, libc++, and LLVM test-suite
  • Understand the LLVM library design and interaction between libraries and standalone tools
  • Increase your knowledge of source code processing stages by learning how the Clang frontend uses a lexer, parser, and syntax analysis
  • Manipulate, generate, and play with LLVM IR files while writing custom IR analyses and transformation passes
  • Write tools to use LLVM Just-in-Time (JIT) compilation capabilities
  • Find bugs and improve your code by using the static analyzer
  • Design source code analysis and transformation tools using LibClang, LibTooling, and the Clang plugin interface

In Detail

LLVM is a bleeding edge compiler technology framework. Easily extendable and designed as a multitude of libraries, LLVM provides a smooth experience for compiler newcomers and reduces the steep learning curve often associated with compiler development.

To start, this book will show you how to configure, build, and install LLVM libraries, tools, and external projects. Next, you will be introduced to LLVM design and how it works in practice throughout each LLVM compiler stage: frontend, IR, backend, the JIT engine, cross-compilation capabilities, and the plugin interface. With multiple hands-on examples and source code snippets, Getting Started with LLVM Core Libraries ensures a solid and smooth  first step into the LLVM compiler development environment.

Authors

Table of Contents

Chapter 1: Build and Install LLVM
Understanding LLVM versions
Obtaining prebuilt packages
Building from sources
Summary
Chapter 2: External Projects
Introducing Clang extras
Using the DragonEgg plugin
Summary
Chapter 3: Tools and Design
Introducing LLVM's basic design principles and its history
Understanding LLVM today
Interacting with the compiler driver
Using standalone tools
Delving into the LLVM internal design
Writing your first LLVM project
Navigating the LLVM source – general advice
Summary
Chapter 4: The Frontend
Introducing Clang
Learning the frontend phases with Clang
Putting it together
Summary
Chapter 5: The LLVM Intermediate Representation
Overview
Exercising basic tools to manipulate the IR formats
Introducing the LLVM IR language syntax
Writing a custom LLVM IR generator
Optimizing at the IR level
Summary
Chapter 6: The Backend
Overview
Learning the backend code structure
Knowing the backend libraries
Learning how to use TableGen for LLVM backends
Understanding the instruction selection phase
Scheduler
Machine instructions
Register allocation
Prologue and epilogue
Understanding the machine code framework
Writing your own machine pass
Summary
Chapter 7: The Just-in-Time Compiler
Getting to know the LLVM JIT engine basics
Introducing the llvm::JIT framework
Introducing the llvm::MCJIT framework
Using LLVM JIT compilation tools
Other resources
Summary
Chapter 8: Cross-platform Compilation
Comparing GCC and LLVM
Understanding target triples
Preparing your toolchain
Cross-compiling with Clang command-line arguments
Generating a Clang cross-compiler
Testing
Additional resources
Summary
Chapter 9: The Clang Static Analyzer
Understanding the role of a static analyzer
Testing the static analyzer
Extending the static analyzer with your own checkers
More resources
Summary
Chapter 10: Clang Tools with LibTooling
Generating a compile command database
The clang-tidy tool
Refactoring tools
Writing your own tool
More resources
Summary

Book Details

ISBN 139781782166924
Paperback314 pages
Read More