But if a module is constructed by hand, how can I transform it into a
LLVM IR is *always* in SSA form, even if you're constructing module by
hands (Verifier pass actually does the check and reject invalid code).
If you want to eliminate memory accesses and transform them to registers
& phi's you might want to run mem2reg pass also.
Anton Korobeynikov wrote:
To add to what Anton has said:
You need to generate your code in SSA form. Generating SSA code is kind
of a pain, so here's the easiest way to do it:
1) Make all of your variables memory locations (LLVM globals or LLVM
alloca instructions). Every time you use the variable, use the LLVM
load and store instructions to read and write its value.
2) After your LLVM bytecode is generated, use the mem2reg pass (opt
-mem2reg) to convert the memory locations into LLVM virtual registers.
The mem2reg pass will take care of all the details of creating phi nodes
This is what we did for the C frontend in LLVM 1.8 and previous (we
probably do it in LLVM 1.9 and later, but I'm not sure).
-- John T.