[LLVMdev] Implementing a complicated VAARG

Andrew Lenharth
Tue, 03 Apr 2007 19:19:37 -0000

On 4/3/07, Nicolas Geoffray <nicolas.geoffray at lip6.fr>
wrote:
> A VAARG call requires a lot of computation. Typically the C code for
> va_arg(ap, int)
> is:
>
> int va_arg_gpr(ap_list ap) {
>     int idx = ap->gpr;
>     if (idx < 8) {
>         ap->gpr = idx + 1;
>         return ap->reg_save_area[idx];
>     }
>     else {
>       int res = ap->overflow_arg_area[0];
>       ap->gpr = idx + 1;
>       ap->overflow_arg_area += 4;
>       return res;
>     }
> }

This isn't much more (any more?) complex than Alpha's vaargs.  You can
do it without introducing any new branches with some selects and
generate DAG code directly.

Andrew