Here is the code snippet that I am using to create the PHIs in the loop according to the PHIs in the new preheader. At this point I have already redirected the loop backedge and removed the preheader from the loop. for (BasicBlock::iterator II = loopHeaderBB->begin(); (PN=dyn_cast<PHINode>(II)); ++II) { // remove loop back PHI and add it to split BB errs()<<*II<<"\n"; PHINode *newPHIvalue = PHINode::Create(PN->getType(), 2, PN->getName().str(), splitBB->getFirstInsertionPt()); int IDX = PN->getBasicBlockIndex(splitBB); while (IDX != -1) { Value *oldValue = PN->getIncomingValue((unsigned(IDX))); PN->removeIncomingValue(IDX, false); newPHIvalue->addIncoming(oldValue, loopLatchBB); newPHIvalue->addIncoming(PN, loopHeaderBB); IDX = PN->getBasicBlockIndex(splitBB); } } On Wed, Mar 7, 2012 at 4:04 PM, Ryan Taylor <ryta1203 at gmail.com> wrote:> I have attached a case of what I am trying to do, I'm pretty sure I'm just > missing some simple API call. In the cfg you can see that although Im > setting "lsr.iv441" as "lsr.iv44" from for.body.387.i it's not propagating > that through the block or graph. > > > On Wed, Mar 7, 2012 at 12:03 PM, Ryan Taylor <ryta1203 at gmail.com> wrote: > >> I am splitting a one BB loop into two BB. >> >> Basically, the one loop BB has 3 incoming values, one form back edge two >> from other edges. I want to extract the PHIs from the other two edges out >> into it's own BB and delete that from the loop, then redirect the backedge >> to the loopbody (non extracted portion) and create a new PHI coming from >> the extracted BB and the backedge. >> >> I can do this; however, the PHIs following in all the other BBs are not >> getting updated, neither are the statements in the loopbody. >> >> What is the easieset way to propagate these changes downward? >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120307/33f31947/attachment.html>
I guess I thought that once I redirected the branches and created new PHIs that LLVM would correct the variable usage when I return true (changed CFG) from the pass. Is this not the case? On Wed, Mar 7, 2012 at 4:08 PM, Ryan Taylor <ryta1203 at gmail.com> wrote:> Here is the code snippet that I am using to create the PHIs in the loop > according to the PHIs in the new preheader. At this point I have already > redirected the loop backedge and removed the preheader from the loop. > > for (BasicBlock::iterator II = loopHeaderBB->begin(); > (PN=dyn_cast<PHINode>(II)); ++II) { > // remove loop back PHI and add it to split BB > errs()<<*II<<"\n"; > PHINode *newPHIvalue = PHINode::Create(PN->getType(), 2, > PN->getName().str(), splitBB->getFirstInsertionPt()); > int IDX = PN->getBasicBlockIndex(splitBB); > while (IDX != -1) { > Value *oldValue = PN->getIncomingValue((unsigned(IDX))); > PN->removeIncomingValue(IDX, false); > newPHIvalue->addIncoming(oldValue, loopLatchBB); > newPHIvalue->addIncoming(PN, loopHeaderBB); > IDX = PN->getBasicBlockIndex(splitBB); > > } > } > > On Wed, Mar 7, 2012 at 4:04 PM, Ryan Taylor <ryta1203 at gmail.com> wrote: > >> I have attached a case of what I am trying to do, I'm pretty sure I'm >> just missing some simple API call. In the cfg you can see that although Im >> setting "lsr.iv441" as "lsr.iv44" from for.body.387.i it's not propagating >> that through the block or graph. >> >> >> On Wed, Mar 7, 2012 at 12:03 PM, Ryan Taylor <ryta1203 at gmail.com> wrote: >> >>> I am splitting a one BB loop into two BB. >>> >>> Basically, the one loop BB has 3 incoming values, one form back edge two >>> from other edges. I want to extract the PHIs from the other two edges out >>> into it's own BB and delete that from the loop, then redirect the backedge >>> to the loopbody (non extracted portion) and create a new PHI coming from >>> the extracted BB and the backedge. >>> >>> I can do this; however, the PHIs following in all the other BBs are not >>> getting updated, neither are the statements in the loopbody. >>> >>> What is the easieset way to propagate these changes downward? >>> >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120308/2b1adad9/attachment.html>
>From my experience, this is not the case really.What you can do is call 'replaceUsesOfWith' on every user of the PHI'ed variable (lsr.iv44) that is inside the dominator tree of the new basicblock (for.body.387.i.split). LLVM has a dominator tree analysis that you can use to do it. 2012/3/8 Ryan Taylor <ryta1203 at gmail.com>> I guess I thought that once I redirected the branches and created new PHIs > that LLVM would correct the variable usage when I return true (changed CFG) > from the pass. Is this not the case? > > > On Wed, Mar 7, 2012 at 4:08 PM, Ryan Taylor <ryta1203 at gmail.com> wrote: > >> Here is the code snippet that I am using to create the PHIs in the loop >> according to the PHIs in the new preheader. At this point I have already >> redirected the loop backedge and removed the preheader from the loop. >> >> for (BasicBlock::iterator II = loopHeaderBB->begin(); >> (PN=dyn_cast<PHINode>(II)); ++II) { >> // remove loop back PHI and add it to split BB >> errs()<<*II<<"\n"; >> PHINode *newPHIvalue = PHINode::Create(PN->getType(), 2, >> PN->getName().str(), splitBB->getFirstInsertionPt()); >> int IDX = PN->getBasicBlockIndex(splitBB); >> while (IDX != -1) { >> Value *oldValue = PN->getIncomingValue((unsigned(IDX))); >> PN->removeIncomingValue(IDX, false); >> newPHIvalue->addIncoming(oldValue, loopLatchBB); >> newPHIvalue->addIncoming(PN, loopHeaderBB); >> IDX = PN->getBasicBlockIndex(splitBB); >> >> } >> } >> >> On Wed, Mar 7, 2012 at 4:04 PM, Ryan Taylor <ryta1203 at gmail.com> wrote: >> >>> I have attached a case of what I am trying to do, I'm pretty sure I'm >>> just missing some simple API call. In the cfg you can see that although Im >>> setting "lsr.iv441" as "lsr.iv44" from for.body.387.i it's not propagating >>> that through the block or graph. >>> >>> >>> On Wed, Mar 7, 2012 at 12:03 PM, Ryan Taylor <ryta1203 at gmail.com> wrote: >>> >>>> I am splitting a one BB loop into two BB. >>>> >>>> Basically, the one loop BB has 3 incoming values, one form back edge >>>> two from other edges. I want to extract the PHIs from the other two edges >>>> out into it's own BB and delete that from the loop, then redirect the >>>> backedge to the loopbody (non extracted portion) and create a new PHI >>>> coming from the extracted BB and the backedge. >>>> >>>> I can do this; however, the PHIs following in all the other BBs are not >>>> getting updated, neither are the statements in the loopbody. >>>> >>>> What is the easieset way to propagate these changes downward? >>>> >>> >>> >> > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120308/953ea5f2/attachment.html>