Mohammad Norouzi via llvm-dev
2016-Jan-12 15:43 UTC
[llvm-dev] Get arguments of a function (bitcast)
Hi All, I need to get the list of arguments of a function which is bitcasted. Here is the C code excerpt: main() { ..... /* Get input samples */ input_dsp(input, N, 1); ..... } and here is llvm ir for the code section: %call = call i32 (i32*, i32, i32, ...)* bitcast (i32 (...)* @input_dsp to i32 (i32*, i32, i32, ...)*)(i32* getelementptr inbounds ([256 x i32]* @input, i32 0, i32 0), i32 256, i32 1) When I use the ordinary method for getting arguments, for (Function::ArgumentListType::iterator it f->getArgumentList().begin(); it != f->getArgumentList().end(); it++) {...} i get a segmentation fault which i think i valid. But how can i get arguments of *input_dsp* which are *input*, *N* and *1* in this case. Best, Mo -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160112/9e651c09/attachment.html>
Manuel Jacob via llvm-dev
2016-Jan-12 16:36 UTC
[llvm-dev] Get arguments of a function (bitcast)
Hi Mo, Have a look at the Value::stripPointerCasts() method [1] to strip all bitcasts from the function pointer. -Manuel [1] http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html#a38ea12c04523d63adda732b9c5d6da0a On 2016-01-12 16:43, Mohammad Norouzi via llvm-dev wrote:> Hi All, > > I need to get the list of arguments of a function which is bitcasted. > > Here is the C code excerpt: > > main() > { > ..... > > /* Get input samples */ > input_dsp(input, N, 1); > > ..... > } > > and here is llvm ir for the code section: > > %call = call i32 (i32*, i32, i32, ...)* bitcast (i32 (...)* @input_dsp > to > i32 (i32*, i32, i32, ...)*)(i32* getelementptr inbounds ([256 x i32]* > @input, i32 0, i32 0), i32 256, i32 1) > > > When I use the ordinary method for getting arguments, > > for (Function::ArgumentListType::iterator it > f->getArgumentList().begin(); it != f->getArgumentList().end(); it++) > {...} > > i get a segmentation fault which i think i valid. But how can i get > arguments of *input_dsp* which are *input*, *N* and *1* in this case. > > Best, > Mo > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
John Criswell via llvm-dev
2016-Jan-13 14:44 UTC
[llvm-dev] Get arguments of a function (bitcast)
Dear Mohammad, Are you trying to get the formal arguments or the actual arguments? If you're trying to get the actual arguments, you can use the CallSite class (http://llvm.org/doxygen/classllvm_1_1CallSite.html). Create a local CallSite variable constructed from the Instruction * (in this case, a CallInst). You can then use the getArgument() method to get the various operands to the call site. The CallSite class is nice because it abstracts away details of the CallInst and InvokeInst instructions. If you want the formal arguments, you need to find the function that the CallInst calls. You can do that as Manual suggests. However, keep in mind that the CallInst may be an indirect call and, therefore, you may not see a Function constant. In that case, you'll need to use a call graph analysis pass (like DSA) to determine which set of functions the CallInst can call. Regards, John Criswell On 1/12/16 10:43 AM, Mohammad Norouzi via llvm-dev wrote:> Hi All, > > I need to get the list of arguments of a function which is bitcasted. > > Here is the C code excerpt: > > main() > { > ..... > > /* Get input samples */ > input_dsp(input, N, 1); > > ..... > } > > and here is llvm ir for the code section: > > %call = call i32 (i32*, i32, i32, ...)* bitcast (i32 (...)* @input_dsp > to i32 (i32*, i32, i32, ...)*)(i32* getelementptr inbounds ([256 x > i32]* @input, i32 0, i32 0), i32 256, i32 1) > > > When I use the ordinary method for getting arguments, > > for (Function::ArgumentListType::iterator it = > f->getArgumentList().begin(); it != f->getArgumentList().end(); it++) > {...} > > i get a segmentation fault which i think i valid. But how can i get > arguments of /input_dsp/ which are /input/, /N/ and /1/ in this case. > > Best, > Mo > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-- John Criswell Assistant Professor Department of Computer Science, University of Rochester http://www.cs.rochester.edu/u/criswell -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160113/0260a21c/attachment.html>