Hi,
I have the following piece of code:
%34 = fptosi float %33 to i32
%35 = call i32 @function(i32 %34) nounwind
I would like of know how can I duplicate the statement %35 ? , as follows:
%34 = fptosi float %33 to i32
%35 = call i32 @function(i32 %34) nounwind
*%36 = **call i32 @function(i32 %34) nounwind*
*
*
i.e, two instructions exactly equal.
Using clone, results in badref.
Moreover, how can I get the parameters of function?
This is my experimental code that not is running wich I need:
for (BasicBlock::iterator Is = i->begin(), e = i->end(); Is != e; ++Is){
if(isa<CallInst>(*Is)){
CallInst *call = dyn_cast<CallInst>(&*Is);
Function* ft = call->getCalledFunction();
*arguments = ????*
CallInst *call2 = CallInst::Create(ft, *arguments.begin(),
arguments.end()*, "", ++Is);
}
}
Thanks,
--
*Rafael Parizi*
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20120106/6dc1ea9b/attachment.html>
On Jan 6, 2012, at 9:50 AM, Rafael Baldiati Parizi wrote:> Hi, > I have the following piece of code: > %34 = fptosi float %33 to i32 > %35 = call i32 @function(i32 %34) nounwind > > I would like of know how can I duplicate the statement %35 ? , as follows: > %34 = fptosi float %33 to i32 > %35 = call i32 @function(i32 %34) nounwind > %36 = call i32 @function(i32 %34) nounwind > > i.e, two instructions exactly equal. > > Using clone, results in badref.Did you insert the new call instruction it into the basic block?> Moreover, how can I get the parameters of function? > > This is my experimental code that not is running wich I need: > for (BasicBlock::iterator Is = i->begin(), e = i->end(); Is != e; ++Is){ > if(isa<CallInst>(*Is)){ > CallInst *call = dyn_cast<CallInst>(&*Is); > Function* ft = call->getCalledFunction(); > arguments = ???? > CallInst *call2 = CallInst::Create(ft, arguments.begin(), arguments.end(), "", ++Is); > } > } > >Look at the call->getNumArgOperands() and call->getArgOperand() methods. -bw
Hi Rafael,> I have the following piece of code: > %34 = fptosi float %33 to i32 > %35 = call i32 @function(i32 %34) nounwind > > I would like of know how can I duplicate the statement %35 ? , as follows: > %34 = fptosi float %33 to i32 > %35 = call i32 @function(i32 %34) nounwind > *%36 = * *call i32 @function(i32 %34) nounwind*why do you want to do this? Anyway, you will need to create a new CallInst and populate it with the operands and attributes of the first one. If you take a look at a pass like DeadArgumentElimination you should find code that does something like that (except that there one argument is dropped).> * > * > i.e, two instructions exactly equal. > > Using clone, results in badref. > Moreover, how can I get the parameters of function? > > This is my experimental code that not is running wich I need: > for (BasicBlock::iterator Is = i->begin(), e = i->end(); Is != e; ++Is){ > if(isa<CallInst>(*Is)){ > CallInst *call = dyn_cast<CallInst>(&*Is); > Function* ft = call->getCalledFunction();This will return null for indirect calls.> *arguments = ????*It looks like you want ft->arg_begin() and ft->arg_end() (see Function.h). Ciao, Duncan.> CallInst *call2 = CallInst::Create(ft, *arguments.begin(), > arguments.end()* , "", ++Is); > } > } > > > Thanks, > -- > */Rafael Parizi/* > > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev