[LLVMdev] Precompiled templates

Eichner, Andreas - SID-NLKM Andreas.Eichner at sid.sachsen.de
Wed May 25 03:12:57 PDT 2011


Hello list,

I'm currently investigating the use of LLVM for a project. For example,
if I have a function like

int a(int x, int y) {
  if (P == 0)  {
    return x - y;
  } else {
    return y - x;
  }
}

and P could be considered constant, one of the code paths could be
optimized out. Now I want to load a compiled bitcode file into a CFG,
replace all occurrences of P with the value (either 0 or 1), run the
optimization and JIT-compile into a anonymous function on the heap.
Is that possible and if yes how? Basically I thought of declaring the
parameter P as "extern const" and when the CFG is created, also create a
constant node with the actual value and run a "replace-symbol (P,
const_instr)". After that everything should be as easy as in the JIT
compiler tutorial.

Is something like that feasible? And how? I would appreciate any
suggestions.

Thanks in advance,

Andreas




More information about the llvm-dev mailing list