[LLVMdev] Cloning a function with a changed return type

Prabhat Kumar Saraswat prabhat.saraswat at gmail.com
Tue Mar 11 05:53:47 PDT 2008

Hi all,
   I was working on writing a slicing pass which would remove the
parts of the code which are not relevant from the control flow point
of view (mainly, the repetitive computations in the body of the loops
etc). I have been able to implement it successfully. From the POV of
implementation, the pass locates the conditional branches, and then
the conditions are identified, all the instructions which could be
affecting that value are kept while the rest of them are deleted. This
is done by recursively iterating over the defintions and use of those

   Basically, This was done to get a function whose control flow
structure is same as that of original, but the computation overhead is
less. However, when the instructions are removed, several asserts are
encountered during the verifier phase, mostly "Instruction does not
dominate all uses!", rightly so because for the functions with a
return value, all the instructions computing that value are removed by
the pass.

   Thus, a better thing to do would be to remove the return value
statements from the function, but then there are consistency issues
with the function declaration, as the function is declared with a
return type.

   Thus, my questions are:

   1. Is it possible to clone all basic blocks of the function, along
with the function arguments, inside another function, but changing the
type of the function (mainly(only) the return type).

   thus basically ( to illustrate by an example)

   int foo (int a, int b)
      int c;
      return c;

   after slicing and cloning

   void foo_cloned (int a, int b)

   - the function return type is changed, always changed to void()
(to be done!!)
   - computation overhead parts are removed (DONE already)
   - the control structure is basically the same  (DONE already)

   2. Alternatively, Is it possible to change the return type of the
original function itself during the runonmodule pass ?

   Any ideas ? :)



More information about the llvm-dev mailing list