Splitting a MachineBasicBlock in two


I am writing a pre-emit pass on the MI-layer in which I would like to
replace call instructions with a push and a jmp each. Until now, I
figured that I have to do the following things:

1. Split the MachineBasicBlock after the call instruction ==> MBB1, MBB2
2. Delete the call instruction
3. Push address of MBB2
4. Add a jmp to the original call destination at the end of MBB1

Step 1 troubles me. I have no idea how to perform the split correctly.
Maybe I could create a new MachineBasicBlock and copy all the
instructions after the call into it. But then I would also have to
update the CFG manually, no? Is there a better way to do this? Or can
someone point me to some documentation/example code?

Thanks in advance!

Hi Jan,

I think what you are looking for is: MachineBasicBlock::splice (the version with the range).
Then, indeed, you will have to update the CFG.
IIRC you should find examples on how to do that by looking at the uses of splice.