Getting Started with LLVM Core Libraries
eBook - ePub

Getting Started with LLVM Core Libraries

Bruno Cardoso Lopes, Rafael Auler

Share book
  1. 314 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Getting Started with LLVM Core Libraries

Bruno Cardoso Lopes, Rafael Auler

Book details
Book preview
Table of contents
Citations

About This Book

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.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Getting Started with LLVM Core Libraries an online PDF/ePUB?
Yes, you can access Getting Started with LLVM Core Libraries by Bruno Cardoso Lopes, Rafael Auler in PDF and/or ePUB format, as well as other popular books in Ciencia de la computación & Programación en C++. We have over one million books available in our catalogue for you to explore.

Information

Year
2014
ISBN
9781782166924

Getting Started with LLVM Core Libraries


Table of Contents

Getting Started with LLVM Core Libraries
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Build and Install LLVM
Understanding LLVM versions
Obtaining prebuilt packages
Obtaining the official prebuilt binaries
Using package managers
Staying updated with snapshot packages
Linux
Windows
Building from sources
System requirements
Obtaining sources
SVN
Git
Building and installing LLVM
Using the autotools-generated configure script
Building and configuring with Unix
Using CMake and Ninja
Building with Unix using CMake and Ninja
Solving build errors
Using other Unix approaches
Windows and Microsoft Visual Studio
Mac OS X and Xcode
Summary
2. External Projects
Introducing Clang extras
Building and installing Clang extra tools
Understanding Compiler-RT
Seeing Compiler-RT in action
Using the DragonEgg plugin
Building DragonEgg
Understanding the compilation pipeline with DragonEgg and LLVM tools
Understanding the LLVM test suite
Using LLDB
Exercising a debug session with LLDB
Introducing the libc++ standard library
Summary
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
Getting to know LLVM's basic libraries
Introducing LLVM's C++ practices
Seeing polymorphism in practice
Introducing C++ templates in LLVM
Enforcing C++ best practices in LLVM
Making string references lightweight in LLVM
Demonstrating the pluggable pass interface
Writing your first LLVM project
Writing the Makefile
Writing the code
Navigating the LLVM source – general advice
Understanding the code as a documentation
Asking the community for help
Coping with updates – using the SVN log as a documentation
Concluding remarks
Summary
4. The Frontend
Introducing Clang
Frontend actions
Libraries
Using libclang
Understanding Clang diagnostics
Reading diagnostics
Learning the frontend phases with Clang
Lexical analysis
Exercising lexical errors
Writing libclang code that uses the lexer
Preprocessing
Syntactic analysis
Understanding Clang AST nodes
Understanding the parser actions with a debugger
Exercising a parser error
Writing code that traverses the Clang AST
Serializing the AST with precompiled headers
Semantic analysis
Exercising a semantic error
Generating the LLVM IR code
Putting it together
Summary
5. The LLVM Intermediate Representation
Overview
Understanding the LLVM IR target dependency
Exercising basic tools to manipulate the IR formats
Introducing the LLVM IR language syntax
Introducing the LLVM IR in-memory model
Writing a custom LLVM IR generator
Building and running the IR generator
Learning how to write code to generate any IR construct with the C++ backend
Optimizing at the IR level
Compile-time and link-time optimizations
Discovering which passes matter
Understanding pass dependencies
Understanding the pass API
Writing a custom pass
Building and running your new pass with the LLVM build system
Building and running your new pass with your own Makefile
Summary
6. The Backend
Overview
Using the backend tools
Learning the backend code structure
Knowing the backend libraries
Learning how to use TableGen for LLVM backends
The language
Knowing the code generator .td files
Target properties
Registers
Instructions
Understanding the instruction selection phase
The SelectionDAG class
Lowering
DAG combine and legalization
DAG-to-DAG instruction selection
Pattern matching
Visualizing the instruction selection process
Fast instruction selection
Scheduler
Instruction itineraries
Hazard detection
Scheduling units
Machine instructions
Register allocation
Register coalescer
Virtual register rewrite
Target hooks
Prologue and epilogue
Frame indexes
Understanding the machine code framework
MC instructions
Code emission
Writing your own machine pass
Summary
7. The Just-in-Time Compiler
Getting to know the LLVM JIT engine basics
Introducing the execution engine
Memory management
Introducing the llvm::JIT framework
Writing blobs to memory
Using JITMemoryManager
Target code emitters
Target information
Learning how to use the JIT class
The generic value
Introducing the llvm::MCJIT framework
The MCJIT engine
Learning the module's states
Understanding how MCJIT compiles modules
The Object buffer, the cache, and the image
Dynamic linking
The memory manager
The MC code emission
Object finalization
Using the MCJIT engine
Using LLVM JIT compilation tools
Using the lli tool
Using the llvm-rtdyld tool
Other resources
Summary
8. Cross-platform Compilation
Comparing GCC and LLVM
Understanding target triples
Preparing your toolchain
Standard C and C++ libraries
Runtime libraries
The assembler and the linker
The Clang frontend
Multilib
Cross-compiling with Clang command-line arguments
Driver options for the target
Dependencies
Cross-compiling
Installing GCC
Potential problems
Changing the system root
Generating a Clang cross-compiler
Configuration options
Building and installing your Clang-based cross-compiler
Alternative build methods
Ninja
ELLCC
EmbToolkit
Testing
Development boards
Simulators
Additional resources
Summary
9. The Clang Static Analyzer
Understanding the role of a static analyzer
Comparing classic warnings versus the Clang Static Analyzer
The power of the symbolic execution engine
Testing the static analyzer
Using the driver versus using the compiler
Getting to know the available checkers
Using the static analyzer in the Xcode IDE
Generating graphical reports in HTML
Handling large projects
A real-world example – finding bugs in Apache
Extending the static analyzer with your own checkers
Getting familiar with the project architecture
Writing your own checker
Solving the problem with a custom checker
Writing the state class
Understanding ProgramState immutability
Dissecting the code
Defining the Checker subclass
Writing the Register macro
Implem...

Table of contents