[LLVMdev] Is va_arg deprecated?

David Meyer pdox at google.com
Mon Jul 19 14:18:47 PDT 2010


Neal,

FYI, my group has added a flag to llvm-gcc for emitting the va_arg
instruction (instead of lowering in the front-end),
and we also have an implementation of the VAARG instruction for
X86-64. (which is currently not implemented in the LLVM backend).

Both of these things will be sent upstream to LLVM soon, pending some
more testing and review.

If you are dire need of these features now, I can point you to the
(public) repository where we have the beta versions.

- David M


On Mon, Jul 19, 2010 at 11:57 AM, Neal  N. Wang <neal.wang at gmail.com> wrote:
> Hi folk,
>
> I'm writing a set of small C code to verify whether my pass handle some
> instruction correctly.   One of the instruction I want to test is "va_arg",
> but compiling my variadic function does not generate any va_arg instruction.
> Is va_arg deprecated? Will va_arg instruction ever be generated by any
> front-end?  The source code and llvm instructions are appended as follows.
>
> the c code
> #include<stdarg.h>
> #include<stdio.h>
> #include<stdlib.h>
>
> void printValue(char * fmt, ...) {
>   va_list args;
>   va_start(args, fmt);
>   int i;
>   double d;
>   i = va_arg(args, int);
>   d = va_arg(args, double);
>   va_end(args);
> }
>
> the generated llvm instructions:
> ; ModuleID = 'i.bc'
> target datalayout =
> "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
> target triple = "i386-pc-linux-gnu"
>
> define void @printValue(i8* %fmt, ...) nounwind {
> entry:
>   %fmt_addr = alloca i8*                          ; <i8**> [#uses=1]
>   %args.2 = alloca i8*                            ; <i8**> [#uses=3]
>   %args.0 = alloca i8*                            ; <i8**> [#uses=3]
>   %args = alloca i8*                              ; <i8**> [#uses=6]
>   %i = alloca i32                                 ; <i32*> [#uses=1]
>   %d = alloca double, align 8                     ; <double*> [#uses=1]
>   %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
>   store i8* %fmt, i8** %fmt_addr
>   %args1 = bitcast i8** %args to i8*              ; <i8*> [#uses=1]
>   call void @llvm.va_start(i8* %args1)
>   %0 = load i8** %args, align 4                   ; <i8*> [#uses=1]
>   store i8* %0, i8** %args.0, align 4
>   %1 = load i8** %args.0, align 4                 ; <i8*> [#uses=1]
>   %2 = getelementptr inbounds i8* %1, i64 4       ; <i8*> [#uses=1]
>   store i8* %2, i8** %args, align 4
>   %3 = load i8** %args.0, align 4                 ; <i8*> [#uses=1]
>   %4 = bitcast i8* %3 to i32*                     ; <i32*> [#uses=1]
>   %5 = load i32* %4, align 4                      ; <i32> [#uses=1]
>   store i32 %5, i32* %i, align 4
>   %6 = load i8** %args, align 4                   ; <i8*> [#uses=1]
>   store i8* %6, i8** %args.2, align 4
>   %7 = load i8** %args.2, align 4                 ; <i8*> [#uses=1]
>   %8 = getelementptr inbounds i8* %7, i64 8       ; <i8*> [#uses=1]
>   store i8* %8, i8** %args, align 4
>   %9 = load i8** %args.2, align 4                 ; <i8*> [#uses=1]
>   %10 = bitcast i8* %9 to double*                 ; <double*> [#uses=1]
>   %11 = load double* %10, align 4                 ; <double> [#uses=1]
>   store double %11, double* %d, align 8
>   %args2 = bitcast i8** %args to i8*              ; <i8*> [#uses=1]
>   call void @llvm.va_end(i8* %args2)
>   br label %return
>
> return:                                           ; preds = %entry
>   ret void
> }
>
> declare void @llvm.va_start(i8*) nounwind
>
> declare void @llvm.va_end(i8*) nounwind
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>




More information about the llvm-dev mailing list