Re:Gollvm from Google
by barrkel on Saturday May 27, 2017 @01:19PM
(#14430934)
Why zero first, that's already been explained. Why alloca from the stack: this is because there is a pass in LLVM which converts alloca locations into SSA form[1], and SSA is what many of the other optimizations in LLVM are built around. The rules around SSA mean that variables are renamed rather than modified (every assignment is final, except for phi nodes where control flow merges), so producing SSA output from an imperative language is a bit more difficult. Since LLVM comes with something that converts mutable stack allocations into SSA, it's easier to just leverage it.
The pass is called mem2reg:
http://llvm.org/docs/Passes.html#mem2reg-promote-memory-to-r...
[1] https://en.wikipedia.org/wiki/Static_single_assignment_form