blob: 07d6e27c13befc2a34cc679eb2b6047eef9f2995 [file] [log] [blame]
Chris Lattner44d2c352003-10-13 03:32:08 +00001//===- Interval.cpp - Interval class code ---------------------------------===//
Misha Brukman01808ca2005-04-21 21:13:18 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Misha Brukman01808ca2005-04-21 21:13:18 +00006//
John Criswell482202a2003-10-20 19:43:21 +00007//===----------------------------------------------------------------------===//
Chris Lattner28ae5cb2001-06-20 20:09:55 +00008//
Chris Lattner78dd56f2002-04-28 16:21:30 +00009// This file contains the definition of the Interval class, which represents a
10// partition of a control flow graph of some kind.
Chris Lattner28ae5cb2001-06-20 20:09:55 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattnerdec727e2001-06-24 04:05:21 +000014#include "llvm/Analysis/Interval.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000015#include "llvm/IR/BasicBlock.h"
Chandler Carruth1305dc32014-03-04 11:45:46 +000016#include "llvm/IR/CFG.h"
Chris Lattnerb25de3f2009-08-23 04:37:46 +000017#include "llvm/Support/raw_ostream.h"
Chris Lattner28ae5cb2001-06-20 20:09:55 +000018
Brian Gaeke960707c2003-11-11 22:41:34 +000019using namespace llvm;
20
Chris Lattnerd79faa32001-06-21 05:26:15 +000021//===----------------------------------------------------------------------===//
22// Interval Implementation
23//===----------------------------------------------------------------------===//
24
25// isLoop - Find out if there is a back edge in this interval...
Chris Lattner78dd56f2002-04-28 16:21:30 +000026bool Interval::isLoop() const {
Sylvestre Ledru91ce36c2012-09-27 10:14:43 +000027 // There is a loop in this interval iff one of the predecessors of the header
Chris Lattnerd79faa32001-06-21 05:26:15 +000028 // node lives in the interval.
Duncan P. N. Exon Smith6c990152014-07-21 17:06:51 +000029 for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);
30 I != E; ++I)
31 if (contains(*I))
Chris Lattnerb25de3f2009-08-23 04:37:46 +000032 return true;
Chris Lattnerd79faa32001-06-21 05:26:15 +000033 return false;
34}
35
Chris Lattner13626022009-08-23 06:03:38 +000036void Interval::print(raw_ostream &OS) const {
Chris Lattnerb25de3f2009-08-23 04:37:46 +000037 OS << "-------------------------------------------------------------\n"
Chris Lattner26750072002-07-27 01:12:17 +000038 << "Interval Contents:\n";
Misha Brukman01808ca2005-04-21 21:13:18 +000039
Chris Lattner26750072002-07-27 01:12:17 +000040 // Print out all of the basic blocks in the interval...
Benjamin Krameraa209152016-06-26 17:27:42 +000041 for (const BasicBlock *Node : Nodes)
42 OS << *Node << "\n";
Chris Lattner26750072002-07-27 01:12:17 +000043
Chris Lattnerb25de3f2009-08-23 04:37:46 +000044 OS << "Interval Predecessors:\n";
Benjamin Krameraa209152016-06-26 17:27:42 +000045 for (const BasicBlock *Predecessor : Predecessors)
46 OS << *Predecessor << "\n";
Chris Lattner3c420772004-07-15 02:31:46 +000047
Chris Lattnerb25de3f2009-08-23 04:37:46 +000048 OS << "Interval Successors:\n";
Benjamin Krameraa209152016-06-26 17:27:42 +000049 for (const BasicBlock *Successor : Successors)
50 OS << *Successor << "\n";
Chris Lattner26750072002-07-27 01:12:17 +000051}