GCC for asm Experts (and C/C++ Intermediates) - Part 3
[ Atariscne.org - News ] GCC for asm Experts (and C/C++ Intermediates) - Part 3
How GCC Actually Compiles
GCC originally stood for GNU C Compiler. Today it is the GNU Compiler Collection, with frontends for C, C++, Fortran, Ada, Go and more, a shared middle-end, and many backends. VAX and m68k were the first in 1987; today the list spans everything from modern x86-64 and ARM to legacy PDP-11 and MSP430. Each frontend parses its language and lowers it to a common intermediate representation. From there, the shared transformation passes take over, most of them entirely generic regardless of whether the target is a modern 64-core server or our humble 68000.
What happens between "C text goes in" and "assembly comes out" is roughly 360 of these passes, each rewriting the intermediate representation. Some optimize. Some check for errors. Some transform for consistency. Most do a little of everything. We will focus on the ones where our beloved 68000 needs the most help. I have put together a summary of all GCC passes for reference.
Debugging this pipeline is where the fun and the pain live. When the output is wrong, which of the 360 passes is at fault? Often it is not the obvious one; a bad decision in pass 47 might not surface as wrong, or inefficient, code until pass 180. Understanding the stages, even roughly, is the key to knowing where to look.