1f91fdef544a7f79ba78ce2bf7f3f3e9c63275a2
[oota-llvm.git] / lib / Analysis / Interval.cpp
1 //===- Interval.cpp - Interval class code ---------------------------------===//
2 //
3 // This file contains the definition of the Interval class, which represents a
4 // partition of a control flow graph of some kind.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #include "llvm/Analysis/Interval.h"
9 #include "llvm/BasicBlock.h"
10 #include "llvm/Support/CFG.h"
11 #include <algorithm>
12
13 //===----------------------------------------------------------------------===//
14 // Interval Implementation
15 //===----------------------------------------------------------------------===//
16
17 // isLoop - Find out if there is a back edge in this interval...
18 //
19 bool Interval::isLoop() const {
20   // There is a loop in this interval iff one of the predecessors of the header
21   // node lives in the interval.
22   for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);
23        I != E; ++I) {
24     if (contains(*I)) return true;
25   }
26   return false;
27 }
28
29
30 void Interval::print(std::ostream &o) const {
31   o << "-------------------------------------------------------------\n"
32        << "Interval Contents:\n";
33   
34   // Print out all of the basic blocks in the interval...
35   std::copy(Nodes.begin(), Nodes.end(), 
36             std::ostream_iterator<BasicBlock*>(o, "\n"));
37
38   o << "Interval Predecessors:\n";
39   std::copy(Predecessors.begin(), Predecessors.end(), 
40             std::ostream_iterator<BasicBlock*>(o, "\n"));
41   
42   o << "Interval Successors:\n";
43   std::copy(Successors.begin(), Successors.end(), 
44             std::ostream_iterator<BasicBlock*>(o, "\n"));
45 }