How to fix RegisterPressureTracker after inserting a new Machine Instruction during MachineScheduler Pass


I’m doing some MI scheduling optimization in which involves creating a new machine instruction and insert it into the machine basic block that is being scheduled. The new MI created is using a new virtual register which means at least I have to make registerPressureTracker be aware of it.

After a little digging, I found that in RegisterPressure.h

LiveRegSet LiveRegs is responsible for keeping track of all the live virtual/physical registers, but it’s using two sparseSets that only allow to resize before any element is inserted. But I have to insert the new instruction after calling buildDAGWithRegPressure() in which it calls initRegPressure()

So I’m wondering what’s the right approach of doing this, and also is there any other book keeping structure that I have to update.