diff options
author | Whitney Tsang <whitney.uwaterloo@gmail.com> | 2019-07-08 18:30:35 +0000 |
---|---|---|
committer | Whitney Tsang <whitney.uwaterloo@gmail.com> | 2019-07-08 18:30:35 +0000 |
commit | 7d8f30e6b2f27d55d4a14392951e4a61d7598767 (patch) | |
tree | 3714e442c8fce8dd31a825ad4e8b07c541311b18 /llvm/lib/Transforms/Utils/CloneFunction.cpp | |
parent | 7023bdc46fbbd7f5c4f458488497888f767cd2e0 (diff) | |
download | bcm5719-llvm-7d8f30e6b2f27d55d4a14392951e4a61d7598767.tar.gz bcm5719-llvm-7d8f30e6b2f27d55d4a14392951e4a61d7598767.zip |
Keep the order of the basic blocks in the cloned loop as the original
loop
Summary:
Do the cloning in two steps, first allocate all the new loops, then
clone the basic blocks in the same order as the original loop.
Reviewer: Meinersbur, fhahn, kbarton, hfinkel
Reviewed By: hfinkel
Subscribers: hfinkel, hiraditya, llvm-commits
Tag: https://reviews.llvm.org/D64224
Differential Revision:
llvm-svn: 365366
Diffstat (limited to 'llvm/lib/Transforms/Utils/CloneFunction.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/CloneFunction.cpp | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp index 9e160342c8c..1026c9d3703 100644 --- a/llvm/lib/Transforms/Utils/CloneFunction.cpp +++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp @@ -765,37 +765,38 @@ Loop *llvm::cloneLoopWithPreheader(BasicBlock *Before, BasicBlock *LoopDomBB, DT->addNewBlock(NewPH, LoopDomBB); for (Loop *CurLoop : OrigLoop->getLoopsInPreorder()) { - for (BasicBlock *BB : CurLoop->getBlocks()) { - if (CurLoop != LI->getLoopFor(BB)) - continue; + Loop *&NewLoop = LMap[CurLoop]; + if (!NewLoop) { + NewLoop = LI->AllocateLoop(); - Loop *&NewLoop = LMap[CurLoop]; - if (!NewLoop) { - NewLoop = LI->AllocateLoop(); + // Establish the parent/child relationship. + Loop *OrigParent = CurLoop->getParentLoop(); + assert(OrigParent && "Could not find the original parent loop"); + Loop *NewParentLoop = LMap[OrigParent]; + assert(NewParentLoop && "Could not find the new parent loop"); - // Establish the parent/child relationship. - Loop *OrigParent = CurLoop->getParentLoop(); - assert(OrigParent && "Could not find the original parent loop"); - Loop *NewParentLoop = LMap[OrigParent]; - assert(NewParentLoop && "Could not find the new parent loop"); + NewParentLoop->addChildLoop(NewLoop); + } + } - NewParentLoop->addChildLoop(NewLoop); - } + for (BasicBlock *BB : OrigLoop->getBlocks()) { + Loop *CurLoop = LI->getLoopFor(BB); + Loop *&NewLoop = LMap[CurLoop]; + assert(NewLoop && "Expecting new loop to be allocated"); - BasicBlock *NewBB = CloneBasicBlock(BB, VMap, NameSuffix, F); - VMap[BB] = NewBB; + BasicBlock *NewBB = CloneBasicBlock(BB, VMap, NameSuffix, F); + VMap[BB] = NewBB; - // Update LoopInfo. - NewLoop->addBasicBlockToLoop(NewBB, *LI); - if (BB == CurLoop->getHeader()) - NewLoop->moveToHeader(NewBB); + // Update LoopInfo. + NewLoop->addBasicBlockToLoop(NewBB, *LI); + if (BB == CurLoop->getHeader()) + NewLoop->moveToHeader(NewBB); - // Add DominatorTree node. After seeing all blocks, update to correct - // IDom. - DT->addNewBlock(NewBB, NewPH); + // Add DominatorTree node. After seeing all blocks, update to correct + // IDom. + DT->addNewBlock(NewBB, NewPH); - Blocks.push_back(NewBB); - } + Blocks.push_back(NewBB); } for (BasicBlock *BB : OrigLoop->getBlocks()) { |