I’m trying to add a new label after an instruction, in a post reg alloc pass.
The current solution I have is:
// Create a new label MachineBasicBlock *NewLabel = MF.CreateMachineBasicBlock(); // Add it to the machine function - after the instruction MF.insert(std::next(MBBI), NewLabel); // Copy the successors of the current label to the new label for (auto SI = MBBI->succ_begin(), SE = MBBI->succ_end(); SI != SE; ++SI) NewLabel->copySuccessor(&*MBBI, SI); // Add the new label as a successor to the new label (still need to check if this is needed) NewLabel->addSuccessor(NewLabel); // Transfer the rest of the instructions to NewLabel NewLabel->splice(NewLabel->begin(), &*MBBI, std::next(MI), MBBI->end());
And it seems to work?
I don’t think that copying the probability of the successors is the right way, but I could not figure any better than that.
Is there a better way to do it?