How to duplicate a CallInst

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(*Is)){
CallInst *call = dyn_cast(&*Is);

Function* ft = call->getCalledFunction();

arguments = ???

CallInst *call2 = CallInst::Create(ft, arguments.begin(), arguments.end(), “”, ++Is);

}

}

Thanks,

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.