<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV> </DIV>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">Hello,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">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:<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">My question is about Machine Basic Block Duplication:<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt"><o:p> </o:p></SPAN></DIV>
<P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1; tab-stops: list .5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-fareast-font-family: Arial"><SPAN style="mso-list: Ignore">-<SPAN style="FONT: 7pt 'Times New Roman'">          </SPAN></SPAN></SPAN><SPAN dir=ltr><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">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 <SPAN style="mso-spacerun: yes"> </SPAN>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<o:p></o:p></SPAN></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">What I am trying to do is to use exact set of virtual registers in both the blocks. Will it cause any issues? <o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt"><o:p> </o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">Here is the snippet of what the code does:<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt"> MachineBasicBlock* I;<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt"> MachineBasicBlock* copy;<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt"><o:p> </o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">copy = createMachineBasicBlock(I->getBasicBlock());<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt"><o:p> </o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">Clone all the instrs from I --> copy<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">Copy all the successor of ‘I’ to ‘copy’ as well<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt"><o:p> </o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">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):<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt"><o:p> </o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">MachineFunction::iterator It = (predMBB+1);<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">MF.insert(It,copy);<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">predMBB->addSuccessor(copy);<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">predMBB->removeSuccessor(I)</SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt"></SPAN> </DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">MF.RenumberBlocks();</SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt"><o:p> </o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">Am I missing anything here?<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt"><o:p> </o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">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.<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt"><o:p> </o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">Appreciate your help a lot,<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt"><o:p> </o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">Thanks,<o:p></o:p></SPAN></DIV>
<P style="MARGIN: 0in 0in 0pt 0.5in" class=MsoNormal><SPAN style="FONT-FAMILY: Arial; FONT-SIZE: 10pt">Hisham<o:p></o:p></SPAN></DIV>
<DIV><BR><BR> </DIV>
<BLOCKQUOTE style="BORDER-LEFT: rgb(16,16,255) 2px solid; PADDING-LEFT: 5px; MARGIN-LEFT: 5px">
<DIV class=plainMail> </DIV></BLOCKQUOTE></td></tr></table><br>