Hi Alastair, Thank you so much for the information on the tools. Actually, I need to analyze which sections of code are prone to misses and mis predicts, and would have to eventually instrument the code. I was able to instrument and call an external function, but faced an issue while passing an argument to the function. I am following EdgeProfiling.cpp but couldn't figure out the problem. Could you please see where I am going wrong here - virtual bool runOnModule(Module &M) { Constant *hookFunc; LLVMContext& context = M.getContext(); hookFunc M.getOrInsertFunction("cacheCounter",Type::getVoidTy(M.getContext()), llvm::Type::getInt32Ty(M.getContext()), (Type*)0); cacheCounter= cast<Function>(hookFunc); for(Module::iterator F = M.begin(), E = M.end(); F!= E; ++F) { for(Function::iterator BB = F->begin(), E = F->end(); BB !E; ++BB) { cacheProf::runOnBasicBlock(BB, hookFunc, context); } } return false; } virtual bool runOnBasicBlock(Function::iterator &BB, Constant* hookFunc, LLVMContext& context) { for(BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI !BE; ++BI) { std::vector<Value*> Args(1); unsigned a =100; Args[0] = ConstantInt::get(Type::getInt32Ty(context), a); if(isa<LoadInst>(&(*BI)) ) { CallInst *newInst = CallInst::Create(hookFunc, Args, "",BI); } } return true; } The C code is as follows - extern "C" void cacheCounter(unsigned a){ std::cout<<a<<" Load instruction\n"; } Error: line 8: 18499 Segmentation fault (core dumped) lli out.bc Also, the code works fine when I don't try to print out 'a'. Thanks for your help. Regards, Silky -- View this message in context: http://llvm.1065342.n5.nabble.com/Dynamic-Profiling-Instrumentation-basic-query-tp53611p53744.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Alastair Murray
2013-Jan-20 21:31 UTC
[LLVMdev] Dynamic Profiling - Instrumentation basic query
Hi Silky, Sorry for the slow reply. You probably already fixed this, but just in case I'll reply anyway. Comments inline below On 15/01/13 19:38, SArora wrote:> Hi Alastair, > Thank you so much for the information on the tools. Actually, I need to > analyze which sections of code are prone to misses and mis predicts, and > would have to eventually instrument the code. > > I was able to instrument and call an external function, but faced an issue > while passing an argument to the function. I am following EdgeProfiling.cpp > but couldn't figure out the problem. Could you please see where I am going > wrong here - > > virtual bool runOnModule(Module &M) > { > Constant *hookFunc; > LLVMContext& context = M.getContext(); > hookFunc > M.getOrInsertFunction("cacheCounter",Type::getVoidTy(M.getContext()), > > llvm::Type::getInt32Ty(M.getContext()), > (Type*)0); > cacheCounter= cast<Function>(hookFunc); > > for(Module::iterator F = M.begin(), E = M.end(); F!= E; ++F) > { > > for(Function::iterator BB = F->begin(), E = F->end(); BB !> E; ++BB) > { > cacheProf::runOnBasicBlock(BB, hookFunc, context); > } > } > > return false; > } > virtual bool runOnBasicBlock(Function::iterator &BB, Constant* > hookFunc, LLVMContext& context) > { > > for(BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI !> BE; ++BI) > { > std::vector<Value*> Args(1); > unsigned a =100; > Args[0] = ConstantInt::get(Type::getInt32Ty(context), a); > if(isa<LoadInst>(&(*BI)) ) > { > CallInst *newInst = CallInst::Create(hookFunc, Args, > "",BI);Did this line compile without warning? Shouldn't 'BI' be '&(*BI)' or something?> } > > } > return true; > } > > The C code is as follows - > > extern "C" void cacheCounter(unsigned a){ > std::cout<<a<<" Load instruction\n"; > }I was kind of surprised that this worked, so I tried it out and it does! In general libprofile_rt.so is written in C though, if you write it in C++ it will require a C++ library at run-time.> > Error: > line 8: 18499 Segmentation fault (core dumped) lli out.bc > > Also, the code works fine when I don't try to print out 'a'. > > Thanks for your help. > > Regards, > SilkyYou could look at the IR for out.bc before running it, if there is something wrong it will probably be pretty obvious there. Regards, Alastair.
Hi Alastair, You're right. I figured out that I wasn't linking the files properly. Instead of using llvm-link command I used the following commands, and it worked. opt -load /x/ext_students/silkyar/llvm/Debug+Asserts/lib/cacheProf.so -cacheProf a.bc>out.bc llc out.bc -o out.s g++ -o cache.exe out.s cacheSim.o ./cache.exe Regards, Silky -- View this message in context: http://llvm.1065342.n5.nabble.com/Dynamic-Profiling-Instrumentation-basic-query-tp53611p53942.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Maybe Matching Threads
- [LLVMdev] Dynamic Profiling - Instrumentation basic query
- [LLVMdev] Dynamic Profiling - Instrumentation basic query
- [LLVMdev] Dynamic Profiling - Instrumentation basic query
- [LLVMdev] Dynamic Profiling - Instrumentation basic query
- [LLVMdev] Insert a function call in the code