Chaitin's Algorithm for register allocation: How many colors are used with R registers?

170 views Asked by At

In the lecture I have for register allocation/Chaitin's Algorithm, it seems like we construct an interference graph and then try to find a k-coloring of that graph, where k=R if we can use R registers in the target architecture. However, if we spill a value, wouldn't that mean that we need an additional register to load values from memory prior to using them in instructions and can thus only use k=R-1 values for Chaitin's Algorithm?

1

There are 1 answers

0
Johan On

You can still use k=R. When you spill a value you add spill code that store and retrieve the value (usually on the stack, but other alternatives exists). This will replace the original virtual register with a high degree of interference with a number of new virtual registers that exists only for a short time and (hopefully) have a lower degree. You can now make another try at coloring and if it still fails you repeat the spill process until you succeed.