I'm currently writing a toy compiler as a homework, targeted at the MIPS architecture.
There are 18 registers that are generally available when translating from higher-level languages: s0
to s7
which are callee-saved, and t0
to t9
which are caller-saved.
With these 18 registers available, a question emerges: which register should I prefer when performing the translation of a function.
Each set has its pros and cons:
It's clear to me that if I adopt a static strategy on using these registers — whatever the strategy is, like preferring callee-saved registers over caller-saved ones — I will not get the optimal performance since most probably there will be unnecessary register load/stores.
So, is there any good practices of using these two sets of registers?
Here's a better solution than chill's, which allocates registers in a finer granularity:
First we perform liveness analysis for each variable, and: