progs/fun_llvm.scala
changeset 657 732cb155d806
parent 656 cfc0e730bcda
child 678 ff3b48da282c
equal deleted inserted replaced
656:cfc0e730bcda 657:732cb155d806
   269 
   269 
   270 
   270 
   271 def main(args: Array[String]) : Unit = 
   271 def main(args: Array[String]) : Unit = 
   272    //println(compile(args(0)))
   272    //println(compile(args(0)))
   273    compile_and_run(args(0))
   273    compile_and_run(args(0))
   274 
   274 }
   275 }
   275 
       
   276 
       
   277 
       
   278 
       
   279 
       
   280 /*
       
   281 LLVM notes
       
   282 
       
   283 Registers are places for data inside the CPU.
       
   284 + up to 10 times faster access than to main memory 
       
   285 - expensive; typically just 32 of them in a 32-bit CPU
       
   286 
       
   287 High-level view of x86
       
   288 • Not a stack machine; no direct correspondence to operand stacks
       
   289 • Arithmetics, etc. is done with values in registers
       
   290 
       
   291 • Started as academic project at University of Illinois in 2002
       
   292 • Now a large open source project with many contributors and a growing user base
       
   293 
       
   294 Single Static Assignment (SSA) form
       
   295 • Only one assignment in the program text to each variable
       
   296 • But dynamically, this assignment can be executed many times
       
   297 • Many stores to a memory location are allowed
       
   298 • Also, Φ (phi) instructions can be used, in the beginning of a basic block
       
   299 • Value is one of the arguments, depending on from which block control came to this block
       
   300 • Register allocation tries to keep these variables in same real register
       
   301 
       
   302 Why SSA form?
       
   303 Many code optimizations can be done more efficiently
       
   304 
       
   305 Function definition form
       
   306  define t @name(t1 x1, t2 x2, ..., tn xn) {
       
   307  l1: block1
       
   308  l2: block2
       
   309  ... 
       
   310  lm : blockm
       
   311  }
       
   312 
       
   313 
       
   314 
       
   315 
       
   316 */