<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hi, I'm somehow a newby with llvm, I've been working with it for 4 months.</span><div style="font-family:arial,sans-serif;font-size:13px"><br>

</div><div style="font-family:arial,sans-serif;font-size:13px">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".</div>

<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">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).</div>

<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">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:</div>

<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">* 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 <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-June/051063.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-June/051063.html</a> I've solved this partially, but I'm still facing problems when updating branch instructions.</div>

<div style="font-family:arial,sans-serif;font-size:13px">* 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.</div>

<div style="font-family:arial,sans-serif;font-size:13px">* I've tried delete( function->arg_begin() ); with a (somehow predicted) segmentation fault.</div><div style="font-family:arial,sans-serif;font-size:13px">* I've read <a href="http://llvm.org/docs/doxygen/html/DeadArgumentElimination_8cpp_source.html" target="_blank">http://llvm.org/docs/doxygen/html/DeadArgumentElimination_8cpp_source.html</a> to try to understand how deadargelim eliminates the unused arguments of a function, but I'm not able to fully understand the code.</div>

<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Which one is the best approach to remove the unused arguments of the function?. I'm stuck here.</div>

<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Thanks a lot !!</div>
</div>