blob: 8f0bdfa0034733808f18f075fcfd6efc9d80be39 [file] [log] [blame]
Chris Lattnercf3056d2003-10-13 03:32:08 +00001//===- Interval.cpp - Interval class code ---------------------------------===//
John Criswellb576c942003-10-20 19:43:21 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Chris Lattner2275c1d2001-06-20 20:09:55 +00009//
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000010// This file contains the definition of the Interval class, which represents a
11// partition of a control flow graph of some kind.
Chris Lattner2275c1d2001-06-20 20:09:55 +000012//
13//===----------------------------------------------------------------------===//
14
Chris Lattner107109c2001-06-24 04:05:21 +000015#include "llvm/Analysis/Interval.h"
Chris Lattner2275c1d2001-06-20 20:09:55 +000016#include "llvm/BasicBlock.h"
Chris Lattner455889a2002-02-12 22:39:50 +000017#include "llvm/Support/CFG.h"
Chris Lattnera59cbb22002-07-27 01:12:17 +000018#include <algorithm>
Chris Lattner2275c1d2001-06-20 20:09:55 +000019
Brian Gaeked0fde302003-11-11 22:41:34 +000020using namespace llvm;
21
Chris Lattner1c54f1d2001-06-21 05:26:15 +000022//===----------------------------------------------------------------------===//
23// Interval Implementation
24//===----------------------------------------------------------------------===//
25
26// isLoop - Find out if there is a back edge in this interval...
27//
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000028bool Interval::isLoop() const {
Chris Lattner1c54f1d2001-06-21 05:26:15 +000029 // There is a loop in this interval iff one of the predecessors of the header
30 // node lives in the interval.
Chris Lattner455889a2002-02-12 22:39:50 +000031 for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);
32 I != E; ++I) {
Chris Lattner1c54f1d2001-06-21 05:26:15 +000033 if (contains(*I)) return true;
34 }
35 return false;
36}
37
38
Chris Lattner1b0a63f2002-07-31 19:32:01 +000039void Interval::print(std::ostream &o) const {
Chris Lattnera59cbb22002-07-27 01:12:17 +000040 o << "-------------------------------------------------------------\n"
41 << "Interval Contents:\n";
42
43 // Print out all of the basic blocks in the interval...
44 std::copy(Nodes.begin(), Nodes.end(),
45 std::ostream_iterator<BasicBlock*>(o, "\n"));
46
47 o << "Interval Predecessors:\n";
48 std::copy(Predecessors.begin(), Predecessors.end(),
49 std::ostream_iterator<BasicBlock*>(o, "\n"));
50
51 o << "Interval Successors:\n";
52 std::copy(Successors.begin(), Successors.end(),
53 std::ostream_iterator<BasicBlock*>(o, "\n"));
54}