blob: de6480a66d5bfba6239281a8537816c995d02f73 [file] [log] [blame]
Chris Lattner44d2c352003-10-13 03:32:08 +00001//===- LoopInfo.cpp - Natural Loop Calculator -----------------------------===//
Misha Brukman01808ca2005-04-21 21:13:18 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Brukman01808ca2005-04-21 21:13:18 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner6de99422001-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 Brukman81804b42004-01-30 17:26:24 +000017#include "llvm/Analysis/LoopInfo.h"
Chris Lattnerd9dc4252004-04-15 15:16:02 +000018#include "llvm/Constants.h"
19#include "llvm/Instructions.h"
20#include "llvm/Analysis/Dominators.h"
Chris Lattner26750072002-07-27 01:12:17 +000021#include "llvm/Assembly/Writer.h"
Misha Brukman81804b42004-01-30 17:26:24 +000022#include "llvm/Support/CFG.h"
Bill Wendling597d4512006-11-28 22:46:12 +000023#include "llvm/Support/Streams.h"
Reid Spencer7c16caa2004-09-01 22:55:40 +000024#include "llvm/ADT/DepthFirstIterator.h"
Chris Lattner16cf9a72007-03-04 04:06:39 +000025#include "llvm/ADT/SmallPtrSet.h"
Chris Lattner6de99422001-11-26 18:41:20 +000026#include <algorithm>
Bill Wendling597d4512006-11-28 22:46:12 +000027#include <ostream>
Chris Lattner55b7ef52004-04-12 20:26:17 +000028using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000029
Devang Patel8c78a0b2007-05-03 01:11:54 +000030char LoopInfo::ID = 0;
Chris Lattner3c9b2422006-08-27 22:30:17 +000031static RegisterPass<LoopInfo>
Dan Gohman410b4fd2009-05-01 21:58:05 +000032X("loops", "Natural Loop Information", true, true);
Chris Lattnerccf571a2002-01-31 00:42:27 +000033
34//===----------------------------------------------------------------------===//
Chris Lattner78dd56f2002-04-28 16:21:30 +000035// Loop implementation
Chris Lattnerccf571a2002-01-31 00:42:27 +000036//
Misha Brukman3845be22002-10-11 05:31:10 +000037
Chris Lattner26750072002-07-27 01:12:17 +000038//===----------------------------------------------------------------------===//
39// LoopInfo implementation
40//
Chris Lattner26750072002-07-27 01:12:17 +000041bool LoopInfo::runOnFunction(Function &) {
42 releaseMemory();
Owen Andersonb0dd27e2007-11-27 03:43:35 +000043 LI->Calculate(getAnalysis<DominatorTree>().getBase()); // Update
Chris Lattner26750072002-07-27 01:12:17 +000044 return false;
45}
46
Chris Lattner78dd56f2002-04-28 16:21:30 +000047void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
Chris Lattnerc8e66542002-04-27 06:56:12 +000048 AU.setPreservesAll();
Devang Patelaee309e2007-06-08 00:17:13 +000049 AU.addRequired<DominatorTree>();
Chris Lattnerccf571a2002-01-31 00:42:27 +000050}