[LLVMdev] Implementing a complicated VAARG

Chris Lattner sabre at nondot.org
Tue Apr 3 13:03:37 PDT 2007


On Tue, 3 Apr 2007, Nicolas Geoffray wrote:
> I'm guessing that if you're asking, then no llvm.vaarg is generated. I 
> can not test it on my box 'cause llvm-gcc does not compile on Linux/PPC, 
> but the llvm.org online demo does not indeed generate a llvvm.vaarg 
> instruction.

ok

> But this is horribly not portable! The va_arg(ap, int) for Linux/PPC is
> really different
> from Darwin/PPC (see my previous message).

I agree.

> And the .ll file generated by
> llvm-gcc
> can not be executed on Linux/PPC.

Right.

> Btw, I'm using the JIT of llvm, not llvm-gcc, I do not code in C to 
> generate llvm code, but in "MyLanguage". And I want "MyLanguage" to have 
> variadic functions and interoperate with C code.

Ok, if you have a non-C input, implementing llvm.vaarg is important. :)

-Chris

> Cheers,
> Nicolas
>
>> -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
>>
>>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list