notices for using llvm bitcode

If someone use ANTLR3 and LLVM 2.7 to construct a compiler, I believe some of my notices/hints written here will be very very useful.

  1. 1. function's parameter is read only. you should use "alloca" to create a "local variable" to make function parameter writable.
  2. each "basic block" should have a "terminate" instruction. -> br and ret
  3. each "function module" should have only one "ret" instruction. only one!!!!!!!!!!
  4. 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".
  5. ANTLR3's tree walker is great to write "multiple pass" symbol table constructor. But it's a little inconvenient for LLVM IR generator.
  6.  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.

  1.  But it's impossible to let all of your expression be ssa form (just my experience). 
  2. I just using alloca to present cross-statement variable, store these variable to "stack" instead SSA is much good choice for me. 
  3. 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.