LLVM API Documentation
00001 //===- LoopInfo.cpp - Natural Loop Calculator -----------------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // 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/Support/Streams.h" 00024 #include "llvm/ADT/DepthFirstIterator.h" 00025 #include "llvm/ADT/SmallPtrSet.h" 00026 #include <algorithm> 00027 #include <ostream> 00028 using namespace llvm; 00029 00030 char LoopInfo::ID = 0; 00031 static RegisterPass<LoopInfo> 00032 X("loops", "Natural Loop Construction", true, true); 00033 00034 //===----------------------------------------------------------------------===// 00035 // Loop implementation 00036 // 00037 00038 //===----------------------------------------------------------------------===// 00039 // LoopInfo implementation 00040 // 00041 bool LoopInfo::runOnFunction(Function &) { 00042 releaseMemory(); 00043 LI->Calculate(getAnalysis<DominatorTree>().getBase()); // Update 00044 return false; 00045 } 00046 00047 void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const { 00048 AU.setPreservesAll(); 00049 AU.addRequired<DominatorTree>(); 00050 }