Hi, I am interested in generating two different optimized versions of a function into a single binary, so that I can dynamically select the function to execute at runtime. Can anyone shed some insight into the difficulties in achieving this in the LLVM infrastructure? Thank you! vj. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070726/f44fb9a7/attachment.html>
> Hi, > I am interested in generating two different optimized > versions of a function into a single binary, so that I can > dynamically select the function to execute at runtime. Can > anyone shed some insight into the difficulties in achieving > this in the LLVM infrastructure?One way would be to put your function body in a file, e.g. "function.inc", and have to main files: optimize1.c: void testfunc1(void) { #include "function.inc" } optimize2.c: void testfunc2(void) { #include "function.inc" } Now tweak your makefile that the compiler uses different optimizations on those two source files. You'll end up with two *.o files, optimized differently, with different function names in it. This allows you to call testfunc1() or testfunc2(), whatever you need.
On Thu, 26 Jul 2007, VJ wrote:> I am interested in generating two different optimized versions of a > function into a single binary, so that I can dynamically select the function > to execute at runtime. Can anyone shed some insight into the difficulties in > achieving this in the LLVM infrastructure?It's hard to say without more detail. LLVM certainly does support function cloning and other transformations. Can you be more specific about your goals? -Chris -- http://nondot.org/sabre/ http://llvm.org/