Change the return type of a function

Hello All,

I want to change the return type of a function in a Pass(in a module Pass). I dont want to change any of the arguments of that function.
Assume that, I can handle the returning values properly inside the function. Please guide me how to do this ?

You need to do the following steps:

  1. Create a new function with the desired function type.
  2. Clone the body of the old function into the new function
  3. Find all calls calling the old function and replace them with calls to the new function.

This is necessary because a function cannot have its type changed once it has been created.

Automatic Pool Allocation adds parameters to functions (which is similar to what you need to do). See MakeFunctionClone() in poolalloc/lib/PoolAllocate/PoolAllocate.cpp in the poolalloc project. Use

svn co poolalloc … to get a copy from SVN. – John T.

Thanks John for the reply. Ya, I took a similar approach. I cloned the entire
function using CloneFunctionInto() in Cloning.h.

Now, I am facing a new Problem. I am not able to understand the concept of
ValueToValueMap. I am trying to figure it out by testing it. But I am getting
errors like “Referring to an argument in another function!”. I am not able to get
good examples nor good documentation on ValueToValueMap. Can you point
me in the right direction ?

You need to add some 'old first argument ==> new first argument', 'old
second argument ==> new second argument' (and so on) mappings to it.