I am looking into a topic on register allocation in compilers. A widely used algorithm for register allocation is iterative graph coloring by simplification. In the book Modern Compiler Implementation in Java by Andrew W. Appel, chapter 11 on register allocation states:

Each node in the interference graph represents a temporary value.

[...]

Some temporaries are precolored - they represent machine registers. The front end generates these when interfacing to standard calling conventions across module boundaries, for example. For each actual register that is used for some specific purpose, such as the frame pointer, standard-argument-1-register, standard-argument-2-register, and so on, the Codegen or Frame module should use the particular temporary that is permanently bound to that register. For any given color (that is, for any given machine register) there should be only one precolored node of that color.

I don't completely understand the indicated line in the quote above. I can imagine situations where there are multiple temporaries that would be precolored with the same register. For example, the x86 mul instruction stores the result in the EDX:EAX register pair, but functions also return values in the EAX register. So I have different temporaries that have the same color. I would think that those different uses of EAX must be different nodes, or am I wrong?

Could someone explain the highlighted sentence, maybe present some examples?

有帮助吗?

解决方案

In the book, the idea is, you would have a single temporary EAX, which you use both with mul and for the return value. When some value needs to be in a given register, you generate a move from the temporary containing that value to the temporary representing that register; similarly, once a value has arrived in a particular register (for example, a function has returned), you generate a move from the register's temporary to a temporary that will hold that value from then on. See Figure 11.7 in the book.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top