blob: 8f0bdfa0034733808f18f075fcfd6efc9d80be39 [file] [log] [blame]
Chris Lattner44d2c352003-10-13 03:32:08 +00001//===- Interval.cpp - Interval class code ---------------------------------===//
John Criswell482202a2003-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 Lattner28ae5cb2001-06-20 20:09:55 +00009//
Chris Lattner78dd56f2002-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 Lattner28ae5cb2001-06-20 20:09:55 +000012//
13//===----------------------------------------------------------------------===//
14
Chris Lattnerdec727e2001-06-24 04:05:21 +000015#include "llvm/Analysis/Interval.h"
Chris Lattner28ae5cb2001-06-20 20:09:55 +000016#include "llvm/BasicBlock.h"
Chris Lattner83d485b2002-02-12 22:39:50 +000017#include "llvm/Support/CFG.h"
Chris Lattner26750072002-07-27 01:12:17 +000018#include <algorithm>
Chris Lattner28ae5cb2001-06-20 20:09:55 +000019
Brian Gaeke960707c2003-11-11 22:41:34 +000020using namespace llvm;
21
Chris Lattnerd79faa32001-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 Lattner78dd56f2002-04-28 16:21:30 +000028bool Interval::isLoop() const {
Chris Lattnerd79faa32001-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 Lattner83d485b2002-02-12 22:39:50 +000031 for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);
32 I != E; ++I) {
Chris Lattnerd79faa32001-06-21 05:26:15 +000033 if (contains(*I)) return true;
34 }
35 return false;
36}
37
38
Chris Lattnerbe4826e2002-07-31 19:32:01 +000039void Interval::print(std::ostream &o) const {
Chris Lattner26750072002-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}