[llvm-dev] How to simply split MachineBasicBlock ?

PenYiWang via llvm-dev llvm-dev at lists.llvm.org
Thu Mar 12 22:19:42 PDT 2020


Hi

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);
  mf->insert(mbb_it,new_mbb);
  new_mbb->splice(new_mbb->end(),mbb,mbb->begin(),mi);
}

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 !!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200313/846b7b0e/attachment-0001.html>


More information about the llvm-dev mailing list