From 4f5d78e9c1d3baba122affbf68e9ee45ca9e0477 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 14 Aug 2007 23:59:17 +0000 Subject: [PATCH] Break infinite loop. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41091 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/CloneLoop.cpp | 32 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/Transforms/Utils/CloneLoop.cpp b/lib/Transforms/Utils/CloneLoop.cpp index 02278b6d282..6e35916c89a 100644 --- a/lib/Transforms/Utils/CloneLoop.cpp +++ b/lib/Transforms/Utils/CloneLoop.cpp @@ -84,22 +84,21 @@ Loop *llvm::CloneLoop(Loop *OrigL, LPPassManager *LPM, LoopInfo *LI, } SmallVector NewBlocks; - SmallVector, 8> LoopNest; - LoopNest.push_back(std::make_pair(OrigL, OrigL->begin())); - - Loop *NewLoop = NULL; - while (!LoopNest.empty()) { - Loop *L = LoopNest.back().first; - Loop::iterator SubLoop = LoopNest.back().second; - - // Handle sub loops. - if (SubLoop != L->end()) { - Loop *SL = *SubLoop; - LoopNest.push_back(std::make_pair(SL, SL->begin())); - } + // Populate loop nest. + SmallVector LoopNest; + LoopNest.push_back(OrigL); + + + Loop *NewParentLoop = NULL; + while (!LoopNest.empty()) { + Loop *L = LoopNest.back(); LoopNest.pop_back(); - NewLoop = new Loop(); + Loop *NewLoop = new Loop(); + + if (!NewParentLoop) + NewParentLoop = NewLoop; + LPM->insertLoop(NewLoop, L->getParentLoop()); // Clone Basic Blocks. @@ -122,6 +121,9 @@ Loop *llvm::CloneLoop(Loop *OrigL, LPPassManager *LPM, LoopInfo *LI, CloneDominatorInfo(BB, ValueMap, DT, DF); } + // Process sub loops + for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I) + LoopNest.push_back(*I); } // Remap instructions to reference operands from ValueMap. @@ -145,5 +147,5 @@ Loop *llvm::CloneLoop(Loop *OrigL, LPPassManager *LPM, LoopInfo *LI, Function *F = Latch->getParent(); F->getBasicBlockList().insert(Latch, NewBlocks.begin(), NewBlocks.end()); - return NewLoop; + return NewParentLoop; } -- 2.34.1