How to simply split MachineBasicBlock ?


I am developing some machine function pass.

I want to split MachineBasicBlcok when I find some specific machine instruction.

But I don’t insert or delete any machine instruction.

I just “simply” , “purely” split the MachineBasicBlcok.

(So, I stole the idea from ARM64BranchRelaxation::splitBlockBeforeInstr.)

This is my code :

// I would pass call instruction to this function

void split_mbb(MachineInstr* mi){

MachineBasicBlock* mbb=mi->getParent();
MachineFunction* mf=mbb->getParent();
MachineBasicBlock* new_mbb=mf->CreateMachineBasicBlock(mbb->getBasicBlock());

MachineFunction::iterator mbb_it(mbb);

Originally, mi is in BB.
(mi would be a call instruction)
(do not consider mi is a branch instruction)
BB → BB1 , BB2

Then, I split BB, mi is the first instruction of BB2.
And the instructions before mi are in BB1.

But now, I use my machine function pass to compile some test programs.

And these test programs can’t execute , always segment fault.

Is there any problem in my split_mbb ?

How to “simply” split MachineBasicBlock ?

Thank you !!

Did you transfer the successors of BB1 to BB2 and add BB2 as a successor of BB1? This note in code you referenced refers to that “NOTE: Successor list of the original BB is out of date after this function, and must be updated by the caller!”

See this code in ARMConstantIslands::splitBlockBeforeInstr

// Update the CFG. All succs of OrigBB are now succs of NewBB.

// OrigBB branches to NewBB.

Thank You !!
Help me a lot !!

Craig Topper <> 於 2020年3月13日 週五 下午2:36寫道: