This patch changes the pass ordering to run PEI *before* register allocation. That's unconventional; normally PEI runs after register allocation to knows how much space to allocate for spills. However, on WebAssembly we're using register coloring rather than allocation, so we never spill anything.
This fixes a tricky case where code at the end of the function is stackified, and then later an epilogue gets inserted into the middle of it, because LLVM doesn't know that it can't insert code there. Similarly, it obviates the need for the tricky code to insert frame index code in the right place.
Another benefit of running it early is that it exposes prologue, epilogue, and frame-index code to register stackifying and coloring. In PR27357 I suggested that perhaps we could run the stackifier twice, however with the patch here we don't need to do that.
The patch here makes the following additional changes to make this work:
- It introduces a ReplacePhysRegs pass which replaces phys regs like SP32 and FP32 with virtual registers. This is done after PEI, at which point we don't need them as physical registers anymore, and making them virtual registers exposes them to stackification.
- It makes wasm's PEI code maintain SSA form, because it now runs before SSA lowering. There were a few places where it reused registers; I fixed it to create a new register for each def.
- It removes the explicit stackifying from prolog/epilog/frame-index expansion code. I know I previously advocated for having that code there, but with the approach in this patch, it's not needed anymore.
- It eliminates the physreg numbering support, because there are no more phys regs after the ReplacePhysRegs pass.