blob: 28cee8363126bf8776d2a95c8776ffaeeb76bd69 [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
Chris Lattner1c54f1d2001-06-21 05:26:15 +000020//===----------------------------------------------------------------------===//
21// Interval Implementation
22//===----------------------------------------------------------------------===//
23
24// isLoop - Find out if there is a back edge in this interval...
25//
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000026bool Interval::isLoop() const {
Chris Lattner1c54f1d2001-06-21 05:26:15 +000027 // There is a loop in this interval iff one of the predecessors of the header
28 // node lives in the interval.
Chris Lattner455889a2002-02-12 22:39:50 +000029 for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);
30 I != E; ++I) {
Chris Lattner1c54f1d2001-06-21 05:26:15 +000031 if (contains(*I)) return true;
32 }
33 return false;
34}
35
36
Chris Lattner1b0a63f2002-07-31 19:32:01 +000037void Interval::print(std::ostream &o) const {
Chris Lattnera59cbb22002-07-27 01:12:17 +000038 o << "-------------------------------------------------------------\n"
39 << "Interval Contents:\n";
40
41 // Print out all of the basic blocks in the interval...
42 std::copy(Nodes.begin(), Nodes.end(),
43 std::ostream_iterator<BasicBlock*>(o, "\n"));
44
45 o << "Interval Predecessors:\n";
46 std::copy(Predecessors.begin(), Predecessors.end(),
47 std::ostream_iterator<BasicBlock*>(o, "\n"));
48
49 o << "Interval Successors:\n";
50 std::copy(Successors.begin(), Successors.end(),
51 std::ostream_iterator<BasicBlock*>(o, "\n"));
52}