blob: 8ba8980a47ebdea427e84e0abd95ba2028daf95a [file] [log] [blame]
Chris Lattner107109c2001-06-24 04:05:21 +00001//===- Interval.cpp - Interval class code ------------------------*- C++ -*--=//
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 Lattnera59cbb22002-07-27 01:12:17 +000030void Interval::print(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}