blob: 1f91fdef544a7f79ba78ce2bf7f3f3e9c63275a2 [file] [log] [blame]
Chris Lattnercf3056d2003-10-13 03:32:08 +00001//===- Interval.cpp - Interval class code ---------------------------------===//
Chris Lattner2275c1d2001-06-20 20:09:55 +00002//
Chris Lattner1b7f7dc2002-04-28 16:21:30 +00003// This file contains the definition of the Interval class, which represents a
4// partition of a control flow graph of some kind.
Chris Lattner2275c1d2001-06-20 20:09:55 +00005//
6//===----------------------------------------------------------------------===//
7
Chris Lattner107109c2001-06-24 04:05:21 +00008#include "llvm/Analysis/Interval.h"
Chris Lattner2275c1d2001-06-20 20:09:55 +00009#include "llvm/BasicBlock.h"
Chris Lattner455889a2002-02-12 22:39:50 +000010#include "llvm/Support/CFG.h"
Chris Lattnera59cbb22002-07-27 01:12:17 +000011#include <algorithm>
Chris Lattner2275c1d2001-06-20 20:09:55 +000012
Chris Lattner1c54f1d2001-06-21 05:26:15 +000013//===----------------------------------------------------------------------===//
14// Interval Implementation
15//===----------------------------------------------------------------------===//
16
17// isLoop - Find out if there is a back edge in this interval...
18//
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000019bool Interval::isLoop() const {
Chris Lattner1c54f1d2001-06-21 05:26:15 +000020 // There is a loop in this interval iff one of the predecessors of the header
21 // node lives in the interval.
Chris Lattner455889a2002-02-12 22:39:50 +000022 for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);
23 I != E; ++I) {
Chris Lattner1c54f1d2001-06-21 05:26:15 +000024 if (contains(*I)) return true;
25 }
26 return false;
27}
28
29
Chris Lattner1b0a63f2002-07-31 19:32:01 +000030void Interval::print(std::ostream &o) const {
Chris Lattnera59cbb22002-07-27 01:12:17 +000031 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}