[LLVMdev] code generation for variadic function

Eli Friedman eli.friedman at gmail.com
Thu Jul 14 11:34:21 PDT 2011


On Thu, Jul 14, 2011 at 11:20 AM, Ankit Sethia <asethia at eecs.umich.edu> wrote:
> Hi All,
>
> I am trying to understand how a back-end generates code for a function that
> has variable number of arguments. I would also to like to know  what changes
> do i have to do to the corresponding ISAs InstrInfo.td when a call to such a
> function is made? Any pointers or documentation in this regard is greatly
> appreciated.

Usually, calling a variadic function doesn't require doing anything
special; you can use CCIfNotVarArg etc. in the CallingConv.td for most
of that sort of thing, although a few targets require doing a bit more
(like x86-64 requires setting AL depending on the number of FP
registers used by the call).

For defining a vararg function, you'll probably need to mess with the
frontend hooks for va_arg (lib/CodeGen/TargetInfo.cpp for clang), and
you'll need to implement custom hooks for ISD::VASTART.  Beyond that,
it's very dependent on how your target actually defines the constructs
in question.

-Eli




More information about the llvm-dev mailing list