blob: e136f2930f6f92cca21260ceb78c54d43365cdfd [file] [log] [blame]
Chris Lattnercf3056d2003-10-13 03:32:08 +00001//===- LoopInfo.cpp - Natural Loop Calculator -----------------------------===//
Misha Brukman2b37d7c2005-04-21 21:13:18 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman2b37d7c2005-04-21 21:13:18 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner0bbe58f2001-11-26 18:41:20 +00009//
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
Misha Brukman10d208d2004-01-30 17:26:24 +000017#include "llvm/Analysis/LoopInfo.h"
Chris Lattner92020fa2004-04-15 15:16:02 +000018#include "llvm/Constants.h"
19#include "llvm/Instructions.h"
20#include "llvm/Analysis/Dominators.h"
Chris Lattnera59cbb22002-07-27 01:12:17 +000021#include "llvm/Assembly/Writer.h"
Misha Brukman10d208d2004-01-30 17:26:24 +000022#include "llvm/Support/CFG.h"
Bill Wendling6f81b512006-11-28 22:46:12 +000023#include "llvm/Support/Streams.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000024#include "llvm/ADT/DepthFirstIterator.h"
Chris Lattnerb1f5d8b2007-03-04 04:06:39 +000025#include "llvm/ADT/SmallPtrSet.h"
Chris Lattner0bbe58f2001-11-26 18:41:20 +000026#include <algorithm>
Bill Wendling6f81b512006-11-28 22:46:12 +000027#include <ostream>
Chris Lattner46758a82004-04-12 20:26:17 +000028using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000029
Devang Patel19974732007-05-03 01:11:54 +000030char LoopInfo::ID = 0;
Chris Lattner5d8925c2006-08-27 22:30:17 +000031static RegisterPass<LoopInfo>
Chris Lattner17689df2002-07-30 16:27:52 +000032X("loops", "Natural Loop Construction", true);
Chris Lattner93193f82002-01-31 00:42:27 +000033
34//===----------------------------------------------------------------------===//
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000035// Loop implementation
Chris Lattner93193f82002-01-31 00:42:27 +000036//
Misha Brukman6b290a52002-10-11 05:31:10 +000037
Chris Lattner2ef12362003-10-12 22:14:27 +000038/// getNumBackEdges - Calculate the number of back edges to the loop header.
39///
Chris Lattner420df9b2003-02-22 21:33:11 +000040
Chris Lattnera59cbb22002-07-27 01:12:17 +000041//===----------------------------------------------------------------------===//
42// LoopInfo implementation
43//
Chris Lattnera59cbb22002-07-27 01:12:17 +000044bool LoopInfo::runOnFunction(Function &) {
45 releaseMemory();
Owen Andersond735ee82007-11-27 03:43:35 +000046 LI->Calculate(getAnalysis<DominatorTree>().getBase()); // Update
Chris Lattnera59cbb22002-07-27 01:12:17 +000047 return false;
48}
49
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000050void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
Chris Lattnerf57b8452002-04-27 06:56:12 +000051 AU.setPreservesAll();
Devang Patel53c279b2007-06-08 00:17:13 +000052 AU.addRequired<DominatorTree>();
Chris Lattner93193f82002-01-31 00:42:27 +000053}
54
Reid Spencer4f1bd9e2006-06-07 22:00:26 +000055// Ensure this file gets linked when LoopInfo.h is used.
56DEFINING_FILE_FOR(LoopInfo)