[LLVMdev] Convert a function to "main"

Tyler Hardin tghardin1 at catamount.wcu.edu
Thu Oct 3 22:36:06 PDT 2013


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.
On Oct 3, 2013 11:38 AM, "Pablo González de Aledo" <pablo.aledo at gmail.com>
wrote:

> 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 !!
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131004/08d9e52b/attachment.html>


More information about the llvm-dev mailing list