[LLVMdev] Implementing a complicated VAARG

Chris Lattner
Tue, 03 Apr 2007 18:38:13 -0000

On Tue, 3 Apr 2007, Nicolas Geoffray wrote:
> A VAARG call requires a lot of computation. Typically the C code for
> va_arg(ap, int)

If you use va_arg in C, are you seeing llvm.vaarg in the output .ll file?

-Chris

> 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;
>    }
> }
>
> Actually, all VAARG implementations for other backends use DAGs, but
> this may be
> too complicated to do for ELF32.
>
> What would you suggest to code the VAARG instruction efficiently?
> Should I code va_arg_gpr with DAGs (many lines of code) or should I
> create a DAG that will
> call the C method va_arg_gpr (Btw, i do not know how to do this ;))?
>
> Thanks for your help!
>
> Best,
> Nicolas
>
>
>  // For ELF 32 ABI we follow the layout of the va_list struct.
>  // We suppose the given va_list is already allocated.
>  //
>  // typedef struct {
>  //  char gpr;     /* index into the array of 8 GPRs
>  //                 * stored in the register save area
>  //                 * gpr=0 corresponds to r3,
>  //                 * gpr=1 to r4, etc.
>  //                 */
>  //  char fpr;     /* index into the array of 8 FPRs
>  //                 * stored in the register save area
>  //                 * fpr=0 corresponds to f1,
>  //                 * fpr=1 to f2, etc.
>  //                 */
>  //  char *overflow_arg_area;
>  //                /* location on stack that holds
>  //                 * the next overflow argument
>  //                 */
>  //  char *reg_save_area;
>  //               /* where r3:r10 and f1:f8 (if saved)
>  //                * are stored
>  //                */
>  // } va_list[1];
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>

-Chris

--