Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
LLVM Cookbook

You're reading from   LLVM Cookbook Over 80 engaging recipes that will help you build a compiler frontend, optimizer, and code generator using LLVM

Arrow left icon
Product type Paperback
Published in May 2015
Publisher
ISBN-13 9781785285981
Length 296 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (11) Chapters Close

Preface 1. LLVM Design and Use FREE CHAPTER 2. Steps in Writing a Frontend 3. Extending the Frontend and Adding JIT Support 4. Preparing Optimizations 5. Implementing Optimizations 6. Target-independent Code Generator 7. Optimizing the Machine Code 8. Writing an LLVM Backend 9. Using LLVM for Various Useful Projects Index

Defining registers and registers sets


This recipe shows you how to define registers and register sets in .td files. The tablegen function will convert this .td file into .inc files, which will be the #include declarative in our .cpp files and refer to registers.

Getting ready

We have defined our toy target machine to have four registers (r0-r3), a stack register (sp), and a link register (lr). These can be specified in the TOYRegisterInfo.td file. The tablegen function provides the Register class, which can be extended to specify the registers.

How to do it…

To define the backend architecture using target descriptor files, proceed with the following steps.

  1. Create a new folder in lib/Target named TOY:

    $ mkdir llvm_root_directory/lib/Target/TOY
    
  2. Create a new TOYRegisterInfo.td file in the new TOY folder:

    $ cd llvm_root_directory/lib/Target/TOY
    $ vi TOYRegisterInfo.td
    
  3. Define the hardware encoding, namespace, registers, and the register class:

    class TOYReg<bits<16> Enc, string n> : Register...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime