On Monday, 13 September 2021 at 04:08:53 UTC, rikki cattermole
wrote:
On 13/09/2021 3:21 PM, leikang wrote:
Are there any recommended books or videos to learn about the
principles of compilation? What else should I learn besides
the principles of compilation?
The classic book on compilers that Walter recommends is the
dragon book.
https://smile.amazon.com/Compilers-Principles-Techniques-Tools-2nd-dp-0321486811/dp/0321486811
(D Language Foundation is a charity Amazon Smile recognizes).
The dragon book is really really showing it's age these days so I
would highly recommend getting a copy but not reading it fully.
"Engineering a compiler" is much better pedagogically. The dragon
book barely mentions SSA for example, although the sections they
did properly bother to update towards the end are quite
interesting.
"Crafting interpreters" is quite good, I recommend it for
learning how to actually write a parser without getting bogged
down in totally useless theory.
Stephen Muchnick's "Advanced Compiler Design and Implementation"
is *the* bible for optimizations, but uses a very weird
unimplemented language so be careful for bugs.
"Optimizing Compilers for Modern Architectures: A
Dependence-based Approach" is the only book I'm aware of that
actually covers even the beginnings of modern loop optimizations
thoroughly. Even this however is still somewhat set back by it
being written 20 years ago, the principles are the same but the
instinct is not i.e. memory latency is worse, ILP is much better.
What all of these books have in common, by the way, is that they
were all written at a time when it was assumed that x86 would go
the way of the dodo. So there is a somewhat significant deviation
from "theory" and practice in some parts as (say) x86 SIMD is
quite different from how the authors of the aforementioned book
expected the world to go.