Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===- LoopInfo.cpp - Natural Loop Calculator -----------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the LoopInfo class that is used to identify natural loops |
| 11 | // and determine the loop depth of various nodes of the CFG. Note that the |
| 12 | // loops identified may actually be several natural loops that share the same |
| 13 | // header node... not just a single natural loop. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #include "llvm/Analysis/LoopInfo.h" |
| 18 | #include "llvm/Constants.h" |
| 19 | #include "llvm/Instructions.h" |
| 20 | #include "llvm/Analysis/Dominators.h" |
| 21 | #include "llvm/Assembly/Writer.h" |
| 22 | #include "llvm/Support/CFG.h" |
| 23 | #include "llvm/Support/Streams.h" |
| 24 | #include "llvm/ADT/DepthFirstIterator.h" |
| 25 | #include "llvm/ADT/SmallPtrSet.h" |
| 26 | #include <algorithm> |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 27 | using namespace llvm; |
| 28 | |
| 29 | char LoopInfo::ID = 0; |
| 30 | static RegisterPass<LoopInfo> |
Dan Gohman | 4ad1027 | 2009-05-01 21:58:05 +0000 | [diff] [blame] | 31 | X("loops", "Natural Loop Information", true, true); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 32 | |
| 33 | //===----------------------------------------------------------------------===// |
| 34 | // Loop implementation |
| 35 | // |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 36 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 37 | //===----------------------------------------------------------------------===// |
| 38 | // LoopInfo implementation |
| 39 | // |
| 40 | bool LoopInfo::runOnFunction(Function &) { |
| 41 | releaseMemory(); |
Dan Gohman | 9b0abfe | 2009-06-27 21:22:48 +0000 | [diff] [blame^] | 42 | LI.Calculate(getAnalysis<DominatorTree>().getBase()); // Update |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 43 | return false; |
| 44 | } |
| 45 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 46 | void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const { |
| 47 | AU.setPreservesAll(); |
| 48 | AU.addRequired<DominatorTree>(); |
| 49 | } |