LLVM API Documentation

LoopInfo.cpp

Go to the documentation of this file.
00001 //===- LoopInfo.cpp - Natural Loop Calculator -----------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the LoopInfo class that is used to identify natural loops
00011 // and determine the loop depth of various nodes of the CFG.  Note that the
00012 // loops identified may actually be several natural loops that share the same
00013 // header node... not just a single natural loop.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #include "llvm/Analysis/LoopInfo.h"
00018 #include "llvm/Constants.h"
00019 #include "llvm/Instructions.h"
00020 #include "llvm/Analysis/Dominators.h"
00021 #include "llvm/Assembly/Writer.h"
00022 #include "llvm/Support/CFG.h"
00023 #include "llvm/ADT/DepthFirstIterator.h"
00024 #include <algorithm>
00025 #include <iostream>
00026 using namespace llvm;
00027 
00028 static RegisterAnalysis<LoopInfo>
00029 X("loops", "Natural Loop Construction", true);
00030 
00031 //===----------------------------------------------------------------------===//
00032 // Loop implementation
00033 //
00034 bool Loop::contains(const BasicBlock *BB) const {
00035   return std::find(Blocks.begin(), Blocks.end(), BB) != Blocks.end();
00036 }
00037 
00038 bool Loop::isLoopExit(const BasicBlock *BB) const {
00039   for (succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB);
00040        SI != SE; ++SI) {
00041     if (!contains(*SI))
00042       return true;
00043   }
00044   return false;
00045 }
00046 
00047 /// getNumBackEdges - Calculate the number of back edges to the loop header.
00048 ///
00049 unsigned Loop::getNumBackEdges() const {
00050   unsigned NumBackEdges = 0;
00051   BasicBlock *H = getHeader();
00052 
00053   for (pred_iterator I = pred_begin(H), E = pred_end(H); I != E; ++I)
00054     if (contains(*I))
00055       ++NumBackEdges;
00056 
00057   return NumBackEdges;
00058 }
00059 
00060 /// isLoopInvariant - Return true if the specified value is loop invariant
00061 ///
00062 bool Loop::isLoopInvariant(Value *V) const {
00063   if (Instruction *I = dyn_cast<Instruction>(V))
00064     return !contains(I->getParent());
00065   return true;  // All non-instructions are loop invariant
00066 }
00067 
00068 void Loop::print(std::ostream &OS, unsigned Depth) const {
00069   OS << std::string(Depth*2, ' ') << "Loop Containing: ";
00070 
00071   for (unsigned i = 0; i < getBlocks().size(); ++i) {
00072     if (i) OS << ",";
00073     WriteAsOperand(OS, getBlocks()[i], false);
00074   }
00075   OS << "\n";
00076 
00077   for (iterator I = begin(), E = end(); I != E; ++I)
00078     (*I)->print(OS, Depth+2);
00079 }
00080 
00081 void Loop::dump() const {
00082   print(std::cerr);
00083 }
00084 
00085 
00086 //===----------------------------------------------------------------------===//
00087 // LoopInfo implementation
00088 //
00089 void LoopInfo::stub() {}
00090 
00091 bool LoopInfo::runOnFunction(Function &) {
00092   releaseMemory();
00093   Calculate(getAnalysis<ETForest>());    // Update
00094   return false;
00095 }
00096 
00097 void LoopInfo::releaseMemory() {
00098   for (std::vector<Loop*>::iterator I = TopLevelLoops.begin(),
00099          E = TopLevelLoops.end(); I != E; ++I)
00100     delete *I;   // Delete all of the loops...
00101 
00102   BBMap.clear();                             // Reset internal state of analysis
00103   TopLevelLoops.clear();
00104 }
00105 
00106 
00107 void LoopInfo::Calculate(ETForest &EF) {
00108   BasicBlock *RootNode = EF.getRoot();
00109 
00110   for (df_iterator<BasicBlock*> NI = df_begin(RootNode),
00111          NE = df_end(RootNode); NI != NE; ++NI)
00112     if (Loop *L = ConsiderForLoop(*NI, EF))
00113       TopLevelLoops.push_back(L);
00114 }
00115 
00116 void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
00117   AU.setPreservesAll();
00118   AU.addRequired<ETForest>();
00119 }
00120 
00121 void LoopInfo::print(std::ostream &OS, const Module* ) const {
00122   for (unsigned i = 0; i < TopLevelLoops.size(); ++i)
00123     TopLevelLoops[i]->print(OS);
00124 #if 0
00125   for (std::map<BasicBlock*, Loop*>::const_iterator I = BBMap.begin(),
00126          E = BBMap.end(); I != E; ++I)
00127     OS << "BB '" << I->first->getName() << "' level = "
00128        << I->second->getLoopDepth() << "\n";
00129 #endif
00130 }
00131 
00132 static bool isNotAlreadyContainedIn(Loop *SubLoop, Loop *ParentLoop) {
00133   if (SubLoop == 0) return true;
00134   if (SubLoop == ParentLoop) return false;
00135   return isNotAlreadyContainedIn(SubLoop->getParentLoop(), ParentLoop);
00136 }
00137 
00138 Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, ETForest &EF) {
00139   if (BBMap.find(BB) != BBMap.end()) return 0;   // Haven't processed this node?
00140 
00141   std::vector<BasicBlock *> TodoStack;
00142 
00143   // Scan the predecessors of BB, checking to see if BB dominates any of
00144   // them.  This identifies backedges which target this node...
00145   for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I)
00146     if (EF.dominates(BB, *I))   // If BB dominates it's predecessor...
00147       TodoStack.push_back(*I);
00148 
00149   if (TodoStack.empty()) return 0;  // No backedges to this block...
00150 
00151   // Create a new loop to represent this basic block...
00152   Loop *L = new Loop(BB);
00153   BBMap[BB] = L;
00154 
00155   BasicBlock *EntryBlock = &BB->getParent()->getEntryBlock();
00156 
00157   while (!TodoStack.empty()) {  // Process all the nodes in the loop
00158     BasicBlock *X = TodoStack.back();
00159     TodoStack.pop_back();
00160 
00161     if (!L->contains(X) &&         // As of yet unprocessed??
00162         EF.dominates(EntryBlock, X)) {   // X is reachable from entry block?
00163       // Check to see if this block already belongs to a loop.  If this occurs
00164       // then we have a case where a loop that is supposed to be a child of the
00165       // current loop was processed before the current loop.  When this occurs,
00166       // this child loop gets added to a part of the current loop, making it a
00167       // sibling to the current loop.  We have to reparent this loop.
00168       if (Loop *SubLoop = const_cast<Loop*>(getLoopFor(X)))
00169         if (SubLoop->getHeader() == X && isNotAlreadyContainedIn(SubLoop, L)) {
00170           // Remove the subloop from it's current parent...
00171           assert(SubLoop->ParentLoop && SubLoop->ParentLoop != L);
00172           Loop *SLP = SubLoop->ParentLoop;  // SubLoopParent
00173           std::vector<Loop*>::iterator I =
00174             std::find(SLP->SubLoops.begin(), SLP->SubLoops.end(), SubLoop);
00175           assert(I != SLP->SubLoops.end() && "SubLoop not a child of parent?");
00176           SLP->SubLoops.erase(I);   // Remove from parent...
00177 
00178           // Add the subloop to THIS loop...
00179           SubLoop->ParentLoop = L;
00180           L->SubLoops.push_back(SubLoop);
00181         }
00182 
00183       // Normal case, add the block to our loop...
00184       L->Blocks.push_back(X);
00185 
00186       // Add all of the predecessors of X to the end of the work stack...
00187       TodoStack.insert(TodoStack.end(), pred_begin(X), pred_end(X));
00188     }
00189   }
00190 
00191   // If there are any loops nested within this loop, create them now!
00192   for (std::vector<BasicBlock*>::iterator I = L->Blocks.begin(),
00193          E = L->Blocks.end(); I != E; ++I)
00194     if (Loop *NewLoop = ConsiderForLoop(*I, EF)) {
00195       L->SubLoops.push_back(NewLoop);
00196       NewLoop->ParentLoop = L;
00197     }
00198 
00199   // Add the basic blocks that comprise this loop to the BBMap so that this
00200   // loop can be found for them.
00201   //
00202   for (std::vector<BasicBlock*>::iterator I = L->Blocks.begin(),
00203          E = L->Blocks.end(); I != E; ++I) {
00204     std::map<BasicBlock*, Loop*>::iterator BBMI = BBMap.lower_bound(*I);
00205     if (BBMI == BBMap.end() || BBMI->first != *I)  // Not in map yet...
00206       BBMap.insert(BBMI, std::make_pair(*I, L));   // Must be at this level
00207   }
00208 
00209   // Now that we have a list of all of the child loops of this loop, check to
00210   // see if any of them should actually be nested inside of each other.  We can
00211   // accidentally pull loops our of their parents, so we must make sure to
00212   // organize the loop nests correctly now.
00213   {
00214     std::map<BasicBlock*, Loop*> ContainingLoops;
00215     for (unsigned i = 0; i != L->SubLoops.size(); ++i) {
00216       Loop *Child = L->SubLoops[i];
00217       assert(Child->getParentLoop() == L && "Not proper child loop?");
00218 
00219       if (Loop *ContainingLoop = ContainingLoops[Child->getHeader()]) {
00220         // If there is already a loop which contains this loop, move this loop
00221         // into the containing loop.
00222         MoveSiblingLoopInto(Child, ContainingLoop);
00223         --i;  // The loop got removed from the SubLoops list.
00224       } else {
00225         // This is currently considered to be a top-level loop.  Check to see if
00226         // any of the contained blocks are loop headers for subloops we have
00227         // already processed.
00228         for (unsigned b = 0, e = Child->Blocks.size(); b != e; ++b) {
00229           Loop *&BlockLoop = ContainingLoops[Child->Blocks[b]];
00230           if (BlockLoop == 0) {   // Child block not processed yet...
00231             BlockLoop = Child;
00232           } else if (BlockLoop != Child) {
00233             Loop *SubLoop = BlockLoop;
00234             // Reparent all of the blocks which used to belong to BlockLoops
00235             for (unsigned j = 0, e = SubLoop->Blocks.size(); j != e; ++j)
00236               ContainingLoops[SubLoop->Blocks[j]] = Child;
00237 
00238             // There is already a loop which contains this block, that means
00239             // that we should reparent the loop which the block is currently
00240             // considered to belong to to be a child of this loop.
00241             MoveSiblingLoopInto(SubLoop, Child);
00242             --i;  // We just shrunk the SubLoops list.
00243           }
00244         }
00245       }
00246     }
00247   }
00248 
00249   return L;
00250 }
00251 
00252 /// MoveSiblingLoopInto - This method moves the NewChild loop to live inside of
00253 /// the NewParent Loop, instead of being a sibling of it.
00254 void LoopInfo::MoveSiblingLoopInto(Loop *NewChild, Loop *NewParent) {
00255   Loop *OldParent = NewChild->getParentLoop();
00256   assert(OldParent && OldParent == NewParent->getParentLoop() &&
00257          NewChild != NewParent && "Not sibling loops!");
00258 
00259   // Remove NewChild from being a child of OldParent
00260   std::vector<Loop*>::iterator I =
00261     std::find(OldParent->SubLoops.begin(), OldParent->SubLoops.end(), NewChild);
00262   assert(I != OldParent->SubLoops.end() && "Parent fields incorrect??");
00263   OldParent->SubLoops.erase(I);   // Remove from parent's subloops list
00264   NewChild->ParentLoop = 0;
00265 
00266   InsertLoopInto(NewChild, NewParent);
00267 }
00268 
00269 /// InsertLoopInto - This inserts loop L into the specified parent loop.  If the
00270 /// parent loop contains a loop which should contain L, the loop gets inserted
00271 /// into L instead.
00272 void LoopInfo::InsertLoopInto(Loop *L, Loop *Parent) {
00273   BasicBlock *LHeader = L->getHeader();
00274   assert(Parent->contains(LHeader) && "This loop should not be inserted here!");
00275 
00276   // Check to see if it belongs in a child loop...
00277   for (unsigned i = 0, e = Parent->SubLoops.size(); i != e; ++i)
00278     if (Parent->SubLoops[i]->contains(LHeader)) {
00279       InsertLoopInto(L, Parent->SubLoops[i]);
00280       return;
00281     }
00282 
00283   // If not, insert it here!
00284   Parent->SubLoops.push_back(L);
00285   L->ParentLoop = Parent;
00286 }
00287 
00288 /// changeLoopFor - Change the top-level loop that contains BB to the
00289 /// specified loop.  This should be used by transformations that restructure
00290 /// the loop hierarchy tree.
00291 void LoopInfo::changeLoopFor(BasicBlock *BB, Loop *L) {
00292   Loop *&OldLoop = BBMap[BB];
00293   assert(OldLoop && "Block not in a loop yet!");
00294   OldLoop = L;
00295 }
00296 
00297 /// changeTopLevelLoop - Replace the specified loop in the top-level loops
00298 /// list with the indicated loop.
00299 void LoopInfo::changeTopLevelLoop(Loop *OldLoop, Loop *NewLoop) {
00300   std::vector<Loop*>::iterator I = std::find(TopLevelLoops.begin(),
00301                                              TopLevelLoops.end(), OldLoop);
00302   assert(I != TopLevelLoops.end() && "Old loop not at top level!");
00303   *I = NewLoop;
00304   assert(NewLoop->ParentLoop == 0 && OldLoop->ParentLoop == 0 &&
00305          "Loops already embedded into a subloop!");
00306 }
00307 
00308 /// removeLoop - This removes the specified top-level loop from this loop info
00309 /// object.  The loop is not deleted, as it will presumably be inserted into
00310 /// another loop.
00311 Loop *LoopInfo::removeLoop(iterator I) {
00312   assert(I != end() && "Cannot remove end iterator!");
00313   Loop *L = *I;
00314   assert(L->getParentLoop() == 0 && "Not a top-level loop!");
00315   TopLevelLoops.erase(TopLevelLoops.begin() + (I-begin()));
00316   return L;
00317 }
00318 
00319 /// removeBlock - This method completely removes BB from all data structures,
00320 /// including all of the Loop objects it is nested in and our mapping from
00321 /// BasicBlocks to loops.
00322 void LoopInfo::removeBlock(BasicBlock *BB) {
00323   std::map<BasicBlock *, Loop*>::iterator I = BBMap.find(BB);
00324   if (I != BBMap.end()) {
00325     for (Loop *L = I->second; L; L = L->getParentLoop())
00326       L->removeBlockFromLoop(BB);
00327 
00328     BBMap.erase(I);
00329   }
00330 }
00331 
00332 
00333 //===----------------------------------------------------------------------===//
00334 // APIs for simple analysis of the loop.
00335 //
00336 
00337 /// getExitBlocks - Return all of the successor blocks of this loop.  These
00338 /// are the blocks _outside of the current loop_ which are branched to.
00339 ///
00340 void Loop::getExitBlocks(std::vector<BasicBlock*> &ExitBlocks) const {
00341   for (std::vector<BasicBlock*>::const_iterator BI = Blocks.begin(),
00342          BE = Blocks.end(); BI != BE; ++BI)
00343     for (succ_iterator I = succ_begin(*BI), E = succ_end(*BI); I != E; ++I)
00344       if (!contains(*I))               // Not in current loop?
00345         ExitBlocks.push_back(*I);          // It must be an exit block...
00346 }
00347 
00348 
00349 /// getLoopPreheader - If there is a preheader for this loop, return it.  A
00350 /// loop has a preheader if there is only one edge to the header of the loop
00351 /// from outside of the loop.  If this is the case, the block branching to the
00352 /// header of the loop is the preheader node.
00353 ///
00354 /// This method returns null if there is no preheader for the loop.
00355 ///
00356 BasicBlock *Loop::getLoopPreheader() const {
00357   // Keep track of nodes outside the loop branching to the header...
00358   BasicBlock *Out = 0;
00359 
00360   // Loop over the predecessors of the header node...
00361   BasicBlock *Header = getHeader();
00362   for (pred_iterator PI = pred_begin(Header), PE = pred_end(Header);
00363        PI != PE; ++PI)
00364     if (!contains(*PI)) {     // If the block is not in the loop...
00365       if (Out && Out != *PI)
00366         return 0;             // Multiple predecessors outside the loop
00367       Out = *PI;
00368     }
00369 
00370   // Make sure there is only one exit out of the preheader.
00371   assert(Out && "Header of loop has no predecessors from outside loop?");
00372   succ_iterator SI = succ_begin(Out);
00373   ++SI;
00374   if (SI != succ_end(Out))
00375     return 0;  // Multiple exits from the block, must not be a preheader.
00376 
00377   // If there is exactly one preheader, return it.  If there was zero, then Out
00378   // is still null.
00379   return Out;
00380 }
00381 
00382 /// getLoopLatch - If there is a latch block for this loop, return it.  A
00383 /// latch block is the canonical backedge for a loop.  A loop header in normal
00384 /// form has two edges into it: one from a preheader and one from a latch
00385 /// block.
00386 BasicBlock *Loop::getLoopLatch() const {
00387   BasicBlock *Header = getHeader();
00388   pred_iterator PI = pred_begin(Header), PE = pred_end(Header);
00389   if (PI == PE) return 0;  // no preds?
00390   
00391   BasicBlock *Latch = 0;
00392   if (contains(*PI))
00393     Latch = *PI;
00394   ++PI;
00395   if (PI == PE) return 0;  // only one pred?
00396   
00397   if (contains(*PI)) {
00398     if (Latch) return 0;  // multiple backedges
00399     Latch = *PI;
00400   }
00401   ++PI;
00402   if (PI != PE) return 0;  // more than two preds
00403   
00404   return Latch;  
00405 }
00406 
00407 /// getCanonicalInductionVariable - Check to see if the loop has a canonical
00408 /// induction variable: an integer recurrence that starts at 0 and increments by
00409 /// one each time through the loop.  If so, return the phi node that corresponds
00410 /// to it.
00411 ///
00412 PHINode *Loop::getCanonicalInductionVariable() const {
00413   BasicBlock *H = getHeader();
00414 
00415   BasicBlock *Incoming = 0, *Backedge = 0;
00416   pred_iterator PI = pred_begin(H);
00417   assert(PI != pred_end(H) && "Loop must have at least one backedge!");
00418   Backedge = *PI++;
00419   if (PI == pred_end(H)) return 0;  // dead loop
00420   Incoming = *PI++;
00421   if (PI != pred_end(H)) return 0;  // multiple backedges?
00422 
00423   if (contains(Incoming)) {
00424     if (contains(Backedge))
00425       return 0;
00426     std::swap(Incoming, Backedge);
00427   } else if (!contains(Backedge))
00428     return 0;
00429 
00430   // Loop over all of the PHI nodes, looking for a canonical indvar.
00431   for (BasicBlock::iterator I = H->begin(); isa<PHINode>(I); ++I) {
00432     PHINode *PN = cast<PHINode>(I);
00433     if (Instruction *Inc =
00434         dyn_cast<Instruction>(PN->getIncomingValueForBlock(Backedge)))
00435       if (Inc->getOpcode() == Instruction::Add && Inc->getOperand(0) == PN)
00436         if (ConstantInt *CI = dyn_cast<ConstantInt>(Inc->getOperand(1)))
00437           if (CI->equalsInt(1))
00438             return PN;
00439   }
00440   return 0;
00441 }
00442 
00443 /// getCanonicalInductionVariableIncrement - Return the LLVM value that holds
00444 /// the canonical induction variable value for the "next" iteration of the loop.
00445 /// This always succeeds if getCanonicalInductionVariable succeeds.
00446 ///
00447 Instruction *Loop::getCanonicalInductionVariableIncrement() const {
00448   if (PHINode *PN = getCanonicalInductionVariable()) {
00449     bool P1InLoop = contains(PN->getIncomingBlock(1));
00450     return cast<Instruction>(PN->getIncomingValue(P1InLoop));
00451   }
00452   return 0;
00453 }
00454 
00455 /// getTripCount - Return a loop-invariant LLVM value indicating the number of
00456 /// times the loop will be executed.  Note that this means that the backedge of
00457 /// the loop executes N-1 times.  If the trip-count cannot be determined, this
00458 /// returns null.
00459 ///
00460 Value *Loop::getTripCount() const {
00461   // Canonical loops will end with a 'setne I, V', where I is the incremented
00462   // canonical induction variable and V is the trip count of the loop.
00463   Instruction *Inc = getCanonicalInductionVariableIncrement();
00464   if (Inc == 0) return 0;
00465   PHINode *IV = cast<PHINode>(Inc->getOperand(0));
00466 
00467   BasicBlock *BackedgeBlock =
00468     IV->getIncomingBlock(contains(IV->getIncomingBlock(1)));
00469 
00470   if (BranchInst *BI = dyn_cast<BranchInst>(BackedgeBlock->getTerminator()))
00471     if (BI->isConditional())
00472       if (SetCondInst *SCI = dyn_cast<SetCondInst>(BI->getCondition()))
00473         if (SCI->getOperand(0) == Inc)
00474           if (BI->getSuccessor(0) == getHeader()) {
00475             if (SCI->getOpcode() == Instruction::SetNE)
00476               return SCI->getOperand(1);
00477           } else if (SCI->getOpcode() == Instruction::SetEQ) {
00478             return SCI->getOperand(1);
00479           }
00480 
00481   return 0;
00482 }
00483 
00484 
00485 //===-------------------------------------------------------------------===//
00486 // APIs for updating loop information after changing the CFG
00487 //
00488 
00489 /// addBasicBlockToLoop - This function is used by other analyses to update loop
00490 /// information.  NewBB is set to be a new member of the current loop.  Because
00491 /// of this, it is added as a member of all parent loops, and is added to the
00492 /// specified LoopInfo object as being in the current basic block.  It is not
00493 /// valid to replace the loop header with this method.
00494 ///
00495 void Loop::addBasicBlockToLoop(BasicBlock *NewBB, LoopInfo &LI) {
00496   assert((Blocks.empty() || LI[getHeader()] == this) &&
00497          "Incorrect LI specified for this loop!");
00498   assert(NewBB && "Cannot add a null basic block to the loop!");
00499   assert(LI[NewBB] == 0 && "BasicBlock already in the loop!");
00500 
00501   // Add the loop mapping to the LoopInfo object...
00502   LI.BBMap[NewBB] = this;
00503 
00504   // Add the basic block to this loop and all parent loops...
00505   Loop *L = this;
00506   while (L) {
00507     L->Blocks.push_back(NewBB);
00508     L = L->getParentLoop();
00509   }
00510 }
00511 
00512 /// replaceChildLoopWith - This is used when splitting loops up.  It replaces
00513 /// the OldChild entry in our children list with NewChild, and updates the
00514 /// parent pointers of the two loops as appropriate.
00515 void Loop::replaceChildLoopWith(Loop *OldChild, Loop *NewChild) {
00516   assert(OldChild->ParentLoop == this && "This loop is already broken!");
00517   assert(NewChild->ParentLoop == 0 && "NewChild already has a parent!");
00518   std::vector<Loop*>::iterator I = std::find(SubLoops.begin(), SubLoops.end(),
00519                                              OldChild);
00520   assert(I != SubLoops.end() && "OldChild not in loop!");
00521   *I = NewChild;
00522   OldChild->ParentLoop = 0;
00523   NewChild->ParentLoop = this;
00524 }
00525 
00526 /// addChildLoop - Add the specified loop to be a child of this loop.
00527 ///
00528 void Loop::addChildLoop(Loop *NewChild) {
00529   assert(NewChild->ParentLoop == 0 && "NewChild already has a parent!");
00530   NewChild->ParentLoop = this;
00531   SubLoops.push_back(NewChild);
00532 }
00533 
00534 template<typename T>
00535 static void RemoveFromVector(std::vector<T*> &V, T *N) {
00536   typename std::vector<T*>::iterator I = std::find(V.begin(), V.end(), N);
00537   assert(I != V.end() && "N is not in this list!");
00538   V.erase(I);
00539 }
00540 
00541 /// removeChildLoop - This removes the specified child from being a subloop of
00542 /// this loop.  The loop is not deleted, as it will presumably be inserted
00543 /// into another loop.
00544 Loop *Loop::removeChildLoop(iterator I) {
00545   assert(I != SubLoops.end() && "Cannot remove end iterator!");
00546   Loop *Child = *I;
00547   assert(Child->ParentLoop == this && "Child is not a child of this loop!");
00548   SubLoops.erase(SubLoops.begin()+(I-begin()));
00549   Child->ParentLoop = 0;
00550   return Child;
00551 }
00552 
00553 
00554 /// removeBlockFromLoop - This removes the specified basic block from the
00555 /// current loop, updating the Blocks and ExitBlocks lists as appropriate.  This
00556 /// does not update the mapping in the LoopInfo class.
00557 void Loop::removeBlockFromLoop(BasicBlock *BB) {
00558   RemoveFromVector(Blocks, BB);
00559 }