[LLVMdev] A few beginner level questions..
Chris Lattner
sabre at nondot.org
Thu Nov 18 10:10:29 PST 2004
On Wed, 17 Nov 2004, Reid Spencer wrote:
> > 2. For an application , for every instruction if its a call
> > instruction I try to print out the called function as below ..
> >
> > void pass01a::instruct_show(Instruction* I){
> > if ( isa<CallInst>(*I) ){
> > const CallInst *CI = cast<CallInst>(I);
> > const Function *Func = CI->getCalledFunction() ;
> > std::cerr<<":calledFunction:"<<Func->getName();
> > }
> > }
As a general comment, the above could be rewritten like this:
void pass01a::instruct_show(Instruction* I){
if (const CallInst *CI = dyn_cast<CallInst>(*I) ){
const Function *Func = CI->getCalledFunction() ;
std::cerr<<":calledFunction:"<<Func->getName();
}
... saving you a line of code ...
> > Now it works fine for some application but for one of the benchmark in
> > MIBENCH , i am getting the following error .. Is there something wrong
> > with my coding or llvm itself .? Is there any simpler way to extract
> > the function names?
There is a problem with your code, though I don't blame you. I've updated
the comment on the getCalledFunction() method to read this:
/// getCalledFunction - Return the function being called by this instruction
/// if it is a direct call. If it is a call through a function pointer,
/// return null.
I hope that helps,
-Chris
--
http://llvm.org/
http://nondot.org/sabre/
More information about the llvm-dev
mailing list