[LLVMdev] Dynamic Profiling - Instrumentation basic query

SArora silkyar at umich.edu
Tue Jan 15 16:38:55 PST 2013


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.



More information about the llvm-dev mailing list