Multiversioning

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.

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.

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