Memory stores "dirtying" clean values in register allocation

97 Views Asked by At

I have a couple questions concerning register allocation, and specifically dirty/clean/rematerializable values. As I understand it: a dirty value must be spilled and restored before use; a clean value is from a memory load and just has to be restored from memory; and a rematerializable value is from a constant load and just has to be restored by loading a constant. My questions are thus:

1) It is easy to determine if a value is clean, but how can we determine the memory location it has been loaded from? We know what register holds the memory location, but the value in that register may change. Do we only count as clean something loaded from a constant location or rematerializable location?

2) Surely a store can dirty a clean value. If r0 was loaded from memory location 1024, and we just had a store to 1024, r0 is now dirty. Worse, what about those registers we did not spill because they held clean value, and are now overwritten? Something like the following sequence.

  1. Load the value from memory 1024 into r0.
  2. Run out of physical registers, decide to spill r0. Since it is clean, we don't need to insert spill code.
  3. Store a value from r1 to memory
  4. Try to restore r0, but now the value in memory has changed.
0

There are 0 best solutions below