Interval.cpp revision 225736
123599Smarkm//===- Interval.cpp - Interval class code ---------------------------------===//
251694Sroger//
351694Sroger//                     The LLVM Compiler Infrastructure
448781Sroger//
548781Sroger// This file is distributed under the University of Illinois Open Source
623599Smarkm// License. See LICENSE.TXT for details.
723599Smarkm//
823599Smarkm//===----------------------------------------------------------------------===//
923599Smarkm//
1023599Smarkm// This file contains the definition of the Interval class, which represents a
1123599Smarkm// partition of a control flow graph of some kind.
1223599Smarkm//
1323599Smarkm//===----------------------------------------------------------------------===//
1423599Smarkm
1523599Smarkm#include "llvm/Analysis/Interval.h"
1623599Smarkm#include "llvm/BasicBlock.h"
1723599Smarkm#include "llvm/Support/CFG.h"
1823599Smarkm#include "llvm/Support/raw_ostream.h"
1923599Smarkm#include <algorithm>
2023599Smarkm
2123599Smarkmusing namespace llvm;
2223599Smarkm
2323599Smarkm//===----------------------------------------------------------------------===//
2423599Smarkm// Interval Implementation
2523599Smarkm//===----------------------------------------------------------------------===//
2623599Smarkm
2723599Smarkm// isLoop - Find out if there is a back edge in this interval...
2823599Smarkm//
2923599Smarkmbool Interval::isLoop() const {
3023599Smarkm  // There is a loop in this interval iff one of the predecessors of the header
3123599Smarkm  // node lives in the interval.
3223599Smarkm  for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);
3323599Smarkm       I != E; ++I)
3439838Ssos    if (contains(*I))
3523599Smarkm      return true;
3651694Sroger  return false;
3759014Sroger}
3859014Sroger
3959014Sroger
4059014Srogervoid Interval::print(raw_ostream &OS) const {
4162112Sroger  OS << "-------------------------------------------------------------\n"
4262112Sroger       << "Interval Contents:\n";
4362112Sroger
4462112Sroger  // Print out all of the basic blocks in the interval...
4562112Sroger  for (std::vector<BasicBlock*>::const_iterator I = Nodes.begin(),
4651694Sroger         E = Nodes.end(); I != E; ++I)
4751694Sroger    OS << **I << "\n";
4862112Sroger
4962112Sroger  OS << "Interval Predecessors:\n";
5062112Sroger  for (std::vector<BasicBlock*>::const_iterator I = Predecessors.begin(),
5162112Sroger         E = Predecessors.end(); I != E; ++I)
5262112Sroger    OS << **I << "\n";
5362112Sroger
5467306Sroger  OS << "Interval Successors:\n";
5567306Sroger  for (std::vector<BasicBlock*>::const_iterator I = Successors.begin(),
5667306Sroger         E = Successors.end(); I != E; ++I)
5767306Sroger    OS << **I << "\n";
5862112Sroger}
5962112Sroger