โ† Compiler Design learning path
Compiler Design ยท Module 9 of 10

Code generation and runtime

Registers, instruction selection and memory.

๐Ÿ“– Key ideas

  1. The code generator maps IR to machine instructions: instruction selection, register allocation and instruction ordering.
  2. Register allocation is often solved as graph colouring; values that do not fit are spilled to memory.
  3. Runtime environment: stack for function calls (activation records), heap for dynamic memory.
  4. An activation record holds parameters, return address, local variables and saved registers.
  5. Peephole optimisation improves short instruction sequences after generation.
๐Ÿ’ก Real-life example: Register allocation is like seating guests at a table with few chairs: those not seated must wait in the next room (memory) and are slower to reach.
Register allocationAssigning variables to CPU registers
SpillingStoring a value in memory when registers run out
Activation recordStack frame for one function call
Peephole optimisationImproving short instruction windows