[LLVMdev] Clone a function and change signature

Chris Lattner clattner at apple.com
Tue Feb 22 12:43:27 PST 2011


On Feb 22, 2011, at 11:46 AM, John Criswell wrote:

> On 2/22/11 1:31 PM, Arushi Aggarwal wrote:
>> Hi,
>> 
>> I want to clone a given function, and add an argument to it. I then 
>> want to add a call to that new function. I have a callInstruction CI, 
>> which I want to transform to call this new function, and to take a new 
>> argument.
> 
> If I understand correctly, you're cloning the function first and then 
> adding a new argument to the clone.  Do I understand correctly?
> 
> If so, I don't believe you can do that.  IIRC, you have to first create 
> a new, empty function with the additional argument and then use 
> CloneFunctionInto() to clone the body of the original function into the 
> new function.  I believe that's what poolalloc does and what I did the 
> last time I had to add function arguments to a function.

Right, you can also take a look at the dead argument elimination or argument promotion passes for examples.

-Chris



More information about the llvm-dev mailing list