C
C#2y ago
Ezlanding

❔ Optimize Compiler Code Generation

I am writing a compiler and I am almost done with all the base syntax/functionality, and am up to optimization. Right now, the compiler isn’t optimized at all. No constant folding, no function inlining, and dead code is still emitted Where can I learn about the optimization steps above and other optimizations for my compiler’s code generation? How helpful is the Dragon Book? (I already have the book, but am not up to a point where it talked about optimization yet). Any good articles/videos/resources?
8 Replies
Anton
Anton2y ago
optimization is a deep topic, better use a library
Ezlanding
EzlandingOP2y ago
What libraries would help me with this? (LLVM?) even if I end up using a library, I still would like to learn about optimization further, so do you have any recommendations?
Anton
Anton2y ago
idk, from what I heard people who write actual compilers for non toy programming languages just use llvm as a black box from theory standpoint, I don't know, I haven't learned that
Thinker
Thinker2y ago
@T = (Q, Σ, Γ, q₀, *, δ)
LPeter1997
LPeter19972y ago
The Dragon Book covers many-many things, but as everything Dragon Book, it's really dense and super formal What I'd do is take a list of optimizations (there's a wiki page listing quite a few), have some casual reading on the ones you are interested in, and once you have a basic understanding, then dive into the Dragon Book Some essentials to look up: - Intermediate representation (IR) of code, aka. on what form do we optimize? Relevant terms: three-address code, register machine, stack machine, SSA - Structure of low-level IR codes, basic blocks, control flow graph - Essential block-local optimization techniques: available expression, copy propagation, dead code elimination - Various beginner-friendly optimizations: unreachable code cutting in the CFG, jump threading, jump inlining, and TCO if you feel adventurous - Adapting block-local optimizations to procedure level (here I really recommend looking into the topic of data-flow analysis)
Ezlanding
EzlandingOP2y ago
Sounds like a great idea, thanks!
LPeter1997
LPeter19972y ago
We are writing an optimizing compiler currently and we are planning to do automatic vectorization, so we are extremely deep in the rabbit-hole 😄
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server