[LLVMdev] How to replace a function using llvm?

Yury Mikhaylov yury.mikhaylov at gmail.com
Mon Sep 19 16:39:39 PDT 2011

Hello Shawn,

I've just implemented something similar. It might be horribly wrong to do it
this way, but at least it works for me :-)

Here's what I do:

* Rename your function "haha" -> "haha_" to avoid name collisions in the
next step;
* Get its function type and modify to suite your needs: add new parameters,
change types, whatever;
* Create new function named "haha" with that signature;
* Relink all basic blocks from original function to the new one. Now "haha_"
is empty, but you can't delete it yet;
* Iterate over all modules/functions that reference your original function
and replace call instructions to match new signature;
* Delete "haha_" function.

I'm no LLVM expert by any means, so take this with a grain of salt..

- Yury
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110919/87559462/attachment.html>

More information about the llvm-dev mailing list