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.

1 則留言:

  1. With new games arriving a daily basis}, there's always something new to discover at Free Daily Spins. Slot machines are 우리카지노 programmed to pay out a sure share of all cash that's bet on them. This payout price typically varies from round 82% a lot as} 99%. For occasion, when a slot has a payout price of 95%, for every $100 wagered on the game, $95 might be paid again to gamers as winnings over lengthy run|the lengthy term}. The idea of cold and hot slots signifies whether or not a machine is on a scorching streak of payouts. Or vice-versa, where chilly slots are not giving out many payouts.