blob: 6d5de22cb93f52ac746a82644bbe0455186961d1 [file] [log] [blame]
Chris Lattnercf3056d2003-10-13 03:32:08 +00001//===- Interval.cpp - Interval class code ---------------------------------===//
Misha Brukman2b37d7c2005-04-21 21:13:18 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman2b37d7c2005-04-21 21:13:18 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
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"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000016#include "llvm/IR/BasicBlock.h"
Chandler Carruth03e36d72014-03-04 11:45:46 +000017#include "llvm/IR/CFG.h"
Chris Lattnerbdff5482009-08-23 04:37:46 +000018#include "llvm/Support/raw_ostream.h"
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...
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000027bool Interval::isLoop() const {
Sylvestre Ledru94c22712012-09-27 10:14:43 +000028 // There is a loop in this interval iff one of the predecessors of the header
Chris Lattner1c54f1d2001-06-21 05:26:15 +000029 // node lives in the interval.
Duncan P. N. Exon Smithfacdfc62014-07-21 17:06:51 +000030 for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);
31 I != E; ++I)
32 if (contains(*I))
Chris Lattnerbdff5482009-08-23 04:37:46 +000033 return true;
Chris Lattner1c54f1d2001-06-21 05:26:15 +000034 return false;
35}
36
Chris Lattner45cfe542009-08-23 06:03:38 +000037void Interval::print(raw_ostream &OS) const {
Chris Lattnerbdff5482009-08-23 04:37:46 +000038 OS << "-------------------------------------------------------------\n"
Chris Lattnera59cbb22002-07-27 01:12:17 +000039 << "Interval Contents:\n";
Misha Brukman2b37d7c2005-04-21 21:13:18 +000040
Chris Lattnera59cbb22002-07-27 01:12:17 +000041 // Print out all of the basic blocks in the interval...
Benjamin Kramer8d0d2b62016-06-26 17:27:42 +000042 for (const BasicBlock *Node : Nodes)
43 OS << *Node << "\n";
Chris Lattnera59cbb22002-07-27 01:12:17 +000044
Chris Lattnerbdff5482009-08-23 04:37:46 +000045 OS << "Interval Predecessors:\n";
Benjamin Kramer8d0d2b62016-06-26 17:27:42 +000046 for (const BasicBlock *Predecessor : Predecessors)
47 OS << *Predecessor << "\n";
Chris Lattner1ff1ff702004-07-15 02:31:46 +000048
Chris Lattnerbdff5482009-08-23 04:37:46 +000049 OS << "Interval Successors:\n";
Benjamin Kramer8d0d2b62016-06-26 17:27:42 +000050 for (const BasicBlock *Successor : Successors)
51 OS << *Successor << "\n";
Chris Lattnera59cbb22002-07-27 01:12:17 +000052}