Resource
Dataflow Analysis
A simple problem we want to solve looks like
which is equivalent to
It’s indeed intuitive to human that this optimization is correct, but it raises complexity when compiler deals with this problem. The above example used two techiques Constant Propagation and Copy Propagation.
Why?
Because the Goal is to optimize the program while retaining the correctness. Branching will greatly raise the cost of retaining correctness. So the Control Flow Graph comes into play. Whatever optimization we do, we need to ensure all path results in the same as before.
Instruction Scheduling
Cache
Consider we only have one register, here is a snippet.
Notice when print a we need to reload a from memory since cache is tiny. However, it’s possible to rewrite the program into
By some simple Data Dependence Analysis, we can assure out optimization is correct.
Software pipelining
Consider a loop.
By default, this loop will run sequentially on one core. But it’s obvious that we want to achieve parallism when we have multiple processors. However, we do need to introduce complexity to handle data dependency and resource constraint.
Grabage Collection
Reference Counting and Mark and Sweep are way too introductory.
A interesting topic is generational garbage collection. The assumption is variables are mostly young (create and delete soon). Whenver objects that are reachable after one garbage collection pass, it would probably pass the next garbage collection pass. So it’s wise to ignore them in the next few garbage collection pass. So we gain the perfomance by ignoring things like global objects.