11.2 Optimising Compilers Flashcards
Where does the optimiser fit in within the compiler pipeline
Middle: After front-end (AST), before backend (Binary).
What are 3 different angles an optimiser could optimise for
- Execution time
- Memory or binary size
- Power consumption
- Example tradeoff between time and power is loop unrolling (more mem = more power etc.).
What are compiler optimisation flags used for
- Choose which optimisation and what level
- Ofast can have up to 6x improvement
How does the optimser (compiler) transform the IR (ie AST) (and what is a basic block)
- Transforms IR in-place replacing unop with op
- Basic block: series of statements (no branches)
What is subexpression elimination (compiler). Use it on the following code
What is dead code elimination (compiler). Use it on the following code
What is constant folding (compiler). Use it on the following code
What is loop-invariant hoisting (compiler), use it on the following code
What is function inlining (compiler). Use it on the following code
Strength reduction (compiler): What is a loop induction variable (linear)
- Replacing expensive loop multiplications with additions (1 cycle instead of 3)
- Linear function with i as variable
Using a loop induction variable (linear), strength reduce the following code
What are the 4 steps of strength reduction (compiler)
What is the purpose of register allocation (in terms of an unlimited amount of variables) (and what is register spilling)
- Deciding which variable is stored in which register (or RAM / Disk)
- By finding out which variables are live.
- Register spilling: Not enough registers => some variables in RAM
Register allocation: what is the purpose of liveness analysis and how to decide if a variable is live.