[llvm-dev] function call replacement
Nema, Ashutosh via llvm-dev
llvm-dev at lists.llvm.org
Mon Jun 20 05:25:16 PDT 2016
Few things you have to be careful with:
1) Create args properly and make sure the actual and formal parameter types should be same.
If not add a cast.
2) Make sure the return types are same.
3) Set the calling conventions if any.
4) Replace use if any.
5) Then replace the instruction.
SmallVector<Value *, 8> Args(CS.arg_begin(), CS.arg_end());
CallInst *NewCI = CallInst::Create(NewFunc, Args);
From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Pierre Gagelin via llvm-dev
Sent: Monday, June 20, 2016 4:47 PM
To: llvm-dev at lists.llvm.org
Subject: [llvm-dev] function call replacement
I am trying to replace the call of a certain function with a call to another function. It would for example replace the following:
%call = tail call noalias i8* @func(i64 10)
%call = tail call noalias i8* @other_func(i64 10)
I managed to declare other_func correctly but I am having troubles to understand how I should proceed to do the replacement.
I tried to use ReplaceInstWithInst function as follows:
CallInst *call_to_other_func_inst = IRBuilder.CreateCall(ptr_to_other_func, args);
LLVM builds correctly but the instrumentation crashes at optimization time. I know this isn't the correct way to do it because IRBuilder generates IR and I just want to have an instance of a CallInst. But I don't see how it is supposed to be done?
There are methods to create CallInst in the Instruction.h file but those needs to give an inserting point. Shoud I insert the call to other_func before the one to func and just remove the call instruction to func?
Thanks for your help,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev