See: https://docs.google.com/document/d/1szwabPJJc4J-igUZU4ZKprOr...
I’m not entirely convinced that stages 2 & 3 are
necessary, maybe we stop at stage 1. It all depends on
what optimizations we’d like to do that can’t be done
because the IR is in the wrong form. Proceeding with
stages 2 and 3 might gain some efficiency in the compiler
itself because then we don’t have to generate the old IR
at all. I suspect that effect will be small, however.https://www.cs.cmu.edu/~fp/courses/15411-f08/lectures/09-ssa...
https://groups.google.com/forum/#!topic/golang-dev/zz-gWGXFZ...
I'm interested in why LLVM was disqualified. Was it simply never considered or is it incompatible with the Go type system, calling convention, etc.?
Also LLVM requires you to either write your IR in SSA or add another expensive optimisation pass to make it SSA (mem2reg). Perhaps they thought writing an SSA generator would be too much of a headache.
From the end of
http://llvm.org/docs/tutorial/LangImpl7.html#memory-in-llvm
> Proven and well tested: clang uses this technique for local mutable variables. As such, the most common clients of LLVM are using this to handle a bulk of their variables. You can be sure that bugs are found fast and fixed early.
They simply used what they knew best:
> If step one had been "learn the GCC or LLVM toolchains well enough to add segmented stacks", I'm not sure we'd have gotten to step two.
> Honestly, if we'd built on GCC or LLVM, we'd be moving so slowly I'd probably have left the project years ago.
If we were using LLVM...
You don't need to add every optimization known to man to a compiler, so you can sometimes keep a few of the important ones and then skip every other optimization. A priori, I'd guess SSA would speed up the compiler, which means you end up having a better budget for the more expensive optimizations.
[1] https://github.com/golang/go/blob/master/src/cmd/compile/int...
[2] http://pp.info.uni-karlsruhe.de/uploads/publikationen/braun1...
SSA is a conversion of the program into a representation of its data flow. I've used it in multiple compilers and found it to be a big win for easing other analyses (e.g., induction variable recognition become trivial) and reducing bugs due to the update problem.