Hi, I’m somehow a newby with llvm, I’ve been working with it for 4 months.
I’m trying to convert a function to ‘main’ in order to execute this concrete function only when the program is run. To do so, I’ve been able to remove all other functions from the module, and change the function name to “main”.
I’ve then allocated new registers for all the formal parameters in the function definition, and update all the subsequent references to the parameters to the allocated values. (I don’t care if the correct value is not passed to the function).
To continue, I need to remove the arguments of the function. Here is where I start having problems. I’ve tried to do so in three different ways:
- Create a new function “main” without arguments and copy all basic-block’s from the original function to the new one. I’ve had problems with this approach because of cloning not updating operators of the basic-block instructions. Thanks to http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-June/051063.html I’ve solved this partially, but I’m still facing problems when updating branch instructions.
- Since all parameters are now useless, I’ve tried to pass the -deadargelim optimization pass with opt -deadargelim < file-1.bc > file-2.bc. However, the optimization pass does not realize by itself that the function parameters are not being used, and does not eliminate them.
- I’ve tried delete( function->arg_begin() ); with a (somehow predicted) segmentation fault.
- I’ve read http://llvm.org/docs/doxygen/html/DeadArgumentElimination_8cpp_source.html to try to understand how deadargelim eliminates the unused arguments of a function, but I’m not able to fully understand the code.
Which one is the best approach to remove the unused arguments of the function?. I’m stuck here.
Thanks a lot !!