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.
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.
To define the backend architecture using target descriptor files, proceed with the following steps.
Create a new folder in
lib/Target
namedTOY
:$ mkdir llvm_root_directory/lib/Target/TOY
Create a new
TOYRegisterInfo.td file
in the newTOY
folder:$ cd llvm_root_directory/lib/Target/TOY $ vi TOYRegisterInfo.td
Define the hardware encoding, namespace, registers, and the register class:
class TOYReg<bits<16> Enc, string n> : Register...