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 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...