[llvm-dev] How to change the type of operands in the Callinst in llvm?

Pierre Gagelin via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 30 00:23:31 PDT 2016

Hi Sue,

> A new definition of called function is constructed(declare x86_fp80 
> @new_add(x86_fp80, x86_fp80, ...)), but the body of this new function 
> is empty. I am very confused how to add the body and get the IR_New I 
> want. My naive idea is:
> |for (Instruction i : called function(add in the example)){
>     create new_i with type x86_fp80;
>     insert new_i in the new function constructed(new_add in the example);
> }|
> Is this a good way to achieve my goal please?
I think this will work but you would have to care about replacing 
operands coming from function's argument with new arguments. Maybe take 
a look at CloneFunctionInto. Once you have created both functions (like 
it is your case obviously), you need to map arguments together like:

ValueToValueMapTy VMap;
for(Function::arg_iterator b_a = func->arg_begin(), e_a = 
func->arg_end() ; b_a != e_a ; ++b_a) {
     Argument *Arg = &*b_a;
     VMap[Arg] = ... (argument from the new function);

CloneFunctionInto will replace them in the new function body (as they 
say in the source code, that's the worst part to implement). Though I am 
not sure it will work with different types? Maybe consider doing this at 
beginning of you instrumentation and then do you instrumentation to 
mutate the type.
> Any advice will be greatly appreciated :)
> Sincerely,
> Suhua
Note that if you don't need to keep your old "add" function there are 
better ways to do. But for compatibility reasons it can be nice to have it.

Hope that helps,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160830/4a2b9ff4/attachment.html>

More information about the llvm-dev mailing list