[LLVMdev] Precompiled templates

Duncan Sands baldrick at free.fr
Fri May 27 00:20:14 PDT 2011


Hi Andreas,

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

It is.  For example you can declare a new global constant P2 with the
appropriate initial value (0 or 1), then do: P->replaceAllUsesWith(P2).
At that you can erase (i.e. delete) P.  Running the instcombine pass on
the module should then propagate the information into all functions;
following that by a run of the simplifycfg pass will get rid of dead
basic blocks.

  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.

Yup, that's a good approach.

Ciao, Duncan.

>
> Is something like that feasible? And how? I would appreciate any
> suggestions.
>
> Thanks in advance,
>
> Andreas
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list