[LLVMdev] How to duplicate a CallInst

Duncan Sands baldrick at free.fr
Sat Jan 7 01:20:10 PST 2012


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




More information about the llvm-dev mailing list