Prabhat Kumar Saraswat
2008-Jan-04 13:10 UTC
[LLVMdev] Extraction of Arguments Passed to a Function
Hi, I am trying to extract the name of the variables passed as an Argument to a Function. I am using a runOnFunction Pass. For example in the following IR respresentation, define void @foo(i32 %limit) { entry: -- -- } I should be able to walk the IR and get '%limit' as the external variable passed to the function. Another question, Is it possible to create a basic symbol table ( internal variables in a function, global variables outside of a fucntion ) only from the entry: basic block. According to my observation, it seems that the temporary variables created for different basic block are independent from each other, for example in the following IR the temp variables used in the basic block bb: i.e. %tmp, %tmp1, %tmp2 are only dependent on the variables defined in the entry: basic block, and same holds for basic block bb5: i.e. variables %tmp6, %tmp7, %tmp8 etc are only dependent on the variables in the entry block (%limit_addr, %i.. etc) and the temp variables defined in the same basic block. Is this true ?, as far as i have seen, by generating the bitcode for various test codes, and it holds true for all. So, now the proposition is, that one can create the symbol table of the internal variables and the variables passed to the function as an agrument by only using the information in entry block and argument list information. The IR.... ................. define void @foo(i32 %limit) { entry: %limit_addr = alloca i32 ; <i32*> [#uses=2] %i = alloca i32, align 4 ; <i32*> [#uses=6] %"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0] store i32 %limit, i32* %limit_addr store i32 0, i32* %i, align 4 store i32 0, i32* %i, align 4 br label %bb5 bb: ; preds = %bb5 %tmp = getelementptr [24 x i8]* @.str, i32 0, i32 0 ; <i8*> [#uses=1] %tmp1 = load i32* %i, align 4 ; <i32> [#uses=1] %tmp2 = call i32 (i8* noalias , ...)* @printf( i8* %tmp noalias , i32 %tmp1 ) ; <i32> [#uses=0] %tmp3 = load i32* %i, align 4 ; <i32> [#uses=1] %tmp4 = add i32 %tmp3, 1 ; <i32> [#uses=1] store i32 %tmp4, i32* %i, align 4 br label %bb5 bb5: ; preds = %bb, %entry %tmp6 = load i32* @glob_var, align 4 ; <i32> [#uses=1] %tmp7 = load i32* %limit_addr, align 4 ; <i32> [#uses=1] %tmp8 = add i32 %tmp7, %tmp6 ; <i32> [#uses=1] %tmp9 = load i32* %i, align 4 ; <i32> [#uses=1] %tmp10 = icmp sge i32 %tmp8, %tmp9 ; <i1> [#uses=1] %tmp1011 = zext i1 %tmp10 to i8 ; <i8> [#uses=1] %toBool = icmp ne i8 %tmp1011, 0 ; <i1> [#uses=1] br i1 %toBool, label %bb, label %bb12 bb12: ; preds = %bb5 br label %return return: ; preds = %bb12 ret void } ......................... Thanks and Regards Prabhat -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080104/ed767cbc/attachment.html>