<p dir="ltr">This may be a really naive suggestion (I'm sure I know even less about LLVM than you), but could you just create a wrapper function called main that calls the function you want to be main? Surely there's a pass that would remove pointless calls like that, which would give you the result you're asking for.</p>
<div class="gmail_quote">On Oct 3, 2013 11:38 AM, "Pablo González de Aledo" <<a href="mailto:pablo.aledo@gmail.com">pablo.aledo@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<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>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div>