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 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 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> |
| 27 | #include <ostream> |
| 28 | using namespace llvm; |
| 29 | |
| 30 | char LoopInfo::ID = 0; |
| 31 | static RegisterPass<LoopInfo> |
| 32 | X("loops", "Natural Loop Construction", true); |
| 33 | |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | // Loop implementation |
| 36 | // |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 37 | |
| 38 | /// getNumBackEdges - Calculate the number of back edges to the loop header. |
| 39 | /// |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 40 | |
| 41 | //===----------------------------------------------------------------------===// |
| 42 | // LoopInfo implementation |
| 43 | // |
| 44 | bool LoopInfo::runOnFunction(Function &) { |
| 45 | releaseMemory(); |
Owen Anderson | ca0b9d4 | 2007-11-27 03:43:35 +0000 | [diff] [blame^] | 46 | LI->Calculate(getAnalysis<DominatorTree>().getBase()); // Update |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 47 | return false; |
| 48 | } |
| 49 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 50 | void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const { |
| 51 | AU.setPreservesAll(); |
| 52 | AU.addRequired<DominatorTree>(); |
| 53 | } |
| 54 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 55 | // Ensure this file gets linked when LoopInfo.h is used. |
| 56 | DEFINING_FILE_FOR(LoopInfo) |