Code Generation Flashcards
What are the 3 main components of code generation?
- Instruction Selection
- Register Allocation
- Instruction Scheduling
What is Instruction Selection?
Essentially pattern matching statements in the Intermediate Representation to statements in the target code
Makes locally optimal choices
Assumes we have enough registers
How might we optimise integer multiplication?
We can convert the problem into a series of bit shifts and additions, these operations are a lot quicker than multiplying.
What does a pre-call do?
Allocate memory for a procedure to be called
What does the Prologue do?
Initialises variables at the start of a function call
Why are function calls problematic?
Though they make the programmer’s life easier,
There is a significant overhead when calling and exiting the function
What is a live range?
The interval between a variable’s definition and its last use
What is top-down register allocation?
Reserve registers for the most frequently used values.
All other values are loaded from memory when needed
What is bottom up register allocation?
We assign values to registers when the values become live,
If there are no registers available, we choose the register whose value will be used latest in the future, and save its value in memory (spilling)
What is spilling?
This is when there are no free registers left, so we must move values to memory
E.g If we have 10 live values, but only 9 registers
How do you compute the priority function used in Instruction Scheduling?
weight = latency + max(weight of children)