[LLVMdev] How to get the name and argument of a function
Nick Lewycky
nicholas at mxc.ca
Mon Jan 17 16:06:46 PST 2011
songlh at cs.wisc.edu wrote:
> Hi everyone:
>
> The code I am analyzing is :
>
> int main()
> {
> int i = 0;
> printf("hello world!");
> printf( "%d" , i );
> }
>
>
>
> I want to get each place where printf is called, and the argument used
> during that call.
>
> so I write llvm pass code like:
>
> void Myfunction( Function& F){
> for( Function::iterator b = F.begin() , be = F.end() ;
> b != be; ++b){
> for(BasicBlock::iterator i = b.begin() , ie = b.end();
> i != ie; i ++){
> if( isa<CallInst>(&(*i)) || isa<InvokeInst>(&(*i))){
> //how could I get the function name and argument
> //used here
> }
> }
>
> }
> }
>
>
> How could I get the function name and the arguments when I know an
> Instruction is a function call?
There's a worked example at
http://wiki.llvm.org/HowTo:_Find_all_call_sites_of_a_function .
With the CallInst/InvokeInst you can query getArgOperand() to get the
arguments or getCallee() which return a Function -- or it might not. If
the call is an indirect call (ie., function pointer) then you don't know
what it's calling. Ignoring indirect calls, you can call getName() on a
function to get its name.
Personally, I rely heavily on the doxygen to find my way around the API:
http://llvm.org/doxygen/hierarchy.html . Look up "CallInst" for example.
The getName() method isn't on Function, but all the way on the base
class Value.
Nick
>
> thanks a lot!
>
> Best wishes!
>
> Linhai Song
>
> _______________________________________________
> 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