โ Compiler Design learning pathCompiler Design ยท Module 9 of 10
Code generation and runtime
Registers, instruction selection and memory.
๐ Key ideas
- The code generator maps IR to machine instructions: instruction selection, register allocation and instruction ordering.
- Register allocation is often solved as graph colouring; values that do not fit are spilled to memory.
- Runtime environment: stack for function calls (activation records), heap for dynamic memory.
- An activation record holds parameters, return address, local variables and saved registers.
- 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