In branch relaxation pass, j's with offset over 1MiB will be relaxed to jump pseudo-instructions.
This patch allocates a stack slot for functions with a size greater than 1MiB. If the register scavenger cannot find a scratch register for jump, spill a register to the slot before the jump and restore it after the jump.
.mbb: foo j .dest_bb bar bar bar .dest_bb: baz
The above code will be relaxed to the following code.
.mbb: foo sd s11, 0(sp) jump .restore_bb, s11 bar bar bar j .dest_bb .restore_bb: ld s11, 0(sp) .dest_bb: baz
Depends on D129999.
You might want to consider using a more conservative estimate for conditional branches, since they can be relaxed to unconditional branches. (I know we don't do this in the ARM function you borrowed this from, but probably we should.)