[LLVMdev] A few beginner level questions..

Reid Spencer reid at x10sys.com
Wed Nov 17 23:48:45 PST 2004


On Wed, 2004-11-17 at 23:19, Abhijit Ray wrote:
> 1. If we run a few passes in a sequence ..is the bytecode file
> transformed after each pass in sequence i.e
> 
> if we have 
> a) opt -pass1 -pass2 -pass3 < in.bc > out.bc 
> b)opt -pass1 -pass2 < in.bc > tmp.bc 
>   opt -pass3 < tmp.bc > out.bc 
> 
> are the above two equivalent ? 

Yes, they're equivalent.

> what I basically want is to run my pass on an optimised bytecode , so
> should i optimize it and get a new bytecode file first or I can just
> put my pass at the end of all the other optimization passes ?

Just put yours at the end. You'll need to create a loadable module
(shared library/dll) and use the --load option to op.

> 
> 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();
>    }
> }
> 
> Now it works fine for some application but for one of the benchmark in
> MIBENCH , i am getting the following error ..
> 
> ++++++++++++++++++++++++
> :calledFunction:opt((anonymous namespace)::PrintStackTrace()+0x1a)[0x86b74e6]
> opt((anonymous namespace)::SignalHandler(int)+0xcb)[0x86b7759]
> /lib/libc.so.6[0x401532b8]
> /home/ary/work/llvm/lib/Debug/libpass01.so((anonymous
> namespace)::pass01a::instruct_show(llvm::Instruction*)+0x281)[0x4001a425]
> /home/ary/work/llvm/lib/Debug/libpass01.so((anonymous
> namespace)::pass01a::runOnFunction(llvm::Function&)+0x18c)[0x4001b57c]
> opt(llvm::PassManagerTraits<llvm::Function>::runPass(llvm::FunctionPass*,
> llvm::Function*)+0x1f)[0x8679cbf]
> opt(llvm::PassManagerT<llvm::Function>::runOnUnit(llvm::Function*)+0x5d3)[0x8675117]
> opt(llvm::PassManagerTraits<llvm::Function>::runOnFunction(llvm::Function&)+0x1f)[0x8672f1d]
> opt(llvm::FunctionPass::runOnModule(llvm::Module&)+0xa7)[0x862234b]
> opt(llvm::PassManagerTraits<llvm::Module>::runPass(llvm::ModulePass*,
> llvm::Module*)+0x1f)[0x8679d55]
> opt(llvm::PassManagerT<llvm::Module>::runOnUnit(llvm::Module*)+0x5d3)[0x8673653]
> opt(llvm::PassManagerTraits<llvm::Module>::runOnModule(llvm::Module&)+0x1f)[0x8672ce1]
> opt(llvm::PassManager::run(llvm::Module&)+0x23)[0x862174d]
> opt(main+0x913)[0x83c0bab]
> /lib/libc.so.6(__libc_start_main+0xcb)[0x4013f90b]
> opt(dlopen+0x41)[0x83c0201]
> Segmentation fault
> +++++++++++++++++++++++++++
> 
> Is there something wrong with my coding or llvm itself .? Is there any
> simpler way to extract the function names?

Based on the above, it looks like "Func" is null. I'm not sure why the
getCalledFunction would return a null, but it looks like it is. Possibly
some transformation invalidated it? What happens in runOnFunction before
you call instruct_show?

Reid.

> 
> Thanks,
> Abhijit
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20041117/9e2c8c63/attachment.sig>


More information about the llvm-dev mailing list