Book Image

LLVM Cookbook

Book Image

LLVM Cookbook

Overview of this book

Table of Contents (16 chapters)
LLVM Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
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...