[LLVMdev] Ho to generate VAARG?

Artem Artem.Rudskyy at st.ovgu.de
Thu Apr 1 08:51:18 PDT 2010


Hello, LLVMers!

 

How can I force a front end to generate VAARG for accessing varargs
parameters?

I compile a simple C-code:

 

#include <stdarg.h>

int FnVarArgs(int a, ...)

{

 int i,tmp=0;

 va_list ptArgument;

 va_start(ptArgument,a);

 for(i=0;i<9;i++)

  tmp+= va_arg(ptArgument,int);

 return tmp;

}

 

And then have this bytecode:

 

; ModuleID = 'main.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:6
4-v64:64:64-v128:128:128-a0:0:64-f80:32:32"

target triple = "i386-pc-linux-gnu"

 

define i32 @FnVarArgs(i32 %a, ...) nounwind {

bb2.thread:

            %ptArgument = alloca i8*, align 4                      ; <i8**>
[#uses=3]

            %ptArgument1 = bitcast i8** %ptArgument to i8*
; <i8*> [#uses=1]

            call void @llvm.va_start(i8* %ptArgument1)

            br label %bb2

 

bb2:                 ; preds = %bb2, %bb2.thread

            %i.0.reg2mem.0 = phi i32 [ 0, %bb2.thread ], [ %indvar.next,
%bb2 ]                   ; <i32> [#uses=1]

            %tmp.0.reg2mem.0 = phi i32 [ 0, %bb2.thread ], [ %4, %bb2 ]
; <i32> [#uses=1]

            %0 = load i8** %ptArgument, align 4                  ; <i8*>
[#uses=2]

            %1 = getelementptr i8* %0, i32 4                       ; <i8*>
[#uses=1]

            store i8* %1, i8** %ptArgument, align 4

            %2 = bitcast i8* %0 to i32*                    ; <i32*>
[#uses=1]

            %3 = load i32* %2, align 4                    ; <i32> [#uses=1]

            %4 = add i32 %3, %tmp.0.reg2mem.0               ; <i32>
[#uses=2]

            %indvar.next = add i32 %i.0.reg2mem.0, 1                     ;
<i32> [#uses=2]

            %exitcond = icmp eq i32 %indvar.next, 9                       ;
<i1> [#uses=1]

            br i1 %exitcond, label %bb3, label %bb2

 

bb3:                 ; preds = %bb2

            ret i32 %4

}

 

declare void @llvm.va_start(i8*) nounwind

 

 

There is a call of "va_start" and there isn't any "va_arg"! But I need it
for specifical lower in back end for my target!

 

Thanks,

--Artem

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100401/e20c6029/attachment.html>


More information about the llvm-dev mailing list