[LLVMdev] Question About Cloning Machine Basic Block

Hisham Chowdhury hisham_chow at yahoo.com
Wed Apr 14 17:30:00 PDT 2010


 
Hello,
I am trying to clone a machine basic block when I ran into some issues, where I am not able to make some headway. Any of yours help is highly appreciated here:
My question is about Machine Basic Block Duplication:
 
-          Is there a utility to clone a MachineBasicBlock in LLVM? I found utility to clone machineInstrs, but couldn’t find similar utility for MachineBasicBlock. So, I created a utility myself for cloning a MachineBasicBlock, but I am running into an issue when LLVM is trying to  destroy the use list for registers (RemoveRegOperandsFromUseLists--> RemoveRegOperandFromRegInfo()-->NextOp->getReg() – where nextOp seems like invalid but not NULL). Its hitting assert in one of the registers that is getting reused in the cloned block
What I am trying to do is to use exact set of virtual registers in both the blocks. Will it cause any issues? 
 
Here is the snippet of what the code does:
 MachineBasicBlock* I;
 MachineBasicBlock* copy;
 
copy = createMachineBasicBlock(I->getBasicBlock());
 
Clone all the instrs from I --> copy
Copy all the successor of ‘I’ to ‘copy’ as well
 
If ‘I’ has 2 predecessors, then update the succ list of the second pred to point to ‘copy’ and insert ‘copy’ after the second pred (‘I’ physically resides after the first pred):
 
MachineFunction::iterator It = (predMBB+1);
MF.insert(It,copy);
predMBB->addSuccessor(copy);
predMBB->removeSuccessor(I)
 
MF.RenumberBlocks();
 
Am I missing anything here?
 
Please note: I am doing this step as a pass just before the asm printer pass in the target machine layer after all the instructions has been generated, registers has been allocated.
 
Appreciate your help a lot,
 
Thanks,
Hisham


 

 


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100414/7615143f/attachment.html>


More information about the llvm-dev mailing list