[LLVMdev] Multiversioning

Holger Schurig hs4233 at mail.mn-solutions.de
Fri Jul 27 03:36:49 PDT 2007


> 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.



More information about the llvm-dev mailing list