- 1. function's parameter is read only. you should use "alloca" to create a "local variable" to make function parameter writable.
- each "basic block" should have a "terminate" instruction. -> br and ret
- each "function module" should have only one "ret" instruction. only one!!!!!!!!!!
- ANTLR3's tree walker is great to write "multiple pass" symbol table constructor. But it's a little inconvenient for LLVM IR generator.
here's my solution: create a "entry block" and "return block". puts every "alloca" to "entry block" and create a "alloca" for return variable. Puts "ret" instruction in "return block". If other statement need to return different return value, I just store "return variable" and "br" to "return block".
EX) conditional block, if() :I need to use IR Builder to create a conditional jump before it's successor not created. When antlr3 walk to this point, my program still don't know how many elsif and else success behind me.My Solution:Create your own IR to present statement structure. (only statement)
LLVM is ssa system.
- But it's impossible to let all of your expression be ssa form (just my experience).
- I just using alloca to present cross-statement variable, store these variable to "stack" instead SSA is much good choice for me.
- If you want to fully utilize SSA's benefit, you should write your own IR to present an expression. Using ANTLR3's grammar tree, you don't need to worry about your IR's operator priority. Just be careful for assignment's LHF and RHS.