Defining the calling convention
The calling convention specifies how values are passed to and from a function call. Our TOY architecture specifies that two arguments are passed in two registers, r0 and r1, while the remaining ones are passed to the stack. This recipe shows you how to define the calling convention, which will be used in ISelLowering
(the instruction selection lowering phase discussed in Chapter 6, Target Independent Code Generator) via function pointers.
The calling convention will be defined in the TOYCallingConv.td
file, which will have primarily two sections—one for defining the return value convention, and the other for defining the argument passing convention. The return value convention specifies how the return values will reside and in which registers. The argument passing convention will specify how the arguments passed will reside and in which registers. The CallingConv
class is inherited while defining the calling convention of the toy architecture.
How to do it…
To...