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.
lib/Target
named TOY
:$ mkdir llvm_root_directory/lib/Target/TOY
TOYRegisterInfo.td file
in the new TOY
folder:$ cd llvm_root_directory/lib/Target/TOY $ vi TOYRegisterInfo.td
class TOYReg<bits<16> Enc, string n> : Register<n> { let HWEncoding = Enc; let Namespace = "TOY"; } foreach i = 0-3 in { def R#i : R<i, "r"#i >; } def SP : TOYReg<13, "sp">; def LR : TOYReg<14, "lr">; def GRRegs : RegisterClass<"TOY", [i32], 32, (add R0, R1, R2, R3, SP)>;
3.147.77.208