Professional Documents
Culture Documents
Full Chapter Learn LLVM 17 A Beginners Guide To Learning LLVM Compiler Tools and Core Libraries With C 2Nd Edition Anonymous PDF
Full Chapter Learn LLVM 17 A Beginners Guide To Learning LLVM Compiler Tools and Core Libraries With C 2Nd Edition Anonymous PDF
https://textbookfull.com/product/primary-mathematics-
textbook-2b-jennifer-hoerst/
https://textbookfull.com/product/entrepreneurship-innovation-and-
technology-a-guide-to-core-models-and-tools-2nd-edition-lorenzo/
https://textbookfull.com/product/handbook-of-macroeconomics-
volume-2a-2b-set-1st-edition-john-b-taylor/
https://textbookfull.com/product/zero-to-maker-a-beginner-s-
guide-to-the-skills-tools-and-ideas-of-the-maker-movement-2nd-
edition-david-lang/
Learn Python Programming A beginner s guide to learning
the fundamentals of Python language to write efficient
high quality code Romano
https://textbookfull.com/product/learn-python-programming-a-
beginner-s-guide-to-learning-the-fundamentals-of-python-language-
to-write-efficient-high-quality-code-romano/
https://textbookfull.com/product/hands-on-machine-learning-with-
scikit-learn-keras-and-tensorflow-concepts-tools-and-techniques-
to-build-intelligent-systems-2nd-edition-aurelien-geron-geron/
https://textbookfull.com/product/learn-electronics-with-arduino-
an-illustrated-beginner-s-guide-to-physical-computing-1st-
edition-jody-culkin/
https://textbookfull.com/product/the-ultimate-beginner-s-guide-
to-learn-kotlin-programming-step-by-step-2020-2nd-edition-moaml-
mohmmed/
https://textbookfull.com/product/php-and-algorithmic-thinking-
for-the-complete-beginner-2nd-edition-learn-to-think-like-a-
programmer-bouras/
Learn LLVM 17
Copyright © 2024 Packt Publishing
All rights reserved. No part of this book may be
reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without
the prior written permission of the publisher, except
in the case of brief quotations embedded in critical
articles or reviews.
Every effort has been made in the preparation of this
book to ensure the accuracy of the information
presented. However, the information contained in
this book is sold without warranty, either express or
implied. Neither the authors, nor Packt Publishing or
its dealers and distributors, will be held liable for any
damages caused or alleged to have been caused
directly or indirectly by this book.
Packt Publishing has endeavored to provide
trademark information about all of the companies
and products mentioned in this book by the
appropriate use of capitals. However, Packt
Publishing cannot guarantee the accuracy of this
information.
Group Product Manager: Kunal Sawant
Publishing Product Manager: Teny Thomas
Book Project Manager: Prajakta Naik
Senior Editor: Ruvika Rao and Nithya Sadanandan
Technical Editor: Jubit Pincy
Copy Editor: Safis Editing
Indexer: Pratik Shirodkar
Production Designer: Vijay Kamble
DevRel Marketing Coordinator: Shrinidhi
Manoharan
Business Development Executive: Kriti Sharma
First published: April 2021
Second published: January 2024
Production reference: 1271223
Published by Packt Publishing Ltd.
Grosvenor House
11 St Paul’s Square
Birmingham
B3 1R.
ISBN 978-1-83763-134-6
www.packtpub.com
Writing a book takes time and energy. Without
the support and understanding of my wife, Tanya,
and my daughter Polina, this book would not
have been possible. Thank you both for always
encouraging me!
Because of some personal challenges, this project
was at risk, and I am grateful to Amy for joining
me as an author. Without her, the book would not
be as good as it is now.
Once again, the team at Packt not only provided
guidance on my writing but also showed an
understanding of my slow writing, and always
motivated me to carry on. I owe them a great
thank you.
- Kai Nacke
2023 has been a very transformative year for me,
and contributing my knowledge of LLVM to this
book has been one of the reasons why this year
has been so significant. I never would have
thought that I would be approached by Kai to
embark on this exciting journey to share LLVM 17
with you all! Thank you to Kai, for his technical
mentorship and guidance, the team at Packt,
and, of course, to my family and close loved ones
for providing me with the support and motivation
in writing this book.
- Amy Kwan
Contributors
Preface
Part 1: The Basics of Compiler
Construction with LLVM
Installing LLVM
Compiling LLVM versus installing
binaries
Getting the prerequisites ready
Ubuntu
Fedora and RedHat
FreeBSD
OS X
Windows
Cloning the repository and building from
source
Configuring Git
Cloning the repository
Creating a build directory
Generating the build system files
Compiling and installing LLVM
Customizing the build process
Variables defined by CMake
Using LLVM-defined build configuration
variables
Summary
Advanced IR Generation
Throwing and catching exceptions
Raising an exception
Catching an exception
Integrating the exception handling code
into the application
Generating metadata for type-based
alias analysis
Understanding the need for additional
metadata
Creating TBAA metadata in LLVM
Adding TBAA metadata to tinylang
Adding debug metadata
Understanding the general structure of
debug metadata
Tracking variables and their values
Adding line numbers
Adding debug support to tinylang
Summary
Optimizing IR
Technical requirements
The LLVM pass manager
Implementing a new pass
Developing the ppprofiler pass as a
plugin
Adding the pass to the LLVM source tree
Using the ppprofiler pass with LLVM
tools
Adding an optimization pipeline to your
compiler
Creating an optimization pipeline
Extending the pass pipeline
Summary
Part 3: Taking LLVM to the Next
Level
JIT Compilation
Technical requirements
LLVM’s overall JIT implementation and
use cases
Using JIT compilation for direct
execution
Exploring the lli tool
Implementing our own JIT compiler with
LLJIT
Integrating the LLJIT engine into the
calculator
Code generation changes to support JIT
compilation via LLJIT
Building an LLJIT-based calculator
Building a JIT compiler class from
scratch
Creating a JIT compiler class
Using our new JIT compiler class
Summary
10
11
Instruction Selection
Defining the rules of the calling
convention
Implementing the rules of the calling
convention
Instruction selection via the selection
DAG
Implementing DAG lowering – handling
legal types and setting operations
Implementing DAG lowering – lowering
formal arguments
Implementing DAG lowering – lowering
return values
Implementing DAG-to-DAG
transformations within instruction
selection
Adding register and instruction
information
Putting an empty frame lowering in
place
Emitting machine instructions
Creating the target machine and the
sub-target
Implementing M88kSubtarget
Implementing M88kTargetMachine –
defining the definitions
Implementing M88kTargetMachine –
adding the implementation
Global instruction selection
Lowering arguments and return values
Legalizing the generic machine
instructions
Selecting a register bank for operands
Translating generic machine instructions
Running an example
How to further evolve the backend
Summary
13
Index