2003-09-30 18:37:50 +00:00
|
|
|
//===- llvm/Analysis/Interval.h - Interval Class Declaration ----*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-20 19:26:12 +00:00
|
|
|
//
|
2002-04-28 16:19:42 +00:00
|
|
|
// This file contains the declaration of the Interval class, which
|
2001-06-24 04:05:09 +00:00
|
|
|
// represents a set of CFG nodes and is a portion of an interval partition.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2001-06-24 04:05:09 +00:00
|
|
|
// Intervals have some interesting and useful properties, including the
|
|
|
|
// following:
|
|
|
|
// 1. The header node of an interval dominates all of the elements of the
|
|
|
|
// interval
|
2001-06-22 02:23:27 +00:00
|
|
|
//
|
2001-06-20 19:26:12 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 00:45:19 +00:00
|
|
|
#ifndef LLVM_ANALYSIS_INTERVAL_H
|
|
|
|
#define LLVM_ANALYSIS_INTERVAL_H
|
2001-06-20 19:26:12 +00:00
|
|
|
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/ADT/GraphTraits.h"
|
2001-06-20 19:26:12 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2001-06-20 19:26:12 +00:00
|
|
|
class BasicBlock;
|
2009-08-23 06:03:38 +00:00
|
|
|
class raw_ostream;
|
2001-06-20 19:26:12 +00:00
|
|
|
|
2001-06-22 02:23:27 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2005-04-21 16:04:49 +00:00
|
|
|
/// Interval Class - An Interval is a set of nodes defined such that every node
|
|
|
|
/// in the interval has all of its predecessors in the interval (except for the
|
|
|
|
/// header)
|
|
|
|
///
|
2001-06-20 19:26:12 +00:00
|
|
|
class Interval {
|
2005-04-21 16:04:49 +00:00
|
|
|
/// HeaderNode - The header BasicBlock, which dominates all BasicBlocks in this
|
|
|
|
/// interval. Also, any loops in this interval must go through the HeaderNode.
|
|
|
|
///
|
2001-06-20 19:26:12 +00:00
|
|
|
BasicBlock *HeaderNode;
|
2001-06-22 02:23:27 +00:00
|
|
|
public:
|
2002-01-20 22:54:45 +00:00
|
|
|
typedef std::vector<BasicBlock*>::iterator succ_iterator;
|
|
|
|
typedef std::vector<BasicBlock*>::iterator pred_iterator;
|
|
|
|
typedef std::vector<BasicBlock*>::iterator node_iterator;
|
2001-06-22 02:23:27 +00:00
|
|
|
|
2001-06-24 04:05:09 +00:00
|
|
|
inline Interval(BasicBlock *Header) : HeaderNode(Header) {
|
|
|
|
Nodes.push_back(Header);
|
|
|
|
}
|
|
|
|
|
2001-06-22 02:23:27 +00:00
|
|
|
inline BasicBlock *getHeaderNode() const { return HeaderNode; }
|
2001-06-20 19:26:12 +00:00
|
|
|
|
2005-04-21 16:04:49 +00:00
|
|
|
/// Nodes - The basic blocks in this interval.
|
|
|
|
///
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<BasicBlock*> Nodes;
|
2001-06-20 19:26:12 +00:00
|
|
|
|
2005-04-21 16:04:49 +00:00
|
|
|
/// Successors - List of BasicBlocks that are reachable directly from nodes in
|
|
|
|
/// this interval, but are not in the interval themselves.
|
|
|
|
/// These nodes necessarily must be header nodes for other intervals.
|
|
|
|
///
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<BasicBlock*> Successors;
|
2001-06-20 19:26:12 +00:00
|
|
|
|
2005-04-21 16:04:49 +00:00
|
|
|
/// Predecessors - List of BasicBlocks that have this Interval's header block
|
|
|
|
/// as one of their successors.
|
|
|
|
///
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<BasicBlock*> Predecessors;
|
2001-06-20 19:26:12 +00:00
|
|
|
|
2005-04-21 16:04:49 +00:00
|
|
|
/// contains - Find out if a basic block is in this interval
|
2001-06-21 05:24:46 +00:00
|
|
|
inline bool contains(BasicBlock *BB) const {
|
2001-06-24 04:05:09 +00:00
|
|
|
for (unsigned i = 0; i < Nodes.size(); ++i)
|
|
|
|
if (Nodes[i] == BB) return true;
|
|
|
|
return false;
|
|
|
|
// I don't want the dependency on <algorithm>
|
|
|
|
//return find(Nodes.begin(), Nodes.end(), BB) != Nodes.end();
|
2001-06-20 19:26:12 +00:00
|
|
|
}
|
|
|
|
|
2005-04-21 16:04:49 +00:00
|
|
|
/// isSuccessor - find out if a basic block is a successor of this Interval
|
2001-06-21 05:24:46 +00:00
|
|
|
inline bool isSuccessor(BasicBlock *BB) const {
|
2001-06-24 04:05:09 +00:00
|
|
|
for (unsigned i = 0; i < Successors.size(); ++i)
|
|
|
|
if (Successors[i] == BB) return true;
|
|
|
|
return false;
|
|
|
|
// I don't want the dependency on <algorithm>
|
|
|
|
//return find(Successors.begin(), Successors.end(), BB) != Successors.end();
|
2001-06-20 19:26:12 +00:00
|
|
|
}
|
|
|
|
|
2005-04-21 20:19:05 +00:00
|
|
|
/// Equality operator. It is only valid to compare two intervals from the
|
|
|
|
/// same partition, because of this, all we have to check is the header node
|
|
|
|
/// for equality.
|
2005-04-21 16:04:49 +00:00
|
|
|
///
|
2001-06-25 03:54:14 +00:00
|
|
|
inline bool operator==(const Interval &I) const {
|
|
|
|
return HeaderNode == I.HeaderNode;
|
|
|
|
}
|
|
|
|
|
2005-04-21 16:04:49 +00:00
|
|
|
/// isLoop - Find out if there is a back edge in this interval...
|
2001-06-21 05:24:46 +00:00
|
|
|
bool isLoop() const;
|
2002-07-27 01:12:15 +00:00
|
|
|
|
2005-04-21 16:04:49 +00:00
|
|
|
/// print - Show contents in human readable format...
|
2009-08-23 06:03:38 +00:00
|
|
|
void print(raw_ostream &O) const;
|
2002-02-12 22:35:27 +00:00
|
|
|
};
|
2001-06-20 19:26:12 +00:00
|
|
|
|
2005-04-21 16:04:49 +00:00
|
|
|
/// succ_begin/succ_end - define methods so that Intervals may be used
|
|
|
|
/// just like BasicBlocks can with the succ_* functions, and *::succ_iterator.
|
|
|
|
///
|
2002-04-28 16:19:42 +00:00
|
|
|
inline Interval::succ_iterator succ_begin(Interval *I) {
|
2002-02-12 22:35:27 +00:00
|
|
|
return I->Successors.begin();
|
|
|
|
}
|
2002-04-28 16:19:42 +00:00
|
|
|
inline Interval::succ_iterator succ_end(Interval *I) {
|
2002-02-12 22:35:27 +00:00
|
|
|
return I->Successors.end();
|
|
|
|
}
|
2005-07-27 05:53:44 +00:00
|
|
|
|
2005-04-21 16:04:49 +00:00
|
|
|
/// pred_begin/pred_end - define methods so that Intervals may be used
|
|
|
|
/// just like BasicBlocks can with the pred_* functions, and *::pred_iterator.
|
|
|
|
///
|
2002-04-28 16:19:42 +00:00
|
|
|
inline Interval::pred_iterator pred_begin(Interval *I) {
|
2002-02-12 22:35:27 +00:00
|
|
|
return I->Predecessors.begin();
|
|
|
|
}
|
2002-04-28 16:19:42 +00:00
|
|
|
inline Interval::pred_iterator pred_end(Interval *I) {
|
2002-02-12 22:35:27 +00:00
|
|
|
return I->Predecessors.end();
|
|
|
|
}
|
2001-06-20 22:44:32 +00:00
|
|
|
|
2003-10-01 22:27:36 +00:00
|
|
|
template <> struct GraphTraits<Interval*> {
|
|
|
|
typedef Interval NodeType;
|
|
|
|
typedef Interval::succ_iterator ChildIteratorType;
|
|
|
|
|
|
|
|
static NodeType *getEntryNode(Interval *I) { return I; }
|
|
|
|
|
2005-04-21 16:04:49 +00:00
|
|
|
/// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
|
2005-07-27 05:53:44 +00:00
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
2003-10-01 22:27:36 +00:00
|
|
|
return succ_begin(N);
|
|
|
|
}
|
2005-04-21 20:19:05 +00:00
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
2003-10-01 22:27:36 +00:00
|
|
|
return succ_end(N);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct GraphTraits<Inverse<Interval*> > {
|
|
|
|
typedef Interval NodeType;
|
|
|
|
typedef Interval::pred_iterator ChildIteratorType;
|
|
|
|
static NodeType *getEntryNode(Inverse<Interval *> G) { return G.Graph; }
|
2005-04-21 20:19:05 +00:00
|
|
|
static inline ChildIteratorType child_begin(NodeType *N) {
|
2003-10-01 22:27:36 +00:00
|
|
|
return pred_begin(N);
|
|
|
|
}
|
2005-04-21 20:19:05 +00:00
|
|
|
static inline ChildIteratorType child_end(NodeType *N) {
|
2003-10-01 22:27:36 +00:00
|
|
|
return pred_end(N);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-06-20 19:26:12 +00:00
|
|
|
#endif
|