2003-10-13 11:32:08 +08:00
|
|
|
//===- LoopInfo.cpp - Natural Loop Calculator -----------------------------===//
|
2005-04-22 05:13:18 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 05:13:18 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-11-27 02:41:20 +08:00
|
|
|
//
|
|
|
|
// This file defines the LoopInfo class that is used to identify natural loops
|
|
|
|
// and determine the loop depth of various nodes of the CFG. Note that the
|
|
|
|
// loops identified may actually be several natural loops that share the same
|
|
|
|
// header node... not just a single natural loop.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-01-31 01:26:24 +08:00
|
|
|
#include "llvm/Analysis/LoopInfo.h"
|
2004-04-15 23:16:02 +08:00
|
|
|
#include "llvm/Constants.h"
|
|
|
|
#include "llvm/Instructions.h"
|
|
|
|
#include "llvm/Analysis/Dominators.h"
|
2002-07-27 09:12:17 +08:00
|
|
|
#include "llvm/Assembly/Writer.h"
|
2004-01-31 01:26:24 +08:00
|
|
|
#include "llvm/Support/CFG.h"
|
2006-11-29 06:46:12 +08:00
|
|
|
#include "llvm/Support/Streams.h"
|
2004-09-02 06:55:40 +08:00
|
|
|
#include "llvm/ADT/DepthFirstIterator.h"
|
2007-03-04 12:06:39 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2001-11-27 02:41:20 +08:00
|
|
|
#include <algorithm>
|
2006-11-29 06:46:12 +08:00
|
|
|
#include <ostream>
|
2004-04-13 04:26:17 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2007-05-03 09:11:54 +08:00
|
|
|
char LoopInfo::ID = 0;
|
2006-08-28 06:30:17 +08:00
|
|
|
static RegisterPass<LoopInfo>
|
2008-03-21 07:27:18 +08:00
|
|
|
X("loops", "Natural Loop Construction", true, true);
|
2002-01-31 08:42:27 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2002-04-29 00:21:30 +08:00
|
|
|
// Loop implementation
|
2002-01-31 08:42:27 +08:00
|
|
|
//
|
2002-10-11 13:31:10 +08:00
|
|
|
|
2003-10-13 06:14:27 +08:00
|
|
|
/// getNumBackEdges - Calculate the number of back edges to the loop header.
|
|
|
|
///
|
2003-02-23 05:33:11 +08:00
|
|
|
|
2002-01-31 08:42:27 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-04-29 00:21:30 +08:00
|
|
|
// LoopInfo implementation
|
2002-01-31 08:42:27 +08:00
|
|
|
//
|
2002-06-26 00:13:24 +08:00
|
|
|
bool LoopInfo::runOnFunction(Function &) {
|
2002-04-09 13:43:19 +08:00
|
|
|
releaseMemory();
|
2007-11-27 11:43:35 +08:00
|
|
|
LI->Calculate(getAnalysis<DominatorTree>().getBase()); // Update
|
2002-01-31 08:42:27 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-04-29 00:21:30 +08:00
|
|
|
void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
|
2002-04-27 14:56:12 +08:00
|
|
|
AU.setPreservesAll();
|
2007-06-08 08:17:13 +08:00
|
|
|
AU.addRequired<DominatorTree>();
|
2002-01-31 08:42:27 +08:00
|
|
|
}
|