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

Adding instruction encoding


If the instructions need to be specific for how they are encoded with respect to bit fields, this can be done by specifying the bit field in the .td file when defining an instruction.

How to do it…

To include instruction encoding while defining instructions, proceed with the following steps:

  1. A register operand that will be used to register the add instruction will have some defined encoding for its instruction. The size of the instruction is 32 bits, and the encoding for it is as follows:

    bits 0 to 3 -> src2, second register operand
    bits 4 to 11 -> all zeros
    bits 12 to 15 -> dst, for destination register
    bits 16 to 19 -> src1, first register operand
    bit 20 -> zero
    bit 21 to 24 -> for opcode
    bit 25 to 27 -> all zeros
    bit 28 to 31 -> 1110

    This can be achieved by specifying the preceding bit pattern in the .td files

  2. In the TOYInstrFormats.td file, define a new variable, called Inst:

    class InstTOY<dag outs, dag ins, string asmstr, list<dag&gt...
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