LoopInfo.cpp revision 204961
1193323Sed//===- LoopInfo.cpp - Natural Loop Calculator -----------------------------===//
2193323Sed//
3193323Sed//                     The LLVM Compiler Infrastructure
4193323Sed//
5193323Sed// This file is distributed under the University of Illinois Open Source
6193323Sed// License. See LICENSE.TXT for details.
7193323Sed//
8193323Sed//===----------------------------------------------------------------------===//
9193323Sed//
10193323Sed// This file defines the LoopInfo class that is used to identify natural loops
11193323Sed// and determine the loop depth of various nodes of the CFG.  Note that the
12193323Sed// loops identified may actually be several natural loops that share the same
13193323Sed// header node... not just a single natural loop.
14193323Sed//
15193323Sed//===----------------------------------------------------------------------===//
16193323Sed
17193323Sed#include "llvm/Analysis/LoopInfo.h"
18193323Sed#include "llvm/Constants.h"
19193323Sed#include "llvm/Instructions.h"
20193323Sed#include "llvm/Analysis/Dominators.h"
21193323Sed#include "llvm/Assembly/Writer.h"
22193323Sed#include "llvm/Support/CFG.h"
23198090Srdivacky#include "llvm/Support/CommandLine.h"
24202375Srdivacky#include "llvm/Support/Debug.h"
25193323Sed#include "llvm/ADT/DepthFirstIterator.h"
26193323Sed#include "llvm/ADT/SmallPtrSet.h"
27193323Sed#include <algorithm>
28193323Sedusing namespace llvm;
29193323Sed
30198090Srdivacky// Always verify loopinfo if expensive checking is enabled.
31198090Srdivacky#ifdef XDEBUG
32198090Srdivackybool VerifyLoopInfo = true;
33198090Srdivacky#else
34198090Srdivackybool VerifyLoopInfo = false;
35198090Srdivacky#endif
36198090Srdivackystatic cl::opt<bool,true>
37198090SrdivackyVerifyLoopInfoX("verify-loop-info", cl::location(VerifyLoopInfo),
38198090Srdivacky                cl::desc("Verify loop info (time consuming)"));
39198090Srdivacky
40193323Sedchar LoopInfo::ID = 0;
41193323Sedstatic RegisterPass<LoopInfo>
42193323SedX("loops", "Natural Loop Information", true, true);
43193323Sed
44193323Sed//===----------------------------------------------------------------------===//
45193323Sed// Loop implementation
46193323Sed//
47193323Sed
48198090Srdivacky/// isLoopInvariant - Return true if the specified value is loop invariant
49198090Srdivacky///
50198090Srdivackybool Loop::isLoopInvariant(Value *V) const {
51198090Srdivacky  if (Instruction *I = dyn_cast<Instruction>(V))
52198090Srdivacky    return isLoopInvariant(I);
53198090Srdivacky  return true;  // All non-instructions are loop invariant
54198090Srdivacky}
55198090Srdivacky
56198090Srdivacky/// isLoopInvariant - Return true if the specified instruction is
57198090Srdivacky/// loop-invariant.
58198090Srdivacky///
59198090Srdivackybool Loop::isLoopInvariant(Instruction *I) const {
60201360Srdivacky  return !contains(I);
61198090Srdivacky}
62198090Srdivacky
63198090Srdivacky/// makeLoopInvariant - If the given value is an instruciton inside of the
64198090Srdivacky/// loop and it can be hoisted, do so to make it trivially loop-invariant.
65198090Srdivacky/// Return true if the value after any hoisting is loop invariant. This
66198090Srdivacky/// function can be used as a slightly more aggressive replacement for
67198090Srdivacky/// isLoopInvariant.
68198090Srdivacky///
69198090Srdivacky/// If InsertPt is specified, it is the point to hoist instructions to.
70198090Srdivacky/// If null, the terminator of the loop preheader is used.
71198090Srdivacky///
72198090Srdivackybool Loop::makeLoopInvariant(Value *V, bool &Changed,
73198090Srdivacky                             Instruction *InsertPt) const {
74198090Srdivacky  if (Instruction *I = dyn_cast<Instruction>(V))
75198090Srdivacky    return makeLoopInvariant(I, Changed, InsertPt);
76198090Srdivacky  return true;  // All non-instructions are loop-invariant.
77198090Srdivacky}
78198090Srdivacky
79198090Srdivacky/// makeLoopInvariant - If the given instruction is inside of the
80198090Srdivacky/// loop and it can be hoisted, do so to make it trivially loop-invariant.
81198090Srdivacky/// Return true if the instruction after any hoisting is loop invariant. This
82198090Srdivacky/// function can be used as a slightly more aggressive replacement for
83198090Srdivacky/// isLoopInvariant.
84198090Srdivacky///
85198090Srdivacky/// If InsertPt is specified, it is the point to hoist instructions to.
86198090Srdivacky/// If null, the terminator of the loop preheader is used.
87198090Srdivacky///
88198090Srdivackybool Loop::makeLoopInvariant(Instruction *I, bool &Changed,
89198090Srdivacky                             Instruction *InsertPt) const {
90198090Srdivacky  // Test if the value is already loop-invariant.
91198090Srdivacky  if (isLoopInvariant(I))
92198090Srdivacky    return true;
93198090Srdivacky  if (!I->isSafeToSpeculativelyExecute())
94198090Srdivacky    return false;
95198090Srdivacky  if (I->mayReadFromMemory())
96198090Srdivacky    return false;
97198090Srdivacky  // Determine the insertion point, unless one was given.
98198090Srdivacky  if (!InsertPt) {
99198090Srdivacky    BasicBlock *Preheader = getLoopPreheader();
100198090Srdivacky    // Without a preheader, hoisting is not feasible.
101198090Srdivacky    if (!Preheader)
102198090Srdivacky      return false;
103198090Srdivacky    InsertPt = Preheader->getTerminator();
104198090Srdivacky  }
105198090Srdivacky  // Don't hoist instructions with loop-variant operands.
106198090Srdivacky  for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
107198090Srdivacky    if (!makeLoopInvariant(I->getOperand(i), Changed, InsertPt))
108198090Srdivacky      return false;
109198090Srdivacky  // Hoist.
110198090Srdivacky  I->moveBefore(InsertPt);
111198090Srdivacky  Changed = true;
112198090Srdivacky  return true;
113198090Srdivacky}
114198090Srdivacky
115198090Srdivacky/// getCanonicalInductionVariable - Check to see if the loop has a canonical
116198090Srdivacky/// induction variable: an integer recurrence that starts at 0 and increments
117198090Srdivacky/// by one each time through the loop.  If so, return the phi node that
118198090Srdivacky/// corresponds to it.
119198090Srdivacky///
120198090Srdivacky/// The IndVarSimplify pass transforms loops to have a canonical induction
121198090Srdivacky/// variable.
122198090Srdivacky///
123198090SrdivackyPHINode *Loop::getCanonicalInductionVariable() const {
124198090Srdivacky  BasicBlock *H = getHeader();
125198090Srdivacky
126198090Srdivacky  BasicBlock *Incoming = 0, *Backedge = 0;
127198090Srdivacky  typedef GraphTraits<Inverse<BasicBlock*> > InvBlockTraits;
128198090Srdivacky  InvBlockTraits::ChildIteratorType PI = InvBlockTraits::child_begin(H);
129198090Srdivacky  assert(PI != InvBlockTraits::child_end(H) &&
130198090Srdivacky         "Loop must have at least one backedge!");
131198090Srdivacky  Backedge = *PI++;
132198090Srdivacky  if (PI == InvBlockTraits::child_end(H)) return 0;  // dead loop
133198090Srdivacky  Incoming = *PI++;
134198090Srdivacky  if (PI != InvBlockTraits::child_end(H)) return 0;  // multiple backedges?
135198090Srdivacky
136198090Srdivacky  if (contains(Incoming)) {
137198090Srdivacky    if (contains(Backedge))
138198090Srdivacky      return 0;
139198090Srdivacky    std::swap(Incoming, Backedge);
140198090Srdivacky  } else if (!contains(Backedge))
141198090Srdivacky    return 0;
142198090Srdivacky
143198090Srdivacky  // Loop over all of the PHI nodes, looking for a canonical indvar.
144198090Srdivacky  for (BasicBlock::iterator I = H->begin(); isa<PHINode>(I); ++I) {
145198090Srdivacky    PHINode *PN = cast<PHINode>(I);
146198090Srdivacky    if (ConstantInt *CI =
147198090Srdivacky        dyn_cast<ConstantInt>(PN->getIncomingValueForBlock(Incoming)))
148198090Srdivacky      if (CI->isNullValue())
149198090Srdivacky        if (Instruction *Inc =
150198090Srdivacky            dyn_cast<Instruction>(PN->getIncomingValueForBlock(Backedge)))
151198090Srdivacky          if (Inc->getOpcode() == Instruction::Add &&
152198090Srdivacky                Inc->getOperand(0) == PN)
153198090Srdivacky            if (ConstantInt *CI = dyn_cast<ConstantInt>(Inc->getOperand(1)))
154198090Srdivacky              if (CI->equalsInt(1))
155198090Srdivacky                return PN;
156198090Srdivacky  }
157198090Srdivacky  return 0;
158198090Srdivacky}
159198090Srdivacky
160198090Srdivacky/// getCanonicalInductionVariableIncrement - Return the LLVM value that holds
161198090Srdivacky/// the canonical induction variable value for the "next" iteration of the
162198090Srdivacky/// loop.  This always succeeds if getCanonicalInductionVariable succeeds.
163198090Srdivacky///
164198090SrdivackyInstruction *Loop::getCanonicalInductionVariableIncrement() const {
165198090Srdivacky  if (PHINode *PN = getCanonicalInductionVariable()) {
166198090Srdivacky    bool P1InLoop = contains(PN->getIncomingBlock(1));
167198090Srdivacky    return cast<Instruction>(PN->getIncomingValue(P1InLoop));
168198090Srdivacky  }
169198090Srdivacky  return 0;
170198090Srdivacky}
171198090Srdivacky
172198090Srdivacky/// getTripCount - Return a loop-invariant LLVM value indicating the number of
173198090Srdivacky/// times the loop will be executed.  Note that this means that the backedge
174198090Srdivacky/// of the loop executes N-1 times.  If the trip-count cannot be determined,
175198090Srdivacky/// this returns null.
176198090Srdivacky///
177198090Srdivacky/// The IndVarSimplify pass transforms loops to have a form that this
178198090Srdivacky/// function easily understands.
179198090Srdivacky///
180198090SrdivackyValue *Loop::getTripCount() const {
181198090Srdivacky  // Canonical loops will end with a 'cmp ne I, V', where I is the incremented
182198090Srdivacky  // canonical induction variable and V is the trip count of the loop.
183198090Srdivacky  Instruction *Inc = getCanonicalInductionVariableIncrement();
184198090Srdivacky  if (Inc == 0) return 0;
185198090Srdivacky  PHINode *IV = cast<PHINode>(Inc->getOperand(0));
186198090Srdivacky
187198090Srdivacky  BasicBlock *BackedgeBlock =
188198090Srdivacky    IV->getIncomingBlock(contains(IV->getIncomingBlock(1)));
189198090Srdivacky
190198090Srdivacky  if (BranchInst *BI = dyn_cast<BranchInst>(BackedgeBlock->getTerminator()))
191198090Srdivacky    if (BI->isConditional()) {
192198090Srdivacky      if (ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition())) {
193198090Srdivacky        if (ICI->getOperand(0) == Inc) {
194198090Srdivacky          if (BI->getSuccessor(0) == getHeader()) {
195198090Srdivacky            if (ICI->getPredicate() == ICmpInst::ICMP_NE)
196198090Srdivacky              return ICI->getOperand(1);
197198090Srdivacky          } else if (ICI->getPredicate() == ICmpInst::ICMP_EQ) {
198198090Srdivacky            return ICI->getOperand(1);
199198090Srdivacky          }
200198090Srdivacky        }
201198090Srdivacky      }
202198090Srdivacky    }
203198090Srdivacky
204198090Srdivacky  return 0;
205198090Srdivacky}
206198090Srdivacky
207198090Srdivacky/// getSmallConstantTripCount - Returns the trip count of this loop as a
208198090Srdivacky/// normal unsigned value, if possible. Returns 0 if the trip count is unknown
209198090Srdivacky/// of not constant. Will also return 0 if the trip count is very large
210198090Srdivacky/// (>= 2^32)
211198090Srdivackyunsigned Loop::getSmallConstantTripCount() const {
212198090Srdivacky  Value* TripCount = this->getTripCount();
213198090Srdivacky  if (TripCount) {
214198090Srdivacky    if (ConstantInt *TripCountC = dyn_cast<ConstantInt>(TripCount)) {
215198090Srdivacky      // Guard against huge trip counts.
216198090Srdivacky      if (TripCountC->getValue().getActiveBits() <= 32) {
217198090Srdivacky        return (unsigned)TripCountC->getZExtValue();
218198090Srdivacky      }
219198090Srdivacky    }
220198090Srdivacky  }
221198090Srdivacky  return 0;
222198090Srdivacky}
223198090Srdivacky
224198090Srdivacky/// getSmallConstantTripMultiple - Returns the largest constant divisor of the
225198090Srdivacky/// trip count of this loop as a normal unsigned value, if possible. This
226198090Srdivacky/// means that the actual trip count is always a multiple of the returned
227198090Srdivacky/// value (don't forget the trip count could very well be zero as well!).
228198090Srdivacky///
229198090Srdivacky/// Returns 1 if the trip count is unknown or not guaranteed to be the
230198090Srdivacky/// multiple of a constant (which is also the case if the trip count is simply
231198090Srdivacky/// constant, use getSmallConstantTripCount for that case), Will also return 1
232198090Srdivacky/// if the trip count is very large (>= 2^32).
233198090Srdivackyunsigned Loop::getSmallConstantTripMultiple() const {
234198090Srdivacky  Value* TripCount = this->getTripCount();
235198090Srdivacky  // This will hold the ConstantInt result, if any
236198090Srdivacky  ConstantInt *Result = NULL;
237198090Srdivacky  if (TripCount) {
238198090Srdivacky    // See if the trip count is constant itself
239198090Srdivacky    Result = dyn_cast<ConstantInt>(TripCount);
240198090Srdivacky    // if not, see if it is a multiplication
241198090Srdivacky    if (!Result)
242198090Srdivacky      if (BinaryOperator *BO = dyn_cast<BinaryOperator>(TripCount)) {
243198090Srdivacky        switch (BO->getOpcode()) {
244198090Srdivacky        case BinaryOperator::Mul:
245198090Srdivacky          Result = dyn_cast<ConstantInt>(BO->getOperand(1));
246198090Srdivacky          break;
247199989Srdivacky        case BinaryOperator::Shl:
248199989Srdivacky          if (ConstantInt *CI = dyn_cast<ConstantInt>(BO->getOperand(1)))
249199989Srdivacky            if (CI->getValue().getActiveBits() <= 5)
250199989Srdivacky              return 1u << CI->getZExtValue();
251199989Srdivacky          break;
252198090Srdivacky        default:
253198090Srdivacky          break;
254198090Srdivacky        }
255198090Srdivacky      }
256198090Srdivacky  }
257198090Srdivacky  // Guard against huge trip counts.
258198090Srdivacky  if (Result && Result->getValue().getActiveBits() <= 32) {
259198090Srdivacky    return (unsigned)Result->getZExtValue();
260198090Srdivacky  } else {
261198090Srdivacky    return 1;
262198090Srdivacky  }
263198090Srdivacky}
264198090Srdivacky
265198090Srdivacky/// isLCSSAForm - Return true if the Loop is in LCSSA form
266198090Srdivackybool Loop::isLCSSAForm() const {
267204961Srdivacky  // Collect all the reachable blocks in the function, for fast lookups.
268204961Srdivacky  SmallPtrSet<BasicBlock *, 32> ReachableBBs;
269204961Srdivacky  BasicBlock *EntryBB = getHeader()->getParent()->begin();
270204961Srdivacky  for (df_iterator<BasicBlock *> NI = df_begin(EntryBB),
271204961Srdivacky       NE = df_end(EntryBB); NI != NE; ++NI)
272204961Srdivacky    ReachableBBs.insert(*NI);
273204961Srdivacky
274198090Srdivacky  // Sort the blocks vector so that we can use binary search to do quick
275198090Srdivacky  // lookups.
276198090Srdivacky  SmallPtrSet<BasicBlock *, 16> LoopBBs(block_begin(), block_end());
277198090Srdivacky
278198090Srdivacky  for (block_iterator BI = block_begin(), E = block_end(); BI != E; ++BI) {
279199481Srdivacky    BasicBlock *BB = *BI;
280199481Srdivacky    for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;++I)
281198090Srdivacky      for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E;
282198090Srdivacky           ++UI) {
283198090Srdivacky        BasicBlock *UserBB = cast<Instruction>(*UI)->getParent();
284199481Srdivacky        if (PHINode *P = dyn_cast<PHINode>(*UI))
285198090Srdivacky          UserBB = P->getIncomingBlock(UI);
286198090Srdivacky
287204961Srdivacky        // Check the current block, as a fast-path, before checking whether
288204961Srdivacky        // the use is anywhere in the loop.  Most values are used in the same
289204961Srdivacky        // block they are defined in.  Also, blocks not reachable from the
290204961Srdivacky        // entry are special; uses in them don't need to go through PHIs.
291204961Srdivacky        if (UserBB != BB &&
292204961Srdivacky            !LoopBBs.count(UserBB) &&
293204961Srdivacky            ReachableBBs.count(UserBB))
294198090Srdivacky          return false;
295198090Srdivacky      }
296198090Srdivacky  }
297198090Srdivacky
298198090Srdivacky  return true;
299198090Srdivacky}
300198090Srdivacky
301198090Srdivacky/// isLoopSimplifyForm - Return true if the Loop is in the form that
302198090Srdivacky/// the LoopSimplify form transforms loops to, which is sometimes called
303198090Srdivacky/// normal form.
304198090Srdivackybool Loop::isLoopSimplifyForm() const {
305199481Srdivacky  // Normal-form loops have a preheader, a single backedge, and all of their
306199481Srdivacky  // exits have all their predecessors inside the loop.
307199481Srdivacky  return getLoopPreheader() && getLoopLatch() && hasDedicatedExits();
308199481Srdivacky}
309199481Srdivacky
310199481Srdivacky/// hasDedicatedExits - Return true if no exit block for the loop
311199481Srdivacky/// has a predecessor that is outside the loop.
312199481Srdivackybool Loop::hasDedicatedExits() const {
313198396Srdivacky  // Sort the blocks vector so that we can use binary search to do quick
314198396Srdivacky  // lookups.
315198396Srdivacky  SmallPtrSet<BasicBlock *, 16> LoopBBs(block_begin(), block_end());
316198090Srdivacky  // Each predecessor of each exit block of a normal loop is contained
317198090Srdivacky  // within the loop.
318198090Srdivacky  SmallVector<BasicBlock *, 4> ExitBlocks;
319198090Srdivacky  getExitBlocks(ExitBlocks);
320198090Srdivacky  for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
321198090Srdivacky    for (pred_iterator PI = pred_begin(ExitBlocks[i]),
322198090Srdivacky         PE = pred_end(ExitBlocks[i]); PI != PE; ++PI)
323198396Srdivacky      if (!LoopBBs.count(*PI))
324198090Srdivacky        return false;
325198090Srdivacky  // All the requirements are met.
326198090Srdivacky  return true;
327198090Srdivacky}
328198090Srdivacky
329198090Srdivacky/// getUniqueExitBlocks - Return all unique successor blocks of this loop.
330198090Srdivacky/// These are the blocks _outside of the current loop_ which are branched to.
331200581Srdivacky/// This assumes that loop exits are in canonical form.
332198090Srdivacky///
333198090Srdivackyvoid
334198090SrdivackyLoop::getUniqueExitBlocks(SmallVectorImpl<BasicBlock *> &ExitBlocks) const {
335200581Srdivacky  assert(hasDedicatedExits() &&
336200581Srdivacky         "getUniqueExitBlocks assumes the loop has canonical form exits!");
337198090Srdivacky
338198090Srdivacky  // Sort the blocks vector so that we can use binary search to do quick
339198090Srdivacky  // lookups.
340198090Srdivacky  SmallVector<BasicBlock *, 128> LoopBBs(block_begin(), block_end());
341198090Srdivacky  std::sort(LoopBBs.begin(), LoopBBs.end());
342198090Srdivacky
343198090Srdivacky  SmallVector<BasicBlock *, 32> switchExitBlocks;
344198090Srdivacky
345198090Srdivacky  for (block_iterator BI = block_begin(), BE = block_end(); BI != BE; ++BI) {
346198090Srdivacky
347198090Srdivacky    BasicBlock *current = *BI;
348198090Srdivacky    switchExitBlocks.clear();
349198090Srdivacky
350198090Srdivacky    typedef GraphTraits<BasicBlock *> BlockTraits;
351198090Srdivacky    typedef GraphTraits<Inverse<BasicBlock *> > InvBlockTraits;
352198090Srdivacky    for (BlockTraits::ChildIteratorType I =
353198090Srdivacky         BlockTraits::child_begin(*BI), E = BlockTraits::child_end(*BI);
354198090Srdivacky         I != E; ++I) {
355198090Srdivacky      // If block is inside the loop then it is not a exit block.
356198090Srdivacky      if (std::binary_search(LoopBBs.begin(), LoopBBs.end(), *I))
357198090Srdivacky        continue;
358198090Srdivacky
359198090Srdivacky      InvBlockTraits::ChildIteratorType PI = InvBlockTraits::child_begin(*I);
360198090Srdivacky      BasicBlock *firstPred = *PI;
361198090Srdivacky
362198090Srdivacky      // If current basic block is this exit block's first predecessor
363198090Srdivacky      // then only insert exit block in to the output ExitBlocks vector.
364198090Srdivacky      // This ensures that same exit block is not inserted twice into
365198090Srdivacky      // ExitBlocks vector.
366198090Srdivacky      if (current != firstPred)
367198090Srdivacky        continue;
368198090Srdivacky
369198090Srdivacky      // If a terminator has more then two successors, for example SwitchInst,
370198090Srdivacky      // then it is possible that there are multiple edges from current block
371198090Srdivacky      // to one exit block.
372198090Srdivacky      if (std::distance(BlockTraits::child_begin(current),
373198090Srdivacky                        BlockTraits::child_end(current)) <= 2) {
374198090Srdivacky        ExitBlocks.push_back(*I);
375198090Srdivacky        continue;
376198090Srdivacky      }
377198090Srdivacky
378198090Srdivacky      // In case of multiple edges from current block to exit block, collect
379198090Srdivacky      // only one edge in ExitBlocks. Use switchExitBlocks to keep track of
380198090Srdivacky      // duplicate edges.
381198090Srdivacky      if (std::find(switchExitBlocks.begin(), switchExitBlocks.end(), *I)
382198090Srdivacky          == switchExitBlocks.end()) {
383198090Srdivacky        switchExitBlocks.push_back(*I);
384198090Srdivacky        ExitBlocks.push_back(*I);
385198090Srdivacky      }
386198090Srdivacky    }
387198090Srdivacky  }
388198090Srdivacky}
389198090Srdivacky
390198090Srdivacky/// getUniqueExitBlock - If getUniqueExitBlocks would return exactly one
391198090Srdivacky/// block, return that block. Otherwise return null.
392198090SrdivackyBasicBlock *Loop::getUniqueExitBlock() const {
393198090Srdivacky  SmallVector<BasicBlock *, 8> UniqueExitBlocks;
394198090Srdivacky  getUniqueExitBlocks(UniqueExitBlocks);
395198090Srdivacky  if (UniqueExitBlocks.size() == 1)
396198090Srdivacky    return UniqueExitBlocks[0];
397198090Srdivacky  return 0;
398198090Srdivacky}
399198090Srdivacky
400202375Srdivackyvoid Loop::dump() const {
401202375Srdivacky  print(dbgs());
402202375Srdivacky}
403202375Srdivacky
404193323Sed//===----------------------------------------------------------------------===//
405193323Sed// LoopInfo implementation
406193323Sed//
407193323Sedbool LoopInfo::runOnFunction(Function &) {
408193323Sed  releaseMemory();
409195340Sed  LI.Calculate(getAnalysis<DominatorTree>().getBase());    // Update
410193323Sed  return false;
411193323Sed}
412193323Sed
413198090Srdivackyvoid LoopInfo::verifyAnalysis() const {
414198090Srdivacky  // LoopInfo is a FunctionPass, but verifying every loop in the function
415198090Srdivacky  // each time verifyAnalysis is called is very expensive. The
416198090Srdivacky  // -verify-loop-info option can enable this. In order to perform some
417198090Srdivacky  // checking by default, LoopPass has been taught to call verifyLoop
418198090Srdivacky  // manually during loop pass sequences.
419198090Srdivacky
420198090Srdivacky  if (!VerifyLoopInfo) return;
421198090Srdivacky
422198090Srdivacky  for (iterator I = begin(), E = end(); I != E; ++I) {
423198090Srdivacky    assert(!(*I)->getParentLoop() && "Top-level loop has a parent!");
424198090Srdivacky    (*I)->verifyLoopNest();
425198090Srdivacky  }
426198090Srdivacky
427198090Srdivacky  // TODO: check BBMap consistency.
428198090Srdivacky}
429198090Srdivacky
430193323Sedvoid LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
431193323Sed  AU.setPreservesAll();
432193323Sed  AU.addRequired<DominatorTree>();
433193323Sed}
434198090Srdivacky
435198090Srdivackyvoid LoopInfo::print(raw_ostream &OS, const Module*) const {
436198090Srdivacky  LI.print(OS);
437198090Srdivacky}
438198090Srdivacky
439