PreRewrite Machine Pass

Hello everybody,

as the title says i’m writing a MachinePass that’s runs just before the register rewriter.
What this pass should do is to replace (when a specific condition holds) the physical register assigned to a virtual register with a new physical register.
This condition doesn’t hold “too many times”, and usually changing the mapping once is enough.
After reading some of the register allocators code i’ve been able to write this (c++ish):

for NewPhysReg in AllocationOrder:

if (NewPhysReg == PrevPhysReg)

if(Matrix->checkInterference(VirtRegInterval, NewPhysReg) == LiveRegMatrix::IK_Free)

Matrix->assign(VirtRegInterval, NewPhysReg);

The problem now is: what should i do when all the “new” physical register have some interference?

Any help is very appreciated!