11.2 Optimising Compilers Flashcards

1
Q

Where does the optimiser fit in within the compiler pipeline

A

Middle: After front-end (AST), before backend (Binary).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are 3 different angles an optimiser could optimise for

A
  • Execution time
  • Memory or binary size
  • Power consumption
  • Example tradeoff between time and power is loop unrolling (more mem = more power etc.).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are compiler optimisation flags used for

A
  • Choose which optimisation and what level
  • Ofast can have up to 6x improvement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does the optimser (compiler) transform the IR (ie AST) (and what is a basic block)

A
  • Transforms IR in-place replacing unop with op
  • Basic block: series of statements (no branches)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is subexpression elimination (compiler). Use it on the following code

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is dead code elimination (compiler). Use it on the following code

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is constant folding (compiler). Use it on the following code

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is loop-invariant hoisting (compiler), use it on the following code

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is function inlining (compiler). Use it on the following code

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Strength reduction (compiler): What is a loop induction variable (linear)

A
  • Replacing expensive loop multiplications with additions (1 cycle instead of 3)
  • Linear function with i as variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Using a loop induction variable (linear), strength reduce the following code

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the 4 steps of strength reduction (compiler)

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the purpose of register allocation (in terms of an unlimited amount of variables) (and what is register spilling)

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Register allocation: what is the purpose of liveness analysis and how to decide if a variable is live.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the liveness analysis of the following program:

A
16
Q

How does a linear scan determine variable liveness and register allocation:

A
17
Q

What would a linear scan of the following program look like

A
18
Q

What is graph coloring for register allocation

A
19
Q

What would the graph coloring for the following program look like

A