[LLVMdev] LLVM load instruction query

Anshul gargaa24 at gmail.com
Wed Mar 6 05:53:04 PST 2013





Duncan Sands <baldrick <at> free.fr> writes:

> 
> Hi Anshul,
> 
>  > I am creating a pass that will pass loaded value by load instruction to an
> > external function.
> > I don't know how to do it.Please Help.
> 
> your question is too vague for anyone to be able to help you.  Add details,
> for example provide the code for your pass.
> 
> Ciao, Duncan.
> 
Here is the code that i did.
I tried to found error.I think whatever i am doing for getting loaded value is 
wrong.But i dont know how to correct it

        virtual bool runOnModule(Module &M)
        {
            Constant *cpProfFunc;
            Context = &M.getContext();
            cpProfFunc = 
M.getOrInsertFunction("_Z6cpProfi",Type::getVoidTy(*Context),
                                                
PointerType::getUnqual(Type::getInt8Ty(*Context)),
                                                ,NULL);   
            cpProf= cast<Function>(cpProfFunc);


            for(Module::iterator F = M.begin(), E = M.end(); F!= E; ++F)
            {
            
                    for(Function::iterator BB = F->begin(), E = F->end(); BB != 
E; ++BB)
                    {
                        anshul_insert::runOnBasicBlock(BB);
                    }
             }

            return false;
        }
        virtual bool runOnBasicBlock(Function::iterator &BB)
        {
            for(BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE; 
++BI)    
            {       
                
                    if(isa<LoadInst>(&(*BI)) )
                    {
                           
                            std::vector<Value*> a1(1);
                            LoadInst *CI = dyn_cast<LoadInst>(BI);
                            
a1[0]=ConstantInt::get(Type::getInt32Ty(*Context),CI->getPointerOperand());
                           
                         CallInst* newInst = CallInst::Create(cpProf,a1,"");
                         BB->getInstList().insert((Instruction*)CI, newInst);
                        
                                                
                    }
                   
            }
            return true;
        }
    };
}




More information about the llvm-dev mailing list